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

@ -20,7 +20,7 @@
*/
const CustomError = require('../utils/customError');
const Pad = require('../db/Pad').Pad;
const Pad = require('../db/Pad');
const db = require('./DB');
const hooks = require('../../static/js/pluginfw/hooks');
@ -138,7 +138,7 @@ exports.getPad = async (id, text) => {
}
// try to load pad
pad = new Pad(id);
pad = new Pad.Pad(id);
// initialize the pad
await pad.init(text);

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)),