mirror of
https://github.com/zadam/trilium.git
synced 2025-11-05 04:45:47 +01:00
file upload WIP
This commit is contained in:
@@ -35,6 +35,24 @@ function saveAttachment(req) {
|
||||
note.saveAttachment({attachmentId, role, mime, title, content});
|
||||
}
|
||||
|
||||
function uploadAttachment(req) {
|
||||
const {noteId} = req.params;
|
||||
const {file} = req;
|
||||
|
||||
const note = becca.getNoteOrThrow(noteId);
|
||||
|
||||
const attachment = note.saveAttachment({
|
||||
role: 'file',
|
||||
mime: file.mimetype,
|
||||
title: file.originalname,
|
||||
content: file.buffer
|
||||
});
|
||||
|
||||
return {
|
||||
uploaded: true
|
||||
};
|
||||
}
|
||||
|
||||
function deleteAttachment(req) {
|
||||
const {attachmentId} = req.params;
|
||||
|
||||
@@ -58,6 +76,7 @@ module.exports = {
|
||||
getAttachment,
|
||||
getAllAttachments,
|
||||
saveAttachment,
|
||||
uploadAttachment,
|
||||
deleteAttachment,
|
||||
convertAttachmentToNote
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ function uploadImage(req) {
|
||||
const {noteId} = req.query;
|
||||
const {file} = req;
|
||||
|
||||
const note = becca.getNoteOrThrow(noteId);
|
||||
becca.getNoteOrThrow(noteId);
|
||||
|
||||
if (!["image/png", "image/jpg", "image/jpeg", "image/gif", "image/webp", "image/svg+xml"].includes(file.mimetype)) {
|
||||
throw new ValidationError(`Unknown image type '${file.mimetype}'`);
|
||||
|
||||
Reference in New Issue
Block a user