Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2025-07-11 11:44:49 +07:00
commit edbb502a0e
2 changed files with 60 additions and 0 deletions

View 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();
}
}

View file

@ -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("/");