mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	file/attachment upload, wiP
This commit is contained in:
		
							
								
								
									
										36
									
								
								src/routes/api/attachments.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/routes/api/attachments.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| "use strict"; | ||||
|  | ||||
| const express = require('express'); | ||||
| const router = express.Router(); | ||||
| const sql = require('../../services/sql'); | ||||
| const auth = require('../../services/auth'); | ||||
| const notes = require('../../services/notes'); | ||||
| const multer = require('multer')(); | ||||
| const wrap = require('express-promise-wrap').wrap; | ||||
|  | ||||
| router.post('/upload/:parentNoteId', auth.checkApiAuthOrElectron, multer.single('upload'), wrap(async (req, res, next) => { | ||||
|     const sourceId = req.headers.source_id; | ||||
|     const parentNoteId = req.params.parentNoteId; | ||||
|     const file = req.file; | ||||
|  | ||||
|     const note = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [parentNoteId]); | ||||
|  | ||||
|     if (!note) { | ||||
|         return res.status(404).send(`Note ${parentNoteId} doesn't exist.`); | ||||
|     } | ||||
|  | ||||
|     const noteId = (await notes.createNewNote(parentNoteId, { | ||||
|         title: "attachment", | ||||
|         content: file.buffer, | ||||
|         target: 'into', | ||||
|         isProtected: false, | ||||
|         type: 'file', | ||||
|         mime: '' | ||||
|     })).noteId; | ||||
|  | ||||
|     res.send({ | ||||
|         noteId: noteId | ||||
|     }); | ||||
| })); | ||||
|  | ||||
| module.exports = router; | ||||
		Reference in New Issue
	
	Block a user