feat: folder size
This commit is contained in:
parent
8f42584423
commit
0a1265b78c
6 changed files with 431 additions and 0 deletions
|
|
@ -182,4 +182,21 @@ export class CabinetController extends Controller {
|
|||
|
||||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example cabinetName "ตู้เอกสาร 1"
|
||||
*/
|
||||
@Get("/{cabinetName}/size")
|
||||
@Tags("ตู้เอกสาร")
|
||||
@Security("bearerAuth")
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
public async calc(@Path() cabinetName: string) {
|
||||
const list = await listItem(DEFAULT_BUCKET!, `${cabinetName}/`, true).catch((e) =>
|
||||
console.error(`Error List Folder: ${e}`),
|
||||
);
|
||||
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง");
|
||||
|
||||
return { size: list.reduce<number>((a, c) => a + c.size, 0) };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -203,4 +203,22 @@ export class DrawerController extends Controller {
|
|||
|
||||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example cabinetName "ตู้เอกสาร 1"
|
||||
* @example drawerName "ลิ้นชัก 1"
|
||||
*/
|
||||
@Get("/{drawerName}/size")
|
||||
@Tags("ลิ้นชัก")
|
||||
@Security("bearerAuth")
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
public async calc(@Path() cabinetName: string, @Path() drawerName: string) {
|
||||
const list = await listItem(DEFAULT_BUCKET!, `${cabinetName}/${drawerName}/`, true).catch((e) =>
|
||||
console.error(`Error List Folder: ${e}`),
|
||||
);
|
||||
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง");
|
||||
|
||||
return { size: list.reduce<number>((a, c) => a + c.size, 0) };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,4 +215,29 @@ export class FolderController extends Controller {
|
|||
|
||||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example cabinetName "ตู้เอกสาร 1"
|
||||
* @example drawerName "ลิ้นชัก 1"
|
||||
* @example folderName "แฟ้ม 1"
|
||||
*/
|
||||
@Get("/{folderName}/size")
|
||||
@Tags("แฟ้ม")
|
||||
@Security("bearerAuth")
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
public async calc(
|
||||
@Path() cabinetName: string,
|
||||
@Path() drawerName: string,
|
||||
@Path() folderName: string,
|
||||
) {
|
||||
const list = await listItem(
|
||||
DEFAULT_BUCKET!,
|
||||
`${cabinetName}/${drawerName}/${folderName}/`,
|
||||
true,
|
||||
).catch((e) => console.error(`Error List Folder: ${e}`));
|
||||
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง");
|
||||
|
||||
return { size: list.reduce<number>((a, c) => a + c.size, 0) };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -220,4 +220,31 @@ export class SubFolderController extends Controller {
|
|||
|
||||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @example cabinetName "ตู้เอกสาร 1"
|
||||
* @example drawerName "ลิ้นชัก 1"
|
||||
* @example folderName "แฟ้ม 1"
|
||||
* @example subFolderName "แฟ้มย่อย 1"
|
||||
*/
|
||||
@Get("/{subFolderName}/size")
|
||||
@Tags("แฟ้มย่อย")
|
||||
@Security("bearerAuth")
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
public async calc(
|
||||
@Path() cabinetName: string,
|
||||
@Path() drawerName: string,
|
||||
@Path() folderName: string,
|
||||
@Path() subFolderName: string,
|
||||
) {
|
||||
const list = await listItem(
|
||||
DEFAULT_BUCKET!,
|
||||
`${cabinetName}/${drawerName}/${folderName}/${subFolderName}`,
|
||||
true,
|
||||
).catch((e) => console.error(`Error List Folder: ${e}`));
|
||||
|
||||
if (!list) throw new Error("เกิดข้อผิดพลาด ไม่สามารถแสดงรายการแฟ้มได้ กรุณาลองใหม่ในภายหลัง");
|
||||
|
||||
return { size: list.reduce<number>((a, c) => a + c.size, 0) };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue