feat: folder size

This commit is contained in:
Methapon2001 2023-12-07 15:45:03 +07:00
parent 8f42584423
commit 0a1265b78c
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
6 changed files with 431 additions and 0 deletions

View file

@ -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) };
}
}