mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	fix saving note revisions, closes #2915
This commit is contained in:
		| @@ -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(); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -21,7 +21,8 @@ function updateFile(req) { | ||||
|         return [404, `Note ${noteId} doesn't exist.`]; | ||||
|     } | ||||
|  | ||||
|     noteRevisionService.createNoteRevision(note); | ||||
|     note.saveNoteRevision(); | ||||
|     noteRevisionService.protectNoteRevisions(note); | ||||
|  | ||||
|     note.mime = file.mimetype.toLowerCase(); | ||||
|     note.save(); | ||||
|   | ||||
| @@ -97,7 +97,8 @@ function restoreNoteRevision(req) { | ||||
|     if (noteRevision) { | ||||
|         const note = noteRevision.getNote(); | ||||
|  | ||||
|         noteRevisionService.createNoteRevision(note); | ||||
|         note.saveNoteRevision(); | ||||
|         noteRevisionService.protectNoteRevisions(note); | ||||
|  | ||||
|         note.title = noteRevision.title; | ||||
|         note.setContent(noteRevision.getContent()); | ||||
|   | ||||
| @@ -294,7 +294,8 @@ function uploadModifiedFile(req) { | ||||
|  | ||||
|     log.info(`Updating note '${noteId}' with content from ${filePath}`); | ||||
|  | ||||
|     noteRevisionService.createNoteRevision(note); | ||||
|     note.saveNoteRevision(); | ||||
|     noteRevisionService.protectNoteRevisions(note); | ||||
|  | ||||
|     const fileContent = fs.readFileSync(filePath); | ||||
|  | ||||
|   | ||||
| @@ -68,7 +68,7 @@ function updateImage(noteId, uploadBuffer, originalName) { | ||||
|  | ||||
|     const note = becca.getNote(noteId); | ||||
|  | ||||
|     noteRevisionService.createNoteRevision(note); | ||||
|     note.saveNoteRevision(); | ||||
|     noteRevisionService.protectNoteRevisions(note); | ||||
|  | ||||
|     note.setLabel('originalFileName', originalName); | ||||
|   | ||||
| @@ -1,9 +1,8 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const NoteRevision = require('../becca/entities/note_revision'); | ||||
| const dateUtils = require('./date_utils'); | ||||
| const log = require('./log'); | ||||
| const sql = require('./sql'); | ||||
| const protectedSession = require("./protected_session"); | ||||
|  | ||||
| /** | ||||
|  * @param {Note} note | ||||
| @@ -11,6 +10,12 @@ const sql = require('./sql'); | ||||
| function protectNoteRevisions(note) { | ||||
|     for (const revision of note.getNoteRevisions()) { | ||||
|         if (note.isProtected !== revision.isProtected) { | ||||
|             if (!protectedSession.isProtectedSessionAvailable()) { | ||||
|                 log.error("Protected session is not available to fix note revisions."); | ||||
|  | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             try { | ||||
|                 const content = revision.getContent(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user