Merge branch 'development'

This commit is contained in:
Methapon2001 2023-12-14 10:41:06 +07:00
commit e424a23c3b
No known key found for this signature in database
GPG key ID: 849924FEF46BD132

View file

@ -104,6 +104,13 @@ interface DeleteFileBody {
file: string;
}
interface DownloadFileBody {
/** @example ["แฟ้ม 1", "แฟ้ม 2", "แฟ้ม 3"] */
path: string[];
/** @example "ไฟล์ 1 แก้ไข.xlsx" */
file: string;
}
async function listFolder(path: string[]) {
const list = await new Promise<{ pathname: string; name: string }[]>((resolve, reject) => {
const item: { pathname: string; name: string }[] = [];
@ -363,7 +370,7 @@ export class StorageController extends Controller {
}
/**
* Folder File
* Folder
*/
@Delete("folder")
@Tags("Storage Folder")
@ -454,8 +461,6 @@ export class StorageController extends Controller {
const presignedUrl = await minioClient.presignedPutObject(DEFAULT_BUCKET, metadata.pathname);
console.log(presignedUrl);
return { ...metadata, uploadUrl: presignedUrl };
}
@ -596,12 +601,15 @@ export class StorageController extends Controller {
return this.setStatus(HttpStatusCode.NO_CONTENT);
}
/**
* File
*/
@Delete("file")
@Tags("Storage File")
@Security("bearerAuth", ["management-role", "admin"])
@SuccessResponse(HttpStatusCode.NO_CONTENT, "สำเร็จ")
public async deleteFile(@Body() body: DeleteFileBody) {
const pathname = body.path.join("/") + body.file;
const pathname = body.path.join("/") + `/${body.file}`;
await minioClient
.removeObject(DEFAULT_BUCKET, pathname)
@ -617,4 +625,30 @@ export class StorageController extends Controller {
return this.setStatus(HttpStatusCode.NO_CONTENT);
}
@Post("file/download")
@Tags("Download")
@Security("bearerAuth", ["management-role", "admin"])
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
public async downloadFile(@Body() body: DownloadFileBody) {
const pathname = body.path.join("/") + `/${body.file}`;
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
index: DEFAULT_INDEX!,
query: {
match: { pathname },
},
});
if (search && search.hits.hits.length === 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์");
}
const { attachment, ...rest } = search.hits.hits[0]._source!;
return {
...rest,
downloadUrl: await minioClient.presignedGetObject(DEFAULT_BUCKET, pathname),
};
}
}