trilium/src/services/anonymization.js

38 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-12-16 13:05:37 +08:00
"use strict";
const dataDir = require('./data_dir');
2018-04-03 08:46:46 +08:00
const dateUtils = require('./date_utils');
2017-12-16 13:05:37 +08:00
const fs = require('fs-extra');
const sqlite = require('sqlite');
async function anonymize() {
if (!fs.existsSync(dataDir.ANONYMIZED_DB_DIR)) {
fs.mkdirSync(dataDir.ANONYMIZED_DB_DIR, 0o700);
2017-12-16 13:05:37 +08:00
}
2018-04-03 10:53:01 +08:00
const anonymizedFile = dataDir.ANONYMIZED_DB_DIR + "/" + "anonymized-" + dateUtils.getDateTimeForFile() + ".db";
2017-12-16 13:05:37 +08:00
fs.copySync(dataDir.DOCUMENT_PATH, anonymizedFile);
2017-12-16 13:05:37 +08:00
const db = await sqlite.open(anonymizedFile, {Promise});
2019-05-30 01:57:50 +08:00
await db.run("UPDATE notes SET title = 'title'");
await db.run("UPDATE note_contents SET content = 'text'");
await db.run("UPDATE note_revisions SET title = 'title'");
await db.run("UPDATE note_revision_contents SET content = 'title'");
await db.run("UPDATE attributes SET name = 'name', value = 'value' WHERE type = 'label'");
await db.run("UPDATE attributes SET name = 'name' WHERE type = 'relation'");
2018-03-25 09:39:15 +08:00
await db.run("UPDATE branches SET prefix = 'prefix' WHERE prefix IS NOT NULL");
2018-01-29 08:30:14 +08:00
await db.run(`UPDATE options SET value = 'anonymized' WHERE name IN
2018-04-03 09:47:46 +08:00
('documentSecret', 'encryptedDataKey', 'passwordVerificationHash',
'passwordVerificationSalt', 'passwordDerivedKeySalt')`);
2017-12-16 13:05:37 +08:00
await db.run("VACUUM");
await db.close();
return anonymizedFile;
2017-12-16 13:05:37 +08:00
}
module.exports = {
anonymize
};