file upload WIP

This commit is contained in:
zadam
2023-06-06 12:31:38 +02:00
parent 0234ff5fca
commit 38839532d5
7 changed files with 24 additions and 29 deletions

View File

@@ -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
};

View File

@@ -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}'`);