attachment revision upload

This commit is contained in:
zadam
2023-05-03 22:49:24 +02:00
parent d8bc9c2982
commit cd01886eb2
11 changed files with 69 additions and 22 deletions

View File

@@ -14,15 +14,12 @@ const NotFoundError = require("../../errors/not_found_error");
const ValidationError = require("../../errors/validation_error.js");
function updateFile(req) {
const {noteId} = req.params;
const file = req.file;
const note = becca.getNote(noteId);
const note = becca.getNote(req.params.noteId);
if (!note) {
throw new NotFoundError(`Note '${noteId}' doesn't exist.`);
throw new NotFoundError(`Note '${req.params.noteId}' doesn't exist.`);
}
const file = req.file;
note.saveNoteRevision();
note.mime = file.mimetype.toLowerCase();
@@ -39,6 +36,23 @@ function updateFile(req) {
};
}
function updateAttachment(req) {
const attachment = becca.getAttachment(req.params.attachmentId);
if (!attachment) {
throw new NotFoundError(`Attachment '${req.params.attachmentId}' doesn't exist.`);
}
const file = req.file;
attachment.getNote().saveNoteRevision();
attachment.mime = file.mimetype.toLowerCase();
attachment.setContent(file.buffer, {forceSave: true});
return {
uploaded: true
};
}
/**
* @param {BNote|BAttachment} noteOrAttachment
* @param res
@@ -234,6 +248,7 @@ function uploadModifiedFileToAttachment(req) {
module.exports = {
updateFile,
updateAttachment,
openFile,
fileContentProvider,
downloadFile,