This commit is contained in:
33
server/routes/attachments.ts
Normal file
33
server/routes/attachments.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import type { FastifyInstance } from 'fastify'
|
||||
import bcrypt from 'bcrypt'
|
||||
import { z } from 'zod'
|
||||
|
||||
export default function (fastify: FastifyInstance) {
|
||||
fastify.post('/attachments/upload', async (req, reply) => {
|
||||
try {
|
||||
const schema = z.object({
|
||||
file: z.file(),
|
||||
})
|
||||
const input = schema.parse(req.body)
|
||||
|
||||
// const file = req.file({ limits: { } })
|
||||
|
||||
const id = await bcrypt.hash(input.file, 10)
|
||||
|
||||
return {
|
||||
id,
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
fastify.log.error(err)
|
||||
reply.code(400)
|
||||
|
||||
if (err instanceof z.ZodError) {
|
||||
reply.send({ error: z.prettifyError(err) })
|
||||
}
|
||||
else {
|
||||
reply.send({ error: err.message })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user