2021-01-18 08:53:15 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-11-27 05:32:31 +00:00
|
|
|
/*
|
2019-02-08 22:20:57 +00: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 05:32:31 +00:00
|
|
|
|
2021-01-18 08:53:15 +00: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.
|
|
|
|
process.on('unhandledRejection', (err) => { throw err; });
|
|
|
|
|
|
|
|
if (process.argv.length !== 3) throw new Error('Use: node extractPadData.js $PADID');
|
2019-02-08 22:20:57 +00:00
|
|
|
|
|
|
|
// get the padID
|
2020-11-23 18:21:51 +00:00
|
|
|
const padId = process.argv[2];
|
2011-11-27 05:32:31 +00:00
|
|
|
|
2021-01-18 08:53:15 +00:00
|
|
|
const npm = require('ep_etherpad-lite/node_modules/npm');
|
2011-11-27 05:32:31 +00:00
|
|
|
|
2021-01-18 08:53:15 +00:00
|
|
|
npm.load({}, async (err) => {
|
|
|
|
if (err) throw err;
|
2013-01-06 18:25:32 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
try {
|
|
|
|
// initialize database
|
2021-01-18 08:53:15 +00:00
|
|
|
require('ep_etherpad-lite/node/utils/Settings');
|
|
|
|
const db = require('ep_etherpad-lite/node/db/DB');
|
2019-01-26 23:52:02 +00:00
|
|
|
await db.init();
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// load extra modules
|
2021-01-18 08:53:15 +00:00
|
|
|
const dirtyDB = require('ep_etherpad-lite/node_modules/dirty');
|
|
|
|
const padManager = require('ep_etherpad-lite/node/db/PadManager');
|
2020-11-23 18:21:51 +00:00
|
|
|
const util = require('util');
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// initialize output database
|
2020-11-23 18:21:51 +00:00
|
|
|
const dirty = dirtyDB(`${padId}.db`);
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// Promise wrapped get and set function
|
2020-11-23 18:21:51 +00:00
|
|
|
const wrapped = db.db.db.wrappedDB;
|
|
|
|
const get = util.promisify(wrapped.get.bind(wrapped));
|
|
|
|
const set = util.promisify(dirty.set.bind(dirty));
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// array in which required key values will be accumulated
|
2020-11-23 18:21:51 +00:00
|
|
|
const neededDBValues = [`pad:${padId}`];
|
2019-01-26 23:52:02 +00:00
|
|
|
|
|
|
|
// get the actual pad object
|
2020-11-23 18:21:51 +00:00
|
|
|
const pad = await padManager.getPad(padId);
|
2019-02-08 22:20:57 +00:00
|
|
|
|
|
|
|
// add all authors
|
2020-11-23 18:21:51 +00:00
|
|
|
neededDBValues.push(...pad.getAllAuthors().map((author) => `globalAuthor:${author}`));
|
2019-02-08 22:20:57 +00:00
|
|
|
|
|
|
|
// add all revisions
|
2019-01-26 23:52:02 +00:00
|
|
|
for (let rev = 0; rev <= pad.head; ++rev) {
|
2020-11-23 18:21:51 +00:00
|
|
|
neededDBValues.push(`pad:${padId}:revs:${rev}`);
|
2011-11-27 05:32:31 +00:00
|
|
|
}
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
// add all chat values
|
|
|
|
for (let chat = 0; chat <= pad.chatHead; ++chat) {
|
2020-11-23 18:21:51 +00:00
|
|
|
neededDBValues.push(`pad:${padId}:chat:${chat}`);
|
2011-11-27 05:32:31 +00:00
|
|
|
}
|
2013-02-18 20:38:32 +00:00
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
for (const dbkey of neededDBValues) {
|
2019-01-26 23:52:02 +00:00
|
|
|
let dbvalue = await get(dbkey);
|
|
|
|
if (dbvalue && typeof dbvalue !== 'object') {
|
|
|
|
dbvalue = JSON.parse(dbvalue);
|
|
|
|
}
|
|
|
|
await set(dbkey, dbvalue);
|
|
|
|
}
|
2019-02-08 22:20:57 +00:00
|
|
|
|
2019-01-26 23:52:02 +00:00
|
|
|
console.log('finished');
|
2021-01-18 08:53:15 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
throw err;
|
2011-11-27 05:32:31 +00:00
|
|
|
}
|
|
|
|
});
|