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
also de-encryption of note history plus bug fixes
azivnerac0e5ada6e9a
diff --git a/public/javascripts/encryption.js b/public/javascripts/encryption.jsindex 499d5f0f62..2303cdcf81 100644--- a/public/javascripts/encryption.js+++ b/public/javascripts/encryption.js@@ -235,31 +235,39 @@ function encryptNoteAndSendToServer() {saveNoteToServer(note);- encryptNoteHistory(note.detail.note_id);+ changeEncryptionOnNoteHistory(note.detail.note_id, true);setNoteBackgroundIfEncrypted(note);});}-function encryptNoteHistory(noteId) {+function changeEncryptionOnNoteHistory(noteId, encrypt) {$.ajax({- url: baseApiUrl + 'notes-history/' + noteId + "?encryption=0",+ url: baseApiUrl + 'notes-history/' + noteId + "?encryption=" + (encrypt ? 0 : 1),type: 'GET',success: result => {for (const row of result) {- row.note_title = encryptString(row.note_title);- row.note_text = encryptString(row.note_text);+ if (encrypt) {+ row.note_title = encryptString(row.note_title);+ row.note_text = encryptString(row.note_text);+ }+ else {+ row.note_title = decryptString(row.note_title);+ row.note_text = decryptString(row.note_text);+ }- row.encryption = 1;+ row.encryption = encrypt ? 1 : 0;$.ajax({url: baseApiUrl + 'notes-history',type: 'PUT',contentType: 'application/json',data: JSON.stringify(row),- success: result => console.log('Note history ' + row.note_history_id + ' encrypted'),- error: () => alert("Error encrypting note history.")+ success: result => console.log('Note history ' + row.note_history_id + ' de/encrypted'),+ error: () => alert("Error de/encrypting note history.")});++ break;}},error: () => alert("Error getting note history.")@@ -276,6 +284,8 @@ function decryptNoteAndSendToServer() {saveNoteToServer(note);+ changeEncryptionOnNoteHistory(note.detail.note_id, false);+setNoteBackgroundIfEncrypted(note);});}diff --git a/routes/api/note_history.js b/routes/api/note_history.jsindex 192754824d..cfe7477ea0 100644--- a/routes/api/note_history.js+++ b/routes/api/note_history.js@@ -21,7 +21,7 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {res.send(history);});-router.put('/', auth.checkApiAuth, async (req, res, next) => {+router.put('', auth.checkApiAuth, async (req, res, next) => {await sql.doInTransaction(async () => {await sql.replace("notes_history", req.body);