Merge branch 'develop' into adiDev
This commit is contained in:
commit
edbb502a0e
2 changed files with 60 additions and 0 deletions
46
src/controllers/AvatarFileController.ts
Normal file
46
src/controllers/AvatarFileController.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import {
|
||||
Controller,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Post,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
} from "tsoa";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { duplicateAvatarFile } from "../services/minio";
|
||||
|
||||
@Route("api/v1/salary/file/avatar")
|
||||
@Tags("Avatar")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class AvatarFileController extends Controller {
|
||||
|
||||
/**
|
||||
* API duplicate avatar file
|
||||
*
|
||||
* @summary API duplicate avatar file
|
||||
*
|
||||
* @param {string} refId objectRefId ไฟล์รูปภาพเดิมก่อนจะทำซ้ำเพื่อสร้างใหม่เป็นรูปภาพในทะเบียนประวัติ
|
||||
*/
|
||||
@Post("{refId}")
|
||||
@SuccessResponse(200, "Success")
|
||||
public async duplicateAvatarFile(
|
||||
@Path() refId: string,
|
||||
@Body()
|
||||
body: {
|
||||
prefix: string,
|
||||
fileName: string,
|
||||
}
|
||||
) {
|
||||
await duplicateAvatarFile(refId, body.prefix, body.fileName);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
@ -145,4 +145,18 @@ export async function s3DownloadFile(...pathname: string[]) {
|
|||
};
|
||||
}
|
||||
|
||||
export async function duplicateAvatarFile(refId: string, prefix: string, fileName: string) {
|
||||
try {
|
||||
await minio.statObject(MINIO_BUCKET, refId);
|
||||
const avatar = `${prefix}/${fileName}`;
|
||||
await minio.copyObject(
|
||||
MINIO_BUCKET,
|
||||
avatar,
|
||||
`/${MINIO_BUCKET}/${refId}`
|
||||
);
|
||||
} catch (error) {
|
||||
exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
export const fileLocation = (...path: string[]) => path.join("/");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue