mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	attachment revision upload
This commit is contained in:
		| @@ -14,15 +14,12 @@ const NotFoundError = require("../../errors/not_found_error"); | ||||
| const ValidationError = require("../../errors/validation_error.js"); | ||||
|  | ||||
| function updateFile(req) { | ||||
|     const {noteId} = req.params; | ||||
|     const file = req.file; | ||||
|  | ||||
|     const note = becca.getNote(noteId); | ||||
|  | ||||
|     const note = becca.getNote(req.params.noteId); | ||||
|     if (!note) { | ||||
|         throw new NotFoundError(`Note '${noteId}' doesn't exist.`); | ||||
|         throw new NotFoundError(`Note '${req.params.noteId}' doesn't exist.`); | ||||
|     } | ||||
|  | ||||
|     const file = req.file; | ||||
|     note.saveNoteRevision(); | ||||
|  | ||||
|     note.mime = file.mimetype.toLowerCase(); | ||||
| @@ -39,6 +36,23 @@ function updateFile(req) { | ||||
|     }; | ||||
| } | ||||
|  | ||||
| function updateAttachment(req) { | ||||
|     const attachment = becca.getAttachment(req.params.attachmentId); | ||||
|     if (!attachment) { | ||||
|         throw new NotFoundError(`Attachment '${req.params.attachmentId}' doesn't exist.`); | ||||
|     } | ||||
|  | ||||
|     const file = req.file; | ||||
|     attachment.getNote().saveNoteRevision(); | ||||
|  | ||||
|     attachment.mime = file.mimetype.toLowerCase(); | ||||
|     attachment.setContent(file.buffer, {forceSave: true}); | ||||
|  | ||||
|     return { | ||||
|         uploaded: true | ||||
|     }; | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * @param {BNote|BAttachment} noteOrAttachment | ||||
|  * @param res | ||||
| @@ -234,6 +248,7 @@ function uploadModifiedFileToAttachment(req) { | ||||
|  | ||||
| module.exports = { | ||||
|     updateFile, | ||||
|     updateAttachment, | ||||
|     openFile, | ||||
|     fileContentProvider, | ||||
|     downloadFile, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user