Merge branch 'development'
This commit is contained in:
commit
e424a23c3b
1 changed files with 38 additions and 4 deletions
|
|
@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue