rename attachment

This commit is contained in:
zadam
2023-06-14 00:28:59 +02:00
parent 2ebbc33081
commit 34c642a49a
7 changed files with 40 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
const becca = require("../../becca/becca");
const blobService = require("../../services/blob.js");
const ValidationError = require("../../errors/validation_error");
function getAttachmentBlob(req) {
const preview = req.query.preview === 'true';
@@ -41,7 +42,7 @@ function uploadAttachment(req) {
const note = becca.getNoteOrThrow(noteId);
const attachment = note.saveAttachment({
note.saveAttachment({
role: 'file',
mime: file.mimetype,
title: file.originalname,
@@ -53,6 +54,20 @@ function uploadAttachment(req) {
};
}
function renameAttachment(req) {
const {title} = req.body;
const {attachmentId} = req.params;
const attachment = becca.getAttachmentOrThrow(attachmentId);
if (!title?.trim()) {
throw new ValidationError("Title must not be empty");
}
attachment.title = title;
attachment.save();
}
function deleteAttachment(req) {
const {attachmentId} = req.params;
@@ -77,6 +92,7 @@ module.exports = {
getAllAttachments,
saveAttachment,
uploadAttachment,
renameAttachment,
deleteAttachment,
convertAttachmentToNote
};