feat: add new endpoint for get or download file
This commit is contained in:
parent
9c8786bf62
commit
91f7cf2a9b
1 changed files with 27 additions and 0 deletions
|
|
@ -556,6 +556,33 @@ export class CustomerAttachmentController extends Controller {
|
|||
return list.map((v) => v.split("/").at(-1) as string);
|
||||
}
|
||||
|
||||
@Get("{filename}")
|
||||
async getAttachment(
|
||||
@Request() req: RequestWithUser,
|
||||
@Path() branchId: string,
|
||||
@Path() filename: string,
|
||||
) {
|
||||
const record = await prisma.customerBranch.findFirst({
|
||||
where: { id: branchId },
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
throw new HttpError(
|
||||
HttpStatus.NOT_FOUND,
|
||||
"Customer branch cannot be found.",
|
||||
"customerBranchNotFound",
|
||||
);
|
||||
}
|
||||
|
||||
return req.res?.redirect(
|
||||
await minio.presignedGetObject(
|
||||
MINIO_BUCKET,
|
||||
`${attachmentLocation(record.customerId, branchId)}/${filename}`,
|
||||
12 * 60 * 60,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@Put("{filename}")
|
||||
async addAttachment(
|
||||
@Request() req: RequestWithUser,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue