Skip to content

Build your personal knowledge base with Trilium Notes

encryption of note history if the note is encrypted

azivner471f7c669d38
diff --git a/public/javascripts/encryption.js b/public/javascripts/encryption.js
index 6ddbc22784..499d5f0f62 100644
--- a/public/javascripts/encryption.js
+++ b/public/javascripts/encryption.js
@@ -235,10 +235,37 @@ function encryptNoteAndSendToServer() {
saveNoteToServer(note);
+ encryptNoteHistory(note.detail.note_id);
+
setNoteBackgroundIfEncrypted(note);
});
}
+function encryptNoteHistory(noteId) {
+ $.ajax({
+ url: baseApiUrl + 'notes-history/' + noteId + "?encryption=0",
+ type: 'GET',
+ success: result => {
+ for (const row of result) {
+ row.note_title = encryptString(row.note_title);
+ row.note_text = encryptString(row.note_text);
+
+ row.encryption = 1;
+
+ $.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.")
+ });
+ }
+ },
+ error: () => alert("Error getting note history.")
+ });
+}
+
function decryptNoteAndSendToServer() {
handleEncryption(true, true, () => {
const note = globalCurrentNote;
diff --git a/public/javascripts/note_history.js b/public/javascripts/note_history.js
index d0c57213cd..b508210bab 100644
--- a/public/javascripts/note_history.js
+++ b/public/javascripts/note_history.js
@@ -24,7 +24,7 @@ function showNoteHistoryDialog(noteId, noteHistoryId) {
const dateModified = getDateFromTS(row.date_modified_to);
$("#note-history-list").append($('<option>', {
- value: row.id,
+ value: row.note_history_id,
text: formatDateTime(dateModified)
}));
}
@@ -46,8 +46,16 @@ $(document).bind('keydown', 'alt+h', showCurrentNoteHistory);
$("#note-history-list").on('change', () => {
const optVal = $("#note-history-list").find(":selected").val();
- const historyItem = globalHistoryItems.find(r => r.id == optVal); // non-strict comparison is important here!!!
+ const historyItem = globalHistoryItems.find(r => r.note_history_id === optVal);
- $("#note-history-title").html(historyItem.note_title);
- $("#note-history-content").html(historyItem.note_text);
+ let noteTitle = historyItem.note_title;
+ let noteText = historyItem.note_text;
+
+ if (historyItem.encryption > 0) {
+ noteTitle = decryptString(noteTitle);
+ noteText = decryptString(noteText);
+ }
+
+ $("#note-history-title").html(noteTitle);
+ $("#note-history-content").html(noteText);
});
\ No newline at end of file
diff --git a/routes/api/note_history.js b/routes/api/note_history.js
index d60784dab0..192754824d 100644
--- a/routes/api/note_history.js
+++ b/routes/api/note_history.js
@@ -7,10 +7,28 @@ const auth = require('../../services/auth');
router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
const noteId = req.params.noteId;
+ const encryption = req.query.encryption;
- const history = await sql.getResults("select * from notes_history where note_id = ? order by date_modified_to desc", [noteId]);
+ let history;
+
+ if (encryption === undefined) {
+ history = await sql.getResults("select * from notes_history where note_id = ? order by date_modified_to desc", [noteId]);
+ }
+ else {
+ history = await sql.getResults("select * from notes_history where note_id = ? and encryption = ? order by date_modified_to desc", [noteId, encryption]);
+ }
res.send(history);
});
+router.put('/', auth.checkApiAuth, async (req, res, next) => {
+ await sql.doInTransaction(async () => {
+ await sql.replace("notes_history", req.body);
+
+ await sql.addNoteHistorySync(req.body.note_history_id);
+ });
+
+ res.send();
+});
+
module.exports = router;
\ No newline at end of file