This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.

44 lines
1007 B
TypeScript

import path from "node:path"
import type { FastifyPluginAsync, FastifySchema } from "fastify"
import type { Static } from "@sinclair/typebox"
import { Type } from "@sinclair/typebox"
import { fastifyErrors } from "#src/models/utils.js"
const parameters = Type.Object({
file: Type.String(),
})
type Parameters = Static<typeof parameters>
export const getServiceSchema: FastifySchema = {
tags: ["messages"] as string[],
params: parameters,
response: {
200: {
type: "string",
format: "binary",
},
400: fastifyErrors[400],
404: fastifyErrors[404],
500: fastifyErrors[500],
},
} as const
export const getMessagesUploadsService: FastifyPluginAsync = async (
fastify,
) => {
fastify.route<{
Params: Parameters
}>({
method: "GET",
url: "/uploads/messages/:file",
schema: getServiceSchema,
handler: async (request, reply) => {
const { file } = request.params
return await reply.sendFile(path.join("messages", file))
},
})
}