From 936185e3b6d77e515d961ffd6a0b5d8899fa393b Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 13 Apr 2022 03:57:47 -0400 Subject: [PATCH] ExportEtherpad: Use Pad API to collect data --- src/node/utils/ExportEtherpad.js | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/node/utils/ExportEtherpad.js b/src/node/utils/ExportEtherpad.js index 73f2b8160..176a53f40 100644 --- a/src/node/utils/ExportEtherpad.js +++ b/src/node/utils/ExportEtherpad.js @@ -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; };