mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	save note in clipper
This commit is contained in:
		| @@ -10,48 +10,44 @@ const path = require('path'); | ||||
| const Link = require('../../entities/link'); | ||||
|  | ||||
| async function createNote(req) { | ||||
|     const {title, html, url, images} = req.body; | ||||
|     const {title, content, url, images} = req.body; | ||||
|  | ||||
|     const todayNote = await dateNoteService.getDateNote(dateUtils.localNowDate()); | ||||
|  | ||||
|     const {note} = await noteService.createNote(todayNote.noteId, title, html, { | ||||
|         attributes: [ | ||||
|             { | ||||
|                 type: 'label', | ||||
|                 name: 'sourceUrl', | ||||
|                 value: url | ||||
|             } | ||||
|         ] | ||||
|     }); | ||||
|     const {note} = await noteService.createNote(todayNote.noteId, title, content); | ||||
|  | ||||
|     let rewrittenHtml = html; | ||||
|  | ||||
|     for (const {src, dataUrl, imageId} of images) { | ||||
|         const filename = path.basename(src); | ||||
|  | ||||
|         if (!dataUrl.startsWith("data:image")) { | ||||
|             log.info("Image could not be recognized as data URL:", dataUrl.substr(0, Math.min(100, dataUrl.length))); | ||||
|             continue; | ||||
|         } | ||||
|  | ||||
|         const buffer = Buffer.from(dataUrl.split(",")[1], 'base64'); | ||||
|  | ||||
|         const {note: imageNote, url} = await imageService.saveImage(buffer, filename, note.noteId, true); | ||||
|  | ||||
|         await new Link({ | ||||
|             noteId: note.noteId, | ||||
|             targetNoteId: imageNote.noteId, | ||||
|             type: 'image' | ||||
|         }).save(); | ||||
|  | ||||
|         console.log(`Replacing ${imageId} with ${url}`); | ||||
|  | ||||
|         rewrittenHtml = rewrittenHtml.replace(imageId, url); | ||||
|     if (url) { | ||||
|         await note.setLabel('sourceUrl', url); | ||||
|     } | ||||
|  | ||||
|     console.log("Done", rewrittenHtml); | ||||
|     let rewrittenContent = content; | ||||
|  | ||||
|     await note.setContent(rewrittenHtml); | ||||
|     if (images) { | ||||
|         for (const {src, dataUrl, imageId} of images) { | ||||
|             const filename = path.basename(src); | ||||
|  | ||||
|             if (!dataUrl.startsWith("data:image")) { | ||||
|                 log.info("Image could not be recognized as data URL:", dataUrl.substr(0, Math.min(100, dataUrl.length))); | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             const buffer = Buffer.from(dataUrl.split(",")[1], 'base64'); | ||||
|  | ||||
|             const {note: imageNote, url} = await imageService.saveImage(buffer, filename, note.noteId, true); | ||||
|  | ||||
|             await new Link({ | ||||
|                 noteId: note.noteId, | ||||
|                 targetNoteId: imageNote.noteId, | ||||
|                 type: 'image' | ||||
|             }).save(); | ||||
|  | ||||
|             console.log(`Replacing ${imageId} with ${url}`); | ||||
|  | ||||
|             rewrittenContent = rewrittenContent.replace(imageId, url); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     await note.setContent(rewrittenContent); | ||||
|  | ||||
|     return { | ||||
|         noteId: note.noteId | ||||
| @@ -105,6 +101,8 @@ async function openNote(req) { | ||||
|         type: 'open-note', | ||||
|         noteId: req.params.noteId | ||||
|     }); | ||||
|  | ||||
|     return {}; | ||||
| } | ||||
|  | ||||
| async function ping(req, res) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user