ExportEtherpad: Use Pad API to collect data
parent
4a6e77839e
commit
936185e3b6
|
@ -15,37 +15,28 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
const db = require('../db/DB');
|
||||
const authorManager = require('../db/AuthorManager');
|
||||
const hooks = require('../../static/js/pluginfw/hooks');
|
||||
const padManager = require('../db/PadManager');
|
||||
|
||||
exports.getPadRaw = async (padId, readOnlyId) => {
|
||||
const keyPrefixRead = `pad:${padId}`;
|
||||
const keyPrefixWrite = readOnlyId ? `pad:${readOnlyId}` : keyPrefixRead;
|
||||
const data = {[keyPrefixWrite]: await db.get(keyPrefixRead)};
|
||||
for (const [k, v] of Object.values(data[keyPrefixWrite].pool.numToAttrib)) {
|
||||
if (k !== 'author') continue;
|
||||
const authorEntry = await db.get(`globalAuthor:${v}`);
|
||||
const pad = await padManager.getPad(padId);
|
||||
const pfx = `pad:${readOnlyId || padId}`;
|
||||
const data = {[pfx]: pad};
|
||||
for (const authorId of pad.getAllAuthors()) {
|
||||
const authorEntry = await authorManager.getAuthor(authorId);
|
||||
if (!authorEntry) continue;
|
||||
data[`globalAuthor:${v}`] = authorEntry;
|
||||
data[`globalAuthor:${authorId}`] = authorEntry;
|
||||
if (!authorEntry.padIDs) continue;
|
||||
authorEntry.padIDs = readOnlyId || padId;
|
||||
}
|
||||
const keySuffixes = [];
|
||||
for (let i = 0; i <= data[keyPrefixWrite].head; i++) keySuffixes.push(`:revs:${i}`);
|
||||
for (let i = 0; i <= data[keyPrefixWrite].chatHead; i++) keySuffixes.push(`:chat:${i}`);
|
||||
for (const keySuffix of keySuffixes) {
|
||||
data[keyPrefixWrite + keySuffix] = await db.get(keyPrefixRead + keySuffix);
|
||||
}
|
||||
|
||||
for (let i = 0; i <= pad.head; ++i) data[`${pfx}:revs:${i}`] = await pad.getRevision(i);
|
||||
for (let i = 0; i <= pad.chatHead; ++i) data[`${pfx}:chat:${i}`] = await pad.getChatMessage(i);
|
||||
// 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}`;
|
||||
const writeKey = readOnlyId ? `${prefix}:${readOnlyId}` : key;
|
||||
data[writeKey] = await db.get(key);
|
||||
data[`${prefix}:${readOnlyId || padId}`] = await pad.db.get(`${prefix}:${padId}`);
|
||||
}));
|
||||
|
||||
return data;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue