Hemmelig.app/server/decorators/attachment-upload.js
bjarneo 0c86efd56c
refactor: use fastify vite for the dev server (#284)
* refactor: use fastify vite for the server

by doing this we do not need to have local hacks for the routes. No local proxy needed. Everything just works.

* fix: update the dockerfile build path

* fix: update package.json

* fix: fonts path
2024-03-11 13:43:20 +01:00

34 lines
1020 B
JavaScript

import fp from 'fastify-plugin';
import fileAdapter from '../services/file-adapter.js';
export default fp(async (fastify) => {
fastify.decorate('attachment', async (req, reply) => {
req.secret = {
files: [],
};
const { files, isPublic } = await req.body;
if (!isPublic && files?.length) {
for (const file of files) {
try {
const imageData = await fileAdapter.upload(file.content);
req.secret.files.push({
type: file.type,
ext: file.ext,
key: imageData.key,
});
} catch (error) {
console.error(error.message);
return reply.code(403).send({
type: 'files',
error: `Something went wrong uploading your files. Please try again.`,
});
}
}
}
});
});