mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
simplified updating note content
This commit is contained in:
parent
7edcd5d746
commit
4cec856e21
@ -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,
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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)}…`)
|
||||
});
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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());
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
content = saveLinks(note, content);
|
||||
|
||||
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);
|
||||
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user