mirror of
https://github.com/TriliumNext/Notes.git
synced 2026-01-02 02:50:00 -06:00
50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
"use strict";
|
|
|
|
const log = require('./log');
|
|
const sql = require('./sql');
|
|
const protectedSessionService = require("./protected_session");
|
|
|
|
/**
|
|
* @param {BNote} note
|
|
*/
|
|
function protectRevisions(note) {
|
|
if (!protectedSessionService.isProtectedSessionAvailable()) {
|
|
throw new Error(`Cannot (un)protect revisions of note '${note.noteId}' without active protected session`);
|
|
}
|
|
|
|
for (const revision of note.getRevisions()) {
|
|
if (note.isProtected === revision.isProtected) {
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
const content = revision.getContent();
|
|
|
|
revision.isProtected = note.isProtected;
|
|
|
|
// this will force de/encryption
|
|
revision.setContent(content, {forceSave: true});
|
|
} catch (e) {
|
|
log.error(`Could not un/protect note revision '${revision.revisionId}'`);
|
|
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
|
|
function eraseRevisions(revisionIdsToErase) {
|
|
if (revisionIdsToErase.length === 0) {
|
|
return;
|
|
}
|
|
|
|
log.info(`Removing note revisions: ${JSON.stringify(revisionIdsToErase)}`);
|
|
|
|
sql.executeMany(`DELETE FROM revisions WHERE revisionId IN (???)`, revisionIdsToErase);
|
|
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'revisions' AND entityId IN (???)`, revisionIdsToErase);
|
|
}
|
|
|
|
module.exports = {
|
|
protectRevisions,
|
|
eraseRevisions
|
|
};
|