ImportEtherpad: Rigorously check imported data

This commit is contained in:
Richard Hansen 2021-11-27 17:49:25 -05:00
parent 885ff3bcde
commit 19909eae53
3 changed files with 130 additions and 2 deletions

View file

@ -16,6 +16,7 @@
* limitations under the License.
*/
const {Pad} = require('../db/Pad');
const authorManager = require('../db/AuthorManager');
const db = require('../db/DB');
const hooks = require('../../static/js/pluginfw/hooks');
@ -90,6 +91,21 @@ exports.setPadRaw = async (padId, r) => {
dbRecords.set(key, value);
}));
const pad = new Pad(padId, {
// Only fetchers are needed to check the pad's integrity.
get: async (k) => dbRecords.get(k),
getSub: async (k, sub) => {
let v = dbRecords.get(k);
for (const sk of sub) {
if (v == null) return null;
v = v[sk];
}
return v;
},
});
await pad.init();
await pad.check();
await Promise.all([
...[...dbRecords].map(async ([k, v]) => await db.set(k, v)),
...[...existingAuthors].map(async (authorId) => await authorManager.addPad(authorId, padId)),