simplified updating note content

This commit is contained in:
zadam 2022-06-13 22:38:59 +02:00
parent 7edcd5d746
commit 4cec856e21
12 changed files with 23 additions and 51 deletions

View File

@ -1222,7 +1222,7 @@ class Note extends AbstractEntity {
title: this.title, title: this.title,
type: this.type, type: this.type,
mime: this.mime, mime: this.mime,
isProtected: false, // will be fixed in the protectNoteRevisions() call isProtected: this.isProtected,
utcDateLastEdited: this.utcDateModified > contentMetadata.utcDateModified utcDateLastEdited: this.utcDateModified > contentMetadata.utcDateModified
? this.utcDateModified ? this.utcDateModified
: contentMetadata.utcDateModified, : contentMetadata.utcDateModified,

View File

@ -280,7 +280,7 @@ function isHtmlEmpty(html) {
async function clearBrowserCache() { async function clearBrowserCache() {
if (isElectron()) { if (isElectron()) {
const win = utils.dynamicRequire('@electron/remote').getCurrentWindow(); const win = dynamicRequire('@electron/remote').getCurrentWindow();
await win.webContents.session.clearCache(); await win.webContents.session.clearCache();
} }
} }

View File

@ -70,17 +70,16 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
const {note} = this.noteContext; const {note} = this.noteContext;
const {noteId} = note; const {noteId} = note;
const dto = note.dto; const content = await this.getTypeWidget().getContent();
dto.content = await this.getTypeWidget().getContent();
// for read only notes // for read only notes
if (dto.content === undefined) { if (content === undefined) {
return; return;
} }
protectedSessionHolder.touchProtectedSessionIfNecessary(note); protectedSessionHolder.touchProtectedSessionIfNecessary(note);
await server.put('notes/' + noteId, dto, this.componentId); await server.put(`notes/${noteId}/content`, {content}, this.componentId);
}); });
appContext.addBeforeUnloadListener(this); appContext.addBeforeUnloadListener(this);

View File

@ -38,7 +38,7 @@ export default class NoteTitleWidget extends NoteContextAwareWidget {
protectedSessionHolder.touchProtectedSessionIfNecessary(this.note); 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; this.deleteNoteOnEscape = false;

View File

@ -60,7 +60,7 @@ export default class SearchString extends AbstractSearchOption {
await this.setAttribute('label', 'searchString', searchString); await this.setAttribute('label', 'searchString', searchString);
if (this.note.title.startsWith('Search: ')) { 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)}`) title: 'Search: ' + (searchString.length < 30 ? searchString : `${searchString.substr(0, 30)}`)
}); });
} }

View File

@ -228,7 +228,7 @@ export default class RelationMapTypeWidget extends TypeWidget {
return; return;
} }
await server.put(`notes/${noteId}/change-title`, { title }); await server.put(`notes/${noteId}/title`, { title });
$title.text(title); $title.text(title);
} }

View File

@ -21,7 +21,7 @@ function updateFile(req) {
return [404, `Note ${noteId} doesn't exist.`]; return [404, `Note ${noteId} doesn't exist.`];
} }
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
note.mime = file.mimetype.toLowerCase(); note.mime = file.mimetype.toLowerCase();
note.save(); note.save();
@ -30,8 +30,6 @@ function updateFile(req) {
note.setLabel('originalFileName', file.originalname); note.setLabel('originalFileName', file.originalname);
noteRevisionService.protectNoteRevisions(note);
return { return {
uploaded: true uploaded: true
}; };

View File

@ -97,7 +97,7 @@ function restoreNoteRevision(req) {
if (noteRevision) { if (noteRevision) {
const note = noteRevision.getNote(); const note = noteRevision.getNote();
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
note.title = noteRevision.title; note.title = noteRevision.title;
note.setContent(noteRevision.getContent()); note.setContent(noteRevision.getContent());

View File

@ -53,11 +53,11 @@ function createNote(req) {
}; };
} }
function updateNote(req) { function updateNoteContent(req) {
const note = req.body; const {content} = req.body;
const noteId = req.params.noteId; const {noteId} = req.params;
return noteService.updateNote(noteId, note); return noteService.updateNoteContent(noteId, content);
} }
function deleteNote(req) { function deleteNote(req) {
@ -294,7 +294,7 @@ function uploadModifiedFile(req) {
log.info(`Updating note '${noteId}' with content from ${filePath}`); log.info(`Updating note '${noteId}' with content from ${filePath}`);
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
const fileContent = fs.readFileSync(filePath); const fileContent = fs.readFileSync(filePath);
@ -322,7 +322,7 @@ function getBacklinkCount(req) {
module.exports = { module.exports = {
getNote, getNote,
updateNote, updateNoteContent,
deleteNote, deleteNote,
undeleteNote, undeleteNote,
createNote, createNote,

View File

@ -218,7 +218,7 @@ function register(app) {
apiRoute(GET, '/api/autocomplete', autocompleteApiRoute.getAutocomplete); apiRoute(GET, '/api/autocomplete', autocompleteApiRoute.getAutocomplete);
apiRoute(GET, '/api/notes/:noteId', notesApiRoute.getNote); 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(DELETE, '/api/notes/:noteId', notesApiRoute.deleteNote);
apiRoute(PUT, '/api/notes/:noteId/undelete', notesApiRoute.undeleteNote); apiRoute(PUT, '/api/notes/:noteId/undelete', notesApiRoute.undeleteNote);
apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote); 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(GET, '/api/notes/:noteId/backlink-count', notesApiRoute.getBacklinkCount);
apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap); apiRoute(POST, '/api/notes/relation-map', notesApiRoute.getRelationMap);
apiRoute(POST, '/api/notes/erase-deleted-notes-now', notesApiRoute.eraseDeletedNotesNow); 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/duplicate/:parentNoteId', notesApiRoute.duplicateSubtree);
apiRoute(POST, '/api/notes/:noteId/upload-modified-file', notesApiRoute.uploadModifiedFile); apiRoute(POST, '/api/notes/:noteId/upload-modified-file', notesApiRoute.uploadModifiedFile);

View File

@ -68,8 +68,7 @@ function updateImage(noteId, uploadBuffer, originalName) {
const note = becca.getNote(noteId); const note = becca.getNote(noteId);
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
noteRevisionService.protectNoteRevisions(note);
note.setLabel('originalFileName', originalName); note.setLabel('originalFileName', originalName);

View File

@ -520,7 +520,7 @@ function saveNoteRevisionIfNeeded(note) {
} }
} }
function updateNote(noteId, noteUpdates) { function updateNoteContent(noteId, content) {
const note = becca.getNote(noteId); const note = becca.getNote(noteId);
if (!note.isContentAvailable()) { if (!note.isContentAvailable()) {
@ -529,33 +529,9 @@ function updateNote(noteId, noteUpdates) {
saveNoteRevisionIfNeeded(note); saveNoteRevisionIfNeeded(note);
// if protected status changed, then we need to encrypt/decrypt the content anyway content = saveLinks(note, content);
if (['file', 'image'].includes(note.type) && note.isProtected !== noteUpdates.isProtected) {
noteUpdates.content = note.getContent();
}
const noteTitleChanged = note.title !== noteUpdates.title; note.setContent(content);
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
};
} }
/** /**
@ -908,7 +884,7 @@ sqlInit.dbReady.then(() => {
module.exports = { module.exports = {
createNewNote, createNewNote,
createNewNoteWithTarget, createNewNoteWithTarget,
updateNote, updateNoteContent,
undeleteNote, undeleteNote,
protectNoteRecursively, protectNoteRecursively,
scanForLinks, scanForLinks,