refactor: is path exist function

This commit is contained in:
Methapon2001 2023-11-27 16:07:32 +07:00
parent ca5be0042d
commit 1559226837
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
8 changed files with 96 additions and 44 deletions

View file

@ -17,7 +17,7 @@ import {
import minioClient from "../minio";
import esClient from "../elasticsearch";
import { copyCond, listFolder, listItem, replaceIllegalChars } from "../utils/minio";
import { copyCond, listFolder, listItem, pathExist, replaceIllegalChars } from "../utils/minio";
import HttpStatusCode from "../interfaces/http-status";
import { StorageFile, StorageFolder } from "../interfaces/storage-fs";
@ -67,15 +67,8 @@ export class SubFolderController extends Controller {
) {
const basePath = `${cabinetName}/${drawerName}/${folderName}/`;
if (
!Boolean(
await minioClient.statObject(DEFAULT_BUCKET!, `${basePath}.keep`).catch((e) => {
if (e.code === "NotFound") return false;
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
}),
)
) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแฟ้ม");
if (!(await pathExist(DEFAULT_BUCKET!, basePath))) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบตำแหน่งที่ต้องการสร้างลิ้นชัก");
}
const created = await minioClient
@ -121,7 +114,9 @@ export class SubFolderController extends Controller {
return await minioClient.removeObject(DEFAULT_BUCKET!, current.name);
}
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
const search = await esClient.search<
StorageFile & { attachment: Record<string, string> }
>({
index: DEFAULT_INDEX!,
query: { match: { pathname: current.name } },
});