2021-11-25 01:43:46 -05:00
|
|
|
'use strict';
|
|
|
|
|
2014-12-29 21:13:49 +01:00
|
|
|
/**
|
2014-12-30 00:12:26 +01:00
|
|
|
* 2014 John McLear (Etherpad Foundation / McLear Ltd)
|
2014-12-29 21:13:49 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-11-25 01:43:46 -05:00
|
|
|
const authorManager = require('../db/AuthorManager');
|
2020-11-23 13:24:19 -05:00
|
|
|
const db = require('../db/DB');
|
2021-01-21 21:06:52 +00:00
|
|
|
const hooks = require('../../static/js/pluginfw/hooks');
|
2021-03-29 20:06:33 -04:00
|
|
|
const log4js = require('log4js');
|
2021-03-02 17:14:47 +00:00
|
|
|
const supportedElems = require('../../static/js/contentcollector').supportedElems;
|
2014-12-29 21:13:49 +01:00
|
|
|
|
2021-03-29 20:06:33 -04:00
|
|
|
const logger = log4js.getLogger('ImportEtherpad');
|
|
|
|
|
2021-11-23 00:34:59 -05:00
|
|
|
exports.setPadRaw = async (padId, r) => {
|
2021-01-21 21:06:52 +00:00
|
|
|
const records = JSON.parse(r);
|
2014-12-30 00:01:15 +01:00
|
|
|
|
2021-02-21 11:07:13 +00:00
|
|
|
// get supported block Elements from plugins, we will use this later.
|
|
|
|
hooks.callAll('ccRegisterBlockElements').forEach((element) => {
|
2021-03-29 19:40:03 -04:00
|
|
|
supportedElems.add(element);
|
2021-02-21 11:07:13 +00:00
|
|
|
});
|
|
|
|
|
2021-03-29 20:06:33 -04:00
|
|
|
const unsupportedElements = new Set();
|
|
|
|
|
2021-11-23 00:34:59 -05:00
|
|
|
await Promise.all(Object.entries(records).map(async ([key, value]) => {
|
2019-02-08 23:20:57 +01:00
|
|
|
if (!value) {
|
2019-01-31 08:55:36 +00:00
|
|
|
return;
|
2015-02-21 12:33:30 +00:00
|
|
|
}
|
2021-11-25 01:43:46 -05:00
|
|
|
const keyParts = key.split(':');
|
|
|
|
const [prefix, id] = keyParts;
|
|
|
|
if (prefix === 'globalAuthor' && keyParts.length === 2) {
|
|
|
|
if (await authorManager.doesAuthorExist(id)) {
|
|
|
|
await authorManager.addPad(id, padId);
|
|
|
|
return;
|
2019-01-31 08:55:36 +00:00
|
|
|
}
|
2021-11-25 01:43:46 -05:00
|
|
|
value.padIDs = {[padId]: 1};
|
2019-02-08 23:20:57 +01:00
|
|
|
} else {
|
|
|
|
// Not author data, probably pad data
|
|
|
|
// we can split it to look to see if it's pad data
|
2021-02-21 11:07:13 +00:00
|
|
|
|
|
|
|
// is this an attribute we support or not? If not, tell the admin
|
|
|
|
if (value.pool) {
|
|
|
|
for (const attrib of Object.keys(value.pool.numToAttrib)) {
|
|
|
|
const attribName = value.pool.numToAttrib[attrib][0];
|
2021-03-29 20:06:33 -04:00
|
|
|
if (!supportedElems.has(attribName)) unsupportedElements.add(attribName);
|
2021-02-21 11:07:13 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 13:24:19 -05:00
|
|
|
const oldPadId = key.split(':');
|
2014-12-30 00:01:15 +01:00
|
|
|
|
2019-02-08 23:20:57 +01:00
|
|
|
// we know it's pad data
|
2020-11-23 13:24:19 -05:00
|
|
|
if (oldPadId[0] === 'pad') {
|
2014-12-30 00:01:15 +01:00
|
|
|
// so set the new pad id for the author
|
|
|
|
oldPadId[1] = padId;
|
2021-11-24 23:39:27 -05:00
|
|
|
key = oldPadId.join(':');
|
2014-12-30 00:01:15 +01:00
|
|
|
}
|
2020-11-06 13:48:25 +00:00
|
|
|
|
|
|
|
// is this a key that is supported through a plugin?
|
2020-11-10 01:20:05 -05:00
|
|
|
// get content that has a different prefix IE comments:padId:foo
|
|
|
|
// a plugin would return something likle ['comments', 'cakes']
|
|
|
|
for (const prefix of await hooks.aCallAll('exportEtherpadAdditionalContent')) {
|
2021-11-24 23:39:27 -05:00
|
|
|
if (prefix === oldPadId[0]) key = `${prefix}:${padId}`;
|
2020-11-10 01:20:05 -05:00
|
|
|
}
|
2014-12-30 00:01:15 +01:00
|
|
|
}
|
2021-11-24 23:39:27 -05:00
|
|
|
await db.set(key, value);
|
2021-11-23 00:34:59 -05:00
|
|
|
}));
|
2021-03-29 20:06:33 -04:00
|
|
|
|
|
|
|
if (unsupportedElements.size) {
|
|
|
|
logger.warn('Ignoring unsupported elements (you might want to install a plugin): ' +
|
|
|
|
`${[...unsupportedElements].join(', ')}`);
|
|
|
|
}
|
2020-11-23 13:24:19 -05:00
|
|
|
};
|