pad.libre-service.eu-etherpad/src/node/utils/ExportEtherpad.js

70 lines
2.1 KiB
JavaScript
Raw Normal View History

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.
*/
2020-11-23 19:24:19 +01:00
const db = require('../db/DB');
const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks');
2014-12-29 21:13:49 +01:00
2020-11-23 19:24:19 +01:00
exports.getPadRaw = async function (padId) {
const padKey = `pad:${padId}`;
const padcontent = await db.get(padKey);
2018-04-04 19:02:54 +02:00
2020-11-23 19:24:19 +01:00
const records = [padKey];
for (let i = 0; i <= padcontent.head; i++) {
2020-11-23 19:24:19 +01:00
records.push(`${padKey}:revs:${i}`);
}
2014-12-29 22:51:31 +01:00
for (let i = 0; i <= padcontent.chatHead; i++) {
2020-11-23 19:24:19 +01:00
records.push(`${padKey}:chat:${i}`);
}
2014-12-29 22:51:31 +01:00
2020-11-23 19:24:19 +01:00
const data = {};
for (const key of records) {
// For each piece of info about a pad.
2020-11-23 19:24:19 +01:00
const entry = data[key] = await db.get(key);
2014-12-29 22:51:31 +01:00
// Get the Pad Authors
if (entry.pool && entry.pool.numToAttrib) {
2020-11-23 19:24:19 +01:00
const authors = entry.pool.numToAttrib;
2014-12-29 22:51:31 +01:00
2020-11-23 19:24:19 +01:00
for (const k of Object.keys(authors)) {
if (authors[k][0] === 'author') {
const authorId = authors[k][1];
// Get the author info
2020-11-23 19:24:19 +01:00
const authorEntry = await db.get(`globalAuthor:${authorId}`);
if (authorEntry) {
2020-11-23 19:24:19 +01:00
data[`globalAuthor:${authorId}`] = authorEntry;
if (authorEntry.padIDs) {
authorEntry.padIDs = padId;
2014-12-29 22:51:31 +01:00
}
}
2014-12-29 22:51:31 +01:00
}
}
}
2014-12-29 22:51:31 +01:00
}
// get content that has a different prefix IE comments:padId:foo
// a plugin would return something likle ['comments', 'cakes']
const prefixes = await hooks.aCallAll('exportEtherpadAdditionalContent');
await Promise.all(prefixes.map(async (prefix) => {
const key = `${prefix}:${padId}`;
data[key] = await db.get(key);
}));
return data;
2020-11-23 19:24:19 +01:00
};