2021-01-21 21:06:52 +00: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.
|
|
|
|
*/
|
|
|
|
|
2022-04-16 22:28:59 -04:00
|
|
|
const Stream = require('./Stream');
|
2022-04-13 23:12:08 -04:00
|
|
|
const assert = require('assert').strict;
|
2022-04-13 03:57:47 -04:00
|
|
|
const authorManager = require('../db/AuthorManager');
|
2021-01-21 21:06:52 +00:00
|
|
|
const hooks = require('../../static/js/pluginfw/hooks');
|
2022-04-13 03:57:47 -04:00
|
|
|
const padManager = require('../db/PadManager');
|
2014-12-29 21:13:49 +01:00
|
|
|
|
2021-06-29 19:13:10 +02:00
|
|
|
exports.getPadRaw = async (padId, readOnlyId) => {
|
2022-04-16 22:28:59 -04:00
|
|
|
const dstPfx = `pad:${readOnlyId || padId}`;
|
|
|
|
const [pad, customPrefixes] = await Promise.all([
|
|
|
|
padManager.getPad(padId),
|
|
|
|
hooks.aCallAll('exportEtherpadAdditionalContent'),
|
|
|
|
]);
|
|
|
|
const pluginRecords = await Promise.all(customPrefixes.map(async (customPrefix) => {
|
|
|
|
const srcPfx = `${customPrefix}:${padId}`;
|
|
|
|
const dstPfx = `${customPrefix}:${readOnlyId || padId}`;
|
2022-04-13 23:12:08 -04:00
|
|
|
assert(!srcPfx.includes('*'));
|
2022-04-16 22:28:59 -04:00
|
|
|
const srcKeys = await pad.db.findKeys(`${srcPfx}:*`, null);
|
|
|
|
return (function* () {
|
|
|
|
yield [dstPfx, pad.db.get(srcPfx)];
|
|
|
|
for (const k of srcKeys) {
|
|
|
|
assert(k.startsWith(`${srcPfx}:`));
|
|
|
|
yield [`${dstPfx}${k.slice(srcPfx.length)}`, pad.db.get(k)];
|
|
|
|
}
|
|
|
|
})();
|
2020-11-10 01:20:05 -05:00
|
|
|
}));
|
2022-04-16 22:28:59 -04:00
|
|
|
const records = (function* () {
|
|
|
|
for (const authorId of pad.getAllAuthors()) {
|
|
|
|
yield [`globalAuthor:${authorId}`, (async () => {
|
|
|
|
const authorEntry = await authorManager.getAuthor(authorId);
|
|
|
|
if (!authorEntry) return undefined; // Becomes unset when converted to JSON.
|
|
|
|
if (authorEntry.padIDs) authorEntry.padIDs = readOnlyId || padId;
|
|
|
|
return authorEntry;
|
|
|
|
})()];
|
|
|
|
}
|
|
|
|
for (let i = 0; i <= pad.head; ++i) yield [`${dstPfx}:revs:${i}`, pad.getRevision(i)];
|
|
|
|
for (let i = 0; i <= pad.chatHead; ++i) yield [`${dstPfx}:chat:${i}`, pad.getChatMessage(i)];
|
|
|
|
for (const gen of pluginRecords) yield* gen;
|
|
|
|
})();
|
|
|
|
const data = {[dstPfx]: pad};
|
|
|
|
for (const [dstKey, p] of new Stream(records).batch(100).buffer(99)) data[dstKey] = await p;
|
2019-01-31 08:55:36 +00:00
|
|
|
return data;
|
2020-11-23 13:24:19 -05:00
|
|
|
};
|