Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix saving history for encrypted notes
azivnerb81f1ed93a05
diff --git a/services/notes.js b/services/notes.jsindex a568f06b51..7cbf41d8b6 100644--- a/services/notes.js+++ b/services/notes.js@@ -81,6 +81,12 @@ async function protectNoteRecursively(noteId, dataKey, protect) {}}+function decryptNote(note, dataKey) {+ note.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(note.note_id), note.note_title);+ note.note_text = data_encryption.decryptString(dataKey, data_encryption.noteTextIv(note.note_id), note.note_text);+ note.is_protected = false;+}+async function protectNote(note, dataKey, protect) {let changed = false;@@ -92,9 +98,7 @@ async function protectNote(note, dataKey, protect) {changed = true;}else if (!protect && note.is_protected) {- note.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(note.note_id), note.note_title);- note.note_text = data_encryption.decryptString(dataKey, data_encryption.noteTextIv(note.note_id), note.note_text);- note.is_protected = false;+ decryptNote(note, dataKey);changed = true;}@@ -150,14 +154,19 @@ async function updateNote(noteId, newNote, ctx) {if (!existingNoteHistoryId && (now - newNote.detail.date_created) >= historySnapshotTimeInterval) {const oldNote = await sql.getSingleResult("SELECT * FROM notes WHERE note_id = ?", [noteId]);+ if (oldNote.is_protected) {+ decryptNote(oldNote, ctx.getDataKey());+ }+const newNoteHistoryId = utils.newNoteHistoryId();await sql.insert('notes_history', {note_history_id: newNoteHistoryId,note_id: noteId,+ // title and text should be decrypted nownote_title: oldNote.note_title,note_text: oldNote.note_text,- is_protected: oldNote.is_protected,+ is_protected: 0, // will be fixed in the protectNoteHistory() calldate_modified_from: oldNote.date_modified,date_modified_to: now});