trilium/src/services/anonymization.js

32 lines
1.1 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});
2018-01-29 08:30:14 +08:00
await db.run("UPDATE notes SET title = 'title', content = 'text'");
await db.run("UPDATE note_revisions SET title = 'title', content = 'text'");
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();
}
module.exports = {
anonymize
};