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