Skip to content

Build your personal knowledge base with Trilium Notes

simplified updating note content

zadam4cec856e217e
diff --git a/src/becca/entities/note.js b/src/becca/entities/note.js
index 17b5b716f8..01288a9fb4 100644
--- a/src/becca/entities/note.js
+++ b/src/becca/entities/note.js
@@ -1222,7 +1222,7 @@ class Note extends AbstractEntity {
title: this.title,
type: this.type,
mime: this.mime,
- isProtected: false, // will be fixed in the protectNoteRevisions() call
+ isProtected: this.isProtected,
utcDateLastEdited: this.utcDateModified > contentMetadata.utcDateModified
? this.utcDateModified
: contentMetadata.utcDateModified,
diff --git a/src/public/app/services/utils.js b/src/public/app/services/utils.js
index 7544a3075e..aabbdb8f00 100644
--- a/src/public/app/services/utils.js
+++ b/src/public/app/services/utils.js
@@ -280,7 +280,7 @@ function isHtmlEmpty(html) {
async function clearBrowserCache() {
if (isElectron()) {
- const win = utils.dynamicRequire('@electron/remote').getCurrentWindow();
+ const win = dynamicRequire('@electron/remote').getCurrentWindow();
await win.webContents.session.clearCache();
}
}
diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js
index 692439d239..07aa7e2e2b 100644
--- a/src/public/app/widgets/note_detail.js
+++ b/src/public/app/widgets/note_detail.js
@@ -70,17 +70,16 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
const {note} = this.noteContext;
const {noteId} = note;
- const dto = note.dto;
- dto.content = await this.getTypeWidget().getContent();
+ const content = await this.getTypeWidget().getContent();
// for read only notes
- if (dto.content === undefined) {
+ if (content === undefined) {
return;
}
protectedSessionHolder.touchProtectedSessionIfNecessary(note);
- await server.put('notes/' + noteId, dto, this.componentId);
+ await server.put(`notes/${noteId}/content`, {content}, this.componentId);
});
appContext.addBeforeUnloadListener(this);
diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js
index 2cbd9b5a1d..030ec4578b 100644
--- a/src/public/app/widgets/note_title.js
+++ b/src/public/app/widgets/note_title.js
@@ -38,7 +38,7 @@ export default class NoteTitleWidget extends NoteContextAwareWidget {
protectedSessionHolder.touchProtectedSessionIfNecessary(this.note);
- await server.put(`notes/${this.noteId}/change-title`, {title}, this.componentId);
+ await server.put(`notes/${this.noteId}/title`, {title}, this.componentId);
});
this.deleteNoteOnEscape = false;
diff --git a/src/public/app/widgets/search_options/search_string.js b/src/public/app/widgets/search_options/search_string.js
index 1f49c0b0dd..beb4deeedb 100644
--- a/src/public/app/widgets/search_options/search_string.js
+++ b/src/public/app/widgets/search_options/search_string.js
@@ -60,7 +60,7 @@ export default class SearchString extends AbstractSearchOption {
await this.setAttribute('label', 'searchString', searchString);
if (this.note.title.startsWith('Search: ')) {
- await server.put(`notes/${this.note.noteId}/change-title`, {
+ await server.put(`notes/${this.note.noteId}/title`, {
title: 'Search: ' + (searchString.length < 30 ? searchString : `${searchString.substr(0, 30)}…`)
});
}
diff --git a/src/public/app/widgets/type_widgets/relation_map.js b/src/public/app/widgets/type_widgets/relation_map.js
index 69b9781c82..c9207107f7 100644
--- a/src/public/app/widgets/type_widgets/relation_map.js
+++ b/src/public/app/widgets/type_widgets/relation_map.js
@@ -228,7 +228,7 @@ export default class RelationMapTypeWidget extends TypeWidget {
return;
}
- await server.put(`notes/${noteId}/change-title`, { title });
+ await server.put(`notes/${noteId}/title`, { title });
$title.text(title);
}
diff --git a/src/routes/api/files.js b/src/routes/api/files.js
index 7b0dc751d8..cb2760665b 100644
--- a/src/routes/api/files.js
+++ b/src/routes/api/files.js
@@ -21,7 +21,7 @@ function updateFile(req) {
return [404, `Note ${noteId} doesn't exist.`];
}
- noteRevisionService.createNoteRevision(note);
+ note.saveNoteRevision();
note.mime = file.mimetype.toLowerCase();
note.save();
@@ -30,8 +30,6 @@ function updateFile(req) {
note.setLabel('originalFileName', file.originalname);
- noteRevisionService.protectNoteRevisions(note);
-
return {
uploaded: true
};
diff --git a/src/routes/api/note_revisions.js b/src/routes/api/note_revisions.js
index 93c792c564..0e058f3bc2 100644
--- a/src/routes/api/note_revisions.js
+++ b/src/routes/api/note_revisions.js
@@ -97,7 +97,7 @@ function restoreNoteRevision(req) {
if (noteRevision) {
const note = noteRevision.getNote();
- noteRevisionService.createNoteRevision(note);
+ note.saveNoteRevision();
note.title = noteRevision.title;
note.setContent(noteRevision.getContent());
diff --git a/src/routes/api/notes.js b/src/routes/api/notes.js
index a2aef1dfae..64a218d505 100644
--- a/src/routes/api/notes.js
+++ b/src/routes/api/notes.js
@@ -53,11 +53,11 @@ function createNote(req) {
};
}
-function updateNote(req) {
- const note = req.body;
- const noteId = req.params.noteId;
+function updateNoteContent(req) {
+ const {content} = req.body;
+ const {noteId} = req.params;
- return noteService.updateNote(noteId, note);
+ return noteService.updateNoteContent(noteId, content);
}
function deleteNote(req) {
@@ -294,7 +294,7 @@ function uploadModifiedFile(req) {
log.info(`Updating note '${noteId}' with content from ${filePath}`);
- noteRevisionService.createNoteRevision(note);
+ note.saveNoteRevision();
const fileContent = fs.readFileSync(filePath);
@@ -322,7 +322,7 @@ function getBacklinkCount(req) {
module.exports = {
getNote,
- updateNote,
+ updateNoteContent,
deleteNote,
undeleteNote,
createNote,
diff --git a/src/routes/routes.js b/src/routes/routes.js
index b9f2d5e5ee..2719936ca1 100644
--- a/src/routes/routes.js
+++ b/src/routes/routes.js
@@ -218,7 +218,7 @@ function register(app) {
apiRoute(GET, '/api/autocomplete', autocompleteApiRoute.getAutocomplete);
apiRoute(GET, '/api/notes/:noteId', notesApiRoute.getNote);
- apiRoute(PUT, '/api/notes/:noteId', notesApiRoute.updateNote);
+ apiRoute(PUT, '/api/notes/:noteId/content', notesApiRoute.updateNoteContent);
apiRoute(DELETE, '/api/notes/:noteId', notesApiRoute.deleteNote);
apiRoute(PUT, '/api/notes/:noteId/undelete', notesApiRoute.undeleteNote);
apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote);
@@ -234,7 +234,7 @@ function register(app) {
apiRoute(GET, '/api/notes/:noteId/backlink-count', notesApiRoute.getBacklinkCount);
apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap);
apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow);
- apiRoute(PUT, '/api/notes/:noteId/change-title', notesApiRoute.changeTitle);
+ apiRoute(PUT, '/api/notes/:noteId/title', notesApiRoute.changeTitle);
apiRoute(POST, '/api/notes/:noteId/duplicate/:parentNoteId', notesApiRoute.duplicateSubtree);
apiRoute(POST, '/api/notes/:noteId/upload-modified-file', notesApiRoute.uploadModifiedFile);
diff --git a/src/services/image.js b/src/services/image.js
index 4c64e8ee55..9a4a2b1be0 100644
--- a/src/services/image.js
+++ b/src/services/image.js
@@ -68,8 +68,7 @@ function updateImage(noteId, uploadBuffer, originalName) {
const note = becca.getNote(noteId);
- noteRevisionService.createNoteRevision(note);
- noteRevisionService.protectNoteRevisions(note);
+ note.saveNoteRevision();
note.setLabel('originalFileName', originalName);
diff --git a/src/services/notes.js b/src/services/notes.js
index 69633c681d..01c3cc1d4d 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -520,7 +520,7 @@ function saveNoteRevisionIfNeeded(note) {
}
}
-function updateNote(noteId, noteUpdates) {
+function updateNoteContent(noteId, content) {
const note = becca.getNote(noteId);
if (!note.isContentAvailable()) {
@@ -529,33 +529,9 @@ function updateNote(noteId, noteUpdates) {
saveNoteRevisionIfNeeded(note);
- // if protected status changed, then we need to encrypt/decrypt the content anyway
- if (['file', 'image'].includes(note.type) && note.isProtected !== noteUpdates.isProtected) {
- noteUpdates.content = note.getContent();
- }
-
- const noteTitleChanged = note.title !== noteUpdates.title;
-
- note.title = noteUpdates.title;
- note.isProtected = noteUpdates.isProtected;
- note.save();
-
- if (noteUpdates.content !== undefined && noteUpdates.content !== null) {
- noteUpdates.content = saveLinks(note, noteUpdates.content);
-
- note.setContent(noteUpdates.content);
- }
-
- if (noteTitleChanged) {
- triggerNoteTitleChanged(note);
- }
-
- noteRevisionService.protectNoteRevisions(note);
+ content = saveLinks(note, content);
- return {
- dateModified: note.dateModified,
- utcDateModified: note.utcDateModified
- };
+ note.setContent(content);
}
/**
@@ -908,7 +884,7 @@ sqlInit.dbReady.then(() => {
module.exports = {
createNewNote,
createNewNoteWithTarget,
- updateNote,
+ updateNoteContent,
undeleteNote,
protectNoteRecursively,
scanForLinks,