mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	note ancillary/attachment backported from dev branch
This commit is contained in:
		| @@ -54,10 +54,10 @@ function createNote(req) { | ||||
| } | ||||
|  | ||||
| function updateNoteData(req) { | ||||
|     const {content} = req.body; | ||||
|     const {content, ancillaries} = req.body; | ||||
|     const {noteId} = req.params; | ||||
|  | ||||
|     return noteService.updateNoteData(noteId, content); | ||||
|     return noteService.updateNoteData(noteId, content, ancillaries); | ||||
| } | ||||
|  | ||||
| function deleteNote(req) { | ||||
| @@ -127,6 +127,49 @@ function setNoteTypeMime(req) { | ||||
|     note.save(); | ||||
| } | ||||
|  | ||||
| function getNoteAncillaries(req) { | ||||
|     const includeContent = req.query.includeContent === 'true'; | ||||
|     const {noteId} = req.params; | ||||
|  | ||||
|     const note = becca.getNote(noteId); | ||||
|  | ||||
|     if (!note) { | ||||
|         throw new NotFoundError(`Note '${noteId}' doesn't exist.`); | ||||
|     } | ||||
|  | ||||
|     const noteAncillaries = note.getNoteAncillaries(); | ||||
|  | ||||
|     return noteAncillaries.map(ancillary => { | ||||
|        const pojo = ancillary.getPojo(); | ||||
|  | ||||
|        if (includeContent && utils.isStringNote(null, ancillary.mime)) { | ||||
|            pojo.content = ancillary.getContent()?.toString(); | ||||
|            pojo.contentLength = pojo.content.length; | ||||
|  | ||||
|            const MAX_ANCILLARY_LENGTH = 1_000_000; | ||||
|  | ||||
|            if (pojo.content.length > MAX_ANCILLARY_LENGTH) { | ||||
|                pojo.content = pojo.content.substring(0, MAX_ANCILLARY_LENGTH); | ||||
|            } | ||||
|        } | ||||
|  | ||||
|        return pojo; | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function saveNoteAncillary(req) { | ||||
|     const {noteId, name} = req.params; | ||||
|     const {mime, content} = req.body; | ||||
|  | ||||
|     const note = becca.getNote(noteId); | ||||
|  | ||||
|     if (!note) { | ||||
|         throw new NotFoundError(`Note '${noteId}' doesn't exist.`); | ||||
|     } | ||||
|  | ||||
|     note.saveNoteAncillary(name, mime, content); | ||||
| } | ||||
|  | ||||
| function getRelationMap(req) { | ||||
|     const {relationMapNoteId, noteIds} = req.body; | ||||
|  | ||||
| @@ -340,5 +383,7 @@ module.exports = { | ||||
|     eraseDeletedNotesNow, | ||||
|     getDeleteNotesPreview, | ||||
|     uploadModifiedFile, | ||||
|     forceSaveNoteRevision | ||||
|     forceSaveNoteRevision, | ||||
|     getNoteAncillaries, | ||||
|     saveNoteAncillary | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user