ExportEtherpad: New importEtherpad, exportEtherpad hooks

This commit is contained in:
Richard Hansen 2022-04-19 17:01:35 -04:00
parent 44fd70491d
commit 2facf3a0c5
4 changed files with 57 additions and 1 deletions

View file

@ -55,5 +55,10 @@ exports.getPadRaw = async (padId, readOnlyId) => {
})();
const data = {[dstPfx]: pad};
for (const [dstKey, p] of new Stream(records).batch(100).buffer(99)) data[dstKey] = await p;
await hooks.aCallAll('exportEtherpad', {
pad,
data,
dstPadId: readOnlyId || padId,
});
return data;
};

View file

@ -90,7 +90,8 @@ exports.setPadRaw = async (padId, r, authorId = '') => {
keyParts[1] = padId;
key = keyParts.join(':');
} else {
logger.warn(`(pad ${padId}) Ignoring record with unsupported key: ${key}`);
logger.debug(`(pad ${padId}) The record with the following key will be ignored unless an ` +
`importEtherpad hook function processes it: ${key}`);
return;
}
await padDb.set(key, value);
@ -100,6 +101,13 @@ exports.setPadRaw = async (padId, r, authorId = '') => {
const pad = new Pad(padId, padDb);
await pad.init(null, authorId);
await hooks.aCallAll('importEtherpad', {
pad,
// Shallow freeze meant to prevent accidental bugs. It would be better to deep freeze, but
// it's not worth the added complexity.
data: Object.freeze(records),
srcPadId: originalPadId,
});
await pad.check();
} finally {
await padDb.close();