diff --git a/src/controllers/01-branch-controller.ts b/src/controllers/01-branch-controller.ts index bceb729..d8d2fcb 100644 --- a/src/controllers/01-branch-controller.ts +++ b/src/controllers/01-branch-controller.ts @@ -674,4 +674,39 @@ export class BranchFileController extends Controller { await this.checkPermission(req.user, branchId); return await deleteFile(fileLocation.branch.line(branchId)); } + + @Get("attachment") + @Security("keycloak") + async listAttachment(@Request() req: RequestWithUser, @Path() branchId: string) { + await this.checkPermission(req.user, branchId); + return await listFile(fileLocation.branch.attachment(branchId)); + } + + @Get("attachment/{name}") + @Security("keycloak") + async getAttachment(@Path() branchId: string, @Path() name: string) { + return await getFile(fileLocation.branch.attachment(branchId, name)); + } + + @Put("attachment/{name}") + @Security("keycloak") + async putAttachment( + @Request() req: RequestWithUser, + @Path() branchId: string, + @Path() name: string, + ) { + await this.checkPermission(req.user, branchId); + return req.res?.redirect(await setFile(fileLocation.branch.attachment(branchId, name))); + } + + @Delete("attachment/{name}") + @Security("keycloak") + async delAttachment( + @Request() req: RequestWithUser, + @Path() branchId: string, + @Path() name: string, + ) { + await this.checkPermission(req.user, branchId); + return await deleteFile(fileLocation.branch.attachment(branchId, name)); + } } diff --git a/src/utils/minio.ts b/src/utils/minio.ts index c376eea..8aecc4c 100644 --- a/src/utils/minio.ts +++ b/src/utils/minio.ts @@ -51,6 +51,7 @@ export const fileLocation = { line: (branchId: string) => `branch/line-qr-${branchId}`, bank: (branchId: string, bankId: string) => `branch/bank-qr-${branchId}-${bankId}`, img: (branchId: string, name?: string) => `branch/img-${branchId}/${name || ""}`, + attachment: (branchId: string, name?: string) => `branch/attachment-${branchId}/${name || ""}`, }, user: { profile: (userId: string, name?: string) => `user/profile-image-${userId}/${name || ""}`,