feat: direct minio upload
This commit is contained in:
parent
d17462cb92
commit
a1b88c070b
4 changed files with 575 additions and 34 deletions
|
|
@ -22,6 +22,7 @@ import {
|
|||
listFile,
|
||||
updateFile,
|
||||
} from "../services/edm";
|
||||
import { s3DownloadFile, s3ListFile, s3UploadFile } from "../services/minio";
|
||||
|
||||
@Route("api/v1/salary/file/{name}/{group}")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -56,6 +57,12 @@ export class FileController extends Controller {
|
|||
},
|
||||
])
|
||||
public async getFile(@Path() name: string, @Path() group: string, @Path() id: string) {
|
||||
if (name !== "ระบบประเมิน") {
|
||||
return await s3ListFile(name, group, id).catch((e) => {
|
||||
console.error(e);
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
});
|
||||
}
|
||||
const list = await listFile([name, group, id]);
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
return list;
|
||||
|
|
@ -99,7 +106,12 @@ export class FileController extends Controller {
|
|||
@Path() id: string,
|
||||
@Path() file: string,
|
||||
) {
|
||||
if (name !== "ระบบประเมิน") {
|
||||
return await s3DownloadFile(name, group, id, file);
|
||||
}
|
||||
|
||||
const data = await downloadFile([name, group, id], file);
|
||||
|
||||
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
return data;
|
||||
}
|
||||
|
|
@ -176,6 +188,16 @@ export class FileController extends Controller {
|
|||
) {
|
||||
const path = [name, group, id];
|
||||
|
||||
if (name !== "ระบบประเมิน") {
|
||||
const ret = await Promise.all(
|
||||
body.fileList.map(async ({ fileName }) => [
|
||||
fileName,
|
||||
await s3UploadFile(...path, fileName),
|
||||
]),
|
||||
);
|
||||
return Object.fromEntries(ret);
|
||||
}
|
||||
|
||||
if (!(await createFolder(path.slice(0, -1), id, true))) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
}
|
||||
|
|
@ -272,6 +294,8 @@ export class FileController extends Controller {
|
|||
metadata?: { [key: string]: unknown };
|
||||
},
|
||||
) {
|
||||
if (name !== "ระบบประเมิน") return; // do nothing, no metadata to update
|
||||
|
||||
const props = body;
|
||||
const result = await updateFile([name, group, id], file, props);
|
||||
|
||||
|
|
@ -362,6 +386,9 @@ export class SubFileController extends Controller {
|
|||
@Path() id: string,
|
||||
@Path() subId: string,
|
||||
) {
|
||||
if (name !== "ระบบประเมิน") {
|
||||
return await s3ListFile(name, group, id);
|
||||
}
|
||||
const list = await listFile([name, group, id, subId]);
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
return list;
|
||||
|
|
@ -408,6 +435,9 @@ export class SubFileController extends Controller {
|
|||
@Path() subId: string,
|
||||
@Path() file: string,
|
||||
) {
|
||||
if (name !== "ระบบประเมิน") {
|
||||
return await s3DownloadFile(name, group, id, subId);
|
||||
}
|
||||
const data = await downloadFile([name, group, id, subId], file);
|
||||
if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
return data;
|
||||
|
|
@ -488,6 +518,10 @@ export class SubFileController extends Controller {
|
|||
) {
|
||||
const path = [name, group, id, subId];
|
||||
|
||||
if (name !== "ระบบประเมิน") {
|
||||
return await s3ListFile(name, group, id, subId);
|
||||
}
|
||||
|
||||
if (!(await createFolder(path.slice(0, -1), subId, true))) {
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้");
|
||||
}
|
||||
|
|
@ -586,6 +620,8 @@ export class SubFileController extends Controller {
|
|||
metadata?: { [key: string]: unknown };
|
||||
},
|
||||
) {
|
||||
if (name !== "ระบบประเมิน") return; // do nothing, no metadata to update
|
||||
|
||||
const props = body;
|
||||
const result = await updateFile([name, group, id, subId], file, props);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue