Skip to content

Build your personal knowledge base with Trilium Notes

fix isProtected consistency for images and files + related consistency check

zadama432ad74834f
diff --git a/package-lock.json b/package-lock.json
index ed2f68159e..2c7112a538 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "trilium",
- "version": "0.30.3-beta",
+ "version": "0.30.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js
index c2f7c3393c..1cd8b55ba7 100644
--- a/src/public/javascripts/services/note_detail.js
+++ b/src/public/javascripts/services/note_detail.js
@@ -117,7 +117,10 @@ async function saveNote() {
}
note.title = $noteTitle.val();
- note.noteContent.content = getCurrentNoteContent(note);
+
+ if (note.noteContent != null) { // might be null for file/image
+ note.noteContent.content = getCurrentNoteContent(note);
+ }
// it's important to set the flag back to false immediatelly after retrieving title and content
// otherwise we might overwrite another change (especially async code)
diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js
index 208fbc8a50..8a351873d0 100644
--- a/src/services/consistency_checks.js
+++ b/src/services/consistency_checks.js
@@ -357,6 +357,13 @@ async function findLogicIssues() {
logFix(`Removed link ${linkId} because target note ${targetNoteId} is also deleted.`);
});
+
+ await findIssues(`
+ SELECT noteId
+ FROM notes
+ JOIN note_contents USING(noteId)
+ WHERE notes.isDeleted = 0 AND notes.isProtected != note_contents.isProtected`,
+ ({noteId}) => `Note ${noteId} has inconsistent isProtected in notes and note_contents tables`);
}
async function runSyncRowChecks(entityName, key) {
diff --git a/src/services/notes.js b/src/services/notes.js
index 623fbc1c56..7509956bf4 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -332,19 +332,21 @@ async function updateNote(noteId, noteUpdates) {
const noteTitleChanged = note.title !== noteUpdates.title;
- noteUpdates.noteContent.content = await saveLinks(note, noteUpdates.noteContent.content);
-
note.title = noteUpdates.title;
note.isProtected = noteUpdates.isProtected;
await note.save();
- if (note.type !== 'file' && note.type !== 'image') {
- const noteContent = await note.getNoteContent();
+ const noteContent = await note.getNoteContent();
+
+ if (!['file', 'image'].includes(note.type)) {
+ noteUpdates.noteContent.content = await saveLinks(note, noteUpdates.noteContent.content);
+
noteContent.content = noteUpdates.noteContent.content;
- noteContent.isProtected = noteUpdates.isProtected;
- await noteContent.save();
}
+ noteContent.isProtected = noteUpdates.isProtected;
+ await noteContent.save();
+
if (noteTitleChanged) {
await triggerNoteTitleChanged(note);
}