* 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
34 lines
1020 B
JavaScript
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.`,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|