From 475fddeec114ceb3b2d6bb624285e697c1b27ae1 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 1 Nov 2019 23:05:33 +0100 Subject: [PATCH] fixes --- .../a2c75661-f9e2-478f-a69f-6a9409e69997.xml | 116 +++++++++++------- src/entities/note.js | 2 +- src/entities/note_revision.js | 2 +- src/routes/api/recent_changes.js | 4 +- src/services/content_hash.js | 1 + src/services/note_cache.js | 2 +- src/services/options.js | 2 +- src/services/protected_session.js | 4 +- 8 files changed, 84 insertions(+), 49 deletions(-) diff --git a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml index fd55d255c..ff9d9b811 100644 --- a/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml +++ b/.idea/dataSources/a2c75661-f9e2-478f-a69f-6a9409e69997.xml @@ -430,199 +430,233 @@ parentNoteId 1 0 - + 8 - TEXT|0s + INT|0s 1 + 0 - + 9 TEXT|0s 1 - + 10 TEXT|0s 1 - + 11 TEXT|0s 1 - + + 12 + TEXT|0s + 1 + + 1 noteId 1 - + + title + + + + type + + + + isDeleted + + + + dateCreated + + + + dateModified + + + + utcDateCreated + + + + utcDateModified + + + noteId 1 sqlite_autoindex_notes_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s - + 3 INTEGER|0s 1 0 - + 4 TEXT|0s 1 "" - + 5 TEXT|0s 1 - + 6 TEXT|0s 1 - + 1 name 1 - + name 1 sqlite_autoindex_options_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 "" - + 4 TEXT|0s 1 - + 5 INT|0s - + 1 noteId 1 - + noteId 1 sqlite_autoindex_recent_notes_1 - + 1 TEXT|0s 1 - + 2 TEXT|0s 1 - + 1 sourceId 1 - + sourceId 1 sqlite_autoindex_source_ids_1 - + 1 text|0s - + 2 text|0s - + 3 text|0s - + 4 int|0s - + 5 text|0s - + 1 - + 2 - + 1 INTEGER|0s 1 1 - + 2 TEXT|0s 1 - + 3 TEXT|0s 1 - + 4 TEXT|0s 1 - + 5 TEXT|0s 1 - + entityName entityId 1 - + utcSyncDate - + id 1 diff --git a/src/entities/note.js b/src/entities/note.js index f8b2748a4..195cbfea9 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -52,7 +52,7 @@ class Note extends Entity { this.isContentAvailable = protectedSessionService.isProtectedSessionAvailable(); if (this.isContentAvailable) { - this.title = protectedSessionService.decrypt(this.title); + this.title = protectedSessionService.decrypt(this.title).toString(); } else { this.title = "[protected]"; diff --git a/src/entities/note_revision.js b/src/entities/note_revision.js index 260d74894..aafef2644 100644 --- a/src/entities/note_revision.js +++ b/src/entities/note_revision.js @@ -37,7 +37,7 @@ class NoteRevision extends Entity { if (this.isProtected) { if (protectedSessionService.isProtectedSessionAvailable()) { - this.title = protectedSessionService.decrypt(this.title); + this.title = protectedSessionService.decrypt(this.title).toString(); } else { this.title = "[Protected]"; diff --git a/src/routes/api/recent_changes.js b/src/routes/api/recent_changes.js index 2ab0b13d3..fbf6fd446 100644 --- a/src/routes/api/recent_changes.js +++ b/src/routes/api/recent_changes.js @@ -41,8 +41,8 @@ async function getRecentChanges() { for (const change of recentChanges) { if (change.current_isProtected) { if (protectedSessionService.isProtectedSessionAvailable()) { - change.title = protectedSessionService.decrypt(change.title); - change.current_title = protectedSessionService.decrypt(change.current_title); + change.title = protectedSessionService.decrypt(change.title).toString(); + change.current_title = protectedSessionService.decrypt(change.current_title).toString(); } else { change.title = change.current_title = "[Protected]"; diff --git a/src/services/content_hash.js b/src/services/content_hash.js index d9f5e5073..5384a3492 100644 --- a/src/services/content_hash.js +++ b/src/services/content_hash.js @@ -34,6 +34,7 @@ async function getHashes() { note_contents: await getHash("note_contents", "noteId"), branches: await getHash(Branch.entityName, Branch.primaryKeyName), note_revisions: await getHash(NoteRevision.entityName, NoteRevision.primaryKeyName), + note_revision_contents: await getHash("note_revision_contents", "noteRevisionId"), recent_notes: await getHash(RecentNote.entityName, RecentNote.primaryKeyName), options: await getHash(Option.entityName, Option.primaryKeyName, "isSynced = 1"), attributes: await getHash(Attribute.entityName, Attribute.primaryKeyName), diff --git a/src/services/note_cache.js b/src/services/note_cache.js index 058a39a89..c51991e17 100644 --- a/src/services/note_cache.js +++ b/src/services/note_cache.js @@ -54,7 +54,7 @@ async function loadProtectedNotes() { protectedNoteTitles = await sql.getMap(`SELECT noteId, title FROM notes WHERE isDeleted = 0 AND isProtected = 1`); for (const noteId in protectedNoteTitles) { - protectedNoteTitles[noteId] = protectedSessionService.decrypt(protectedNoteTitles[noteId]); + protectedNoteTitles[noteId] = protectedSessionService.decrypt(protectedNoteTitles[noteId]).toString(); } } diff --git a/src/services/options.js b/src/services/options.js index 7a33e112b..281105388 100644 --- a/src/services/options.js +++ b/src/services/options.js @@ -4,7 +4,7 @@ async function getOption(name) { const option = await require('./repository').getOption(name); if (!option) { - throw new Error("Option " + name + " doesn't exist"); + throw new Error(`Option ${name} doesn't exist`); } return option.value; diff --git a/src/services/protected_session.js b/src/services/protected_session.js index 35b3a58d7..5c71846e9 100644 --- a/src/services/protected_session.js +++ b/src/services/protected_session.js @@ -37,7 +37,7 @@ function isProtectedSessionAvailable() { function decryptNotes(notes) { for (const note of notes) { if (note.isProtected) { - note.title = decrypt(note.title); + note.title = decrypt(note.title).toString(); } } } @@ -47,7 +47,7 @@ function encrypt(plainText) { } function decrypt(cipherText) { - return dataEncryptionService.encrypt(getDataKey(), cipherText); + return dataEncryptionService.decrypt(getDataKey(), cipherText); } module.exports = {