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

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