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() { | 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(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -21,7 +21,8 @@ function updateFile(req) { | |||||||
|         return [404, `Note ${noteId} doesn't exist.`]; |         return [404, `Note ${noteId} doesn't exist.`]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     noteRevisionService.createNoteRevision(note); |     note.saveNoteRevision(); | ||||||
|  |     noteRevisionService.protectNoteRevisions(note); | ||||||
|  |  | ||||||
|     note.mime = file.mimetype.toLowerCase(); |     note.mime = file.mimetype.toLowerCase(); | ||||||
|     note.save(); |     note.save(); | ||||||
|   | |||||||
| @@ -97,7 +97,8 @@ function restoreNoteRevision(req) { | |||||||
|     if (noteRevision) { |     if (noteRevision) { | ||||||
|         const note = noteRevision.getNote(); |         const note = noteRevision.getNote(); | ||||||
|  |  | ||||||
|         noteRevisionService.createNoteRevision(note); |         note.saveNoteRevision(); | ||||||
|  |         noteRevisionService.protectNoteRevisions(note); | ||||||
|  |  | ||||||
|         note.title = noteRevision.title; |         note.title = noteRevision.title; | ||||||
|         note.setContent(noteRevision.getContent()); |         note.setContent(noteRevision.getContent()); | ||||||
|   | |||||||
| @@ -294,7 +294,8 @@ 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(); | ||||||
|  |     noteRevisionService.protectNoteRevisions(note); | ||||||
|  |  | ||||||
|     const fileContent = fs.readFileSync(filePath); |     const fileContent = fs.readFileSync(filePath); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -68,7 +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); |     noteRevisionService.protectNoteRevisions(note); | ||||||
|  |  | ||||||
|     note.setLabel('originalFileName', originalName); |     note.setLabel('originalFileName', originalName); | ||||||
|   | |||||||
| @@ -1,9 +1,8 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const NoteRevision = require('../becca/entities/note_revision'); |  | ||||||
| const dateUtils = require('./date_utils'); |  | ||||||
| const log = require('./log'); | const log = require('./log'); | ||||||
| const sql = require('./sql'); | const sql = require('./sql'); | ||||||
|  | const protectedSession = require("./protected_session"); | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @param {Note} note |  * @param {Note} note | ||||||
| @@ -11,6 +10,12 @@ const sql = require('./sql'); | |||||||
| function protectNoteRevisions(note) { | function protectNoteRevisions(note) { | ||||||
|     for (const revision of note.getNoteRevisions()) { |     for (const revision of note.getNoteRevisions()) { | ||||||
|         if (note.isProtected !== revision.isProtected) { |         if (note.isProtected !== revision.isProtected) { | ||||||
|  |             if (!protectedSession.isProtectedSessionAvailable()) { | ||||||
|  |                 log.error("Protected session is not available to fix note revisions."); | ||||||
|  |  | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
|                 const content = revision.getContent(); |                 const content = revision.getContent(); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user