92 lines
1.9 KiB
TypeScript
92 lines
1.9 KiB
TypeScript
import { FastifyInstance } from "fastify";
|
|
import {
|
|
deleteFileHandler,
|
|
fileDownloadHandler,
|
|
fileUploadHandler,
|
|
fileUploadS3UrlHandler,
|
|
fileUploadS3UrlMultiPartHandler,
|
|
finishMulitPartUploadHandler,
|
|
} 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
|
|
);
|
|
|
|
fastify.get(
|
|
"/",
|
|
{
|
|
config: { requiredClaims: ["file:upload"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
fileUploadS3UrlHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/multipart",
|
|
{
|
|
schema: {
|
|
querystring: {
|
|
type: "object",
|
|
properties: {
|
|
fileSize: { type: "number" },
|
|
},
|
|
},
|
|
},
|
|
config: { requiredClaims: ["file:upload"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
fileUploadS3UrlMultiPartHandler
|
|
);
|
|
|
|
fastify.post(
|
|
"/multipart/complete",
|
|
{
|
|
schema: {
|
|
body: $file("uploadMultipartCompleteRequest"),
|
|
},
|
|
config: { requiredClaims: ["file:upload"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
finishMulitPartUploadHandler
|
|
);
|
|
}
|