Add file handlers, s3 support

This commit is contained in:
2024-12-27 12:46:28 +05:30
parent 88046d6810
commit 40b2ab54f0
11 changed files with 1533 additions and 0 deletions

50
src/file/file.route.ts Normal file
View File

@@ -0,0 +1,50 @@
import { FastifyInstance } from "fastify";
import {
deleteFileHandler,
fileDownloadHandler,
fileUploadHandler,
} from "./file.controller";
import { $file } from "./file.schema";
export async function fileRoutes(fastify: FastifyInstance) {
fastify.post(
"/upload",
{
schema: {
response: {
201: $file("uploadFileResponse"),
},
},
config: { requiredClaims: ["file:upload"] },
preHandler: [fastify.authorize],
},
fileUploadHandler
);
fastify.get(
"/:fileId",
{
schema: {
params: { type: "object", properties: { fileId: { type: "string" } } },
response: {
200: $file("downloadFileResponse"),
},
},
config: { requiredClaims: ["file:download"] },
preHandler: [fastify.authorize],
},
fileDownloadHandler
);
fastify.delete(
"/:fileId",
{
schema: {
params: { type: "object", properties: { fileId: { type: "string" } } },
},
config: { requiredClaims: ["file:delete"] },
preHandler: [fastify.authorize],
},
deleteFileHandler
);
}