pad.libre-service.eu-etherpad/bin/extractPadData.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

'use strict';
2011-11-27 06:32:31 +01:00
/*
* This is a debug tool. It helps to extract all datas of a pad and move it from
* a productive environment and to a develop environment to reproduce bugs
* there. It outputs a dirtydb file
*/
2011-11-27 06:32:31 +01:00
// As of v14, Node.js does not exit when there is an unhandled Promise rejection. Convert an
// unhandled rejection into an uncaught exception, which does cause Node.js to exit.
2024-03-13 20:31:29 +01:00
import util from "util";
import process from "process";
import dirtyDB from "ueberdb2";
process.on('unhandledRejection', (err) => { throw err; });
if (process.argv.length !== 3) throw new Error('Use: node extractPadData.js $PADID');
// get the padID
const padId = process.argv[2];
2011-11-27 06:32:31 +01:00
2021-01-09 08:44:59 +01:00
(async () => {
// initialize database
2024-03-13 20:31:29 +01:00
require('ep_etherpad-lite/node/utils/Settings');
const db = require('ep_etherpad-lite/node/db/DB');
await db.init();
// load extra modules
2021-02-03 13:08:43 +01:00
const dirtyDB = require('dirty');
2024-03-13 20:31:29 +01:00
const padManager = require('ep_etherpad-lite/node/db/PadManager');
// initialize output database
const dirty = dirtyDB(`${padId}.db`);
// Promise set function
const set = util.promisify(dirty.set.bind(dirty));
// array in which required key values will be accumulated
const neededDBValues = [`pad:${padId}`];
// get the actual pad object
const pad = await padManager.getPad(padId);
// add all authors
neededDBValues.push(...pad.getAllAuthors().map((author) => `globalAuthor:${author}`));
// add all revisions
for (let rev = 0; rev <= pad.head; ++rev) {
neededDBValues.push(`pad:${padId}:revs:${rev}`);
}
// add all chat values
for (let chat = 0; chat <= pad.chatHead; ++chat) {
neededDBValues.push(`pad:${padId}:chat:${chat}`);
}
2013-02-18 21:38:32 +01:00
for (const dbkey of neededDBValues) {
let dbvalue = await db.get(dbkey);
if (dbvalue && typeof dbvalue !== 'object') {
dbvalue = JSON.parse(dbvalue);
}
await set(dbkey, dbvalue);
2011-11-27 06:32:31 +01:00
}
console.log('finished');
2021-01-09 08:44:59 +01:00
})();