feat: new storage endpoint folder size
This commit is contained in:
parent
63314abedb
commit
6a5ccc09a5
3 changed files with 100 additions and 1 deletions
|
|
@ -114,7 +114,25 @@ interface DownloadFileBody {
|
|||
file: string;
|
||||
}
|
||||
|
||||
async function listFolder(path: string[], hidden: boolean = false) {
|
||||
async function folderSize(path: string[]) {
|
||||
const size = await new Promise<number>((resolve, reject) => {
|
||||
const stream = minioClient.listObjectsV2(
|
||||
DEFAULT_BUCKET,
|
||||
path.length === 0 ? "" : path.join("/") + "/",
|
||||
true,
|
||||
);
|
||||
let total: number = 0;
|
||||
|
||||
stream.on("data", (v) => {
|
||||
if (v && v.size) total += v.size;
|
||||
});
|
||||
stream.on("end", () => resolve(total));
|
||||
stream.on("error", () => reject(new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์")));
|
||||
});
|
||||
return size;
|
||||
}
|
||||
|
||||
async function listFolder(path: string[]) {
|
||||
const list = await new Promise<{ pathname: string; name: string }[]>((resolve, reject) => {
|
||||
const item: { pathname: string; name: string }[] = [];
|
||||
|
||||
|
|
@ -379,6 +397,13 @@ export class StorageController extends Controller {
|
|||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Post("folder/size")
|
||||
@Tags("Storage Folder")
|
||||
@Security("bearerAuth", ["management-role", "admin"])
|
||||
public async folderSize(@Body() body: FolderBody) {
|
||||
return { size: await folderSize([...body.path, body.name]) };
|
||||
}
|
||||
|
||||
/**
|
||||
* ลบ Folder ออกจากระบบ
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -824,6 +824,32 @@ export function RegisterRoutes(app: Router) {
|
|||
}
|
||||
});
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
app.post('/storage/folder/size',
|
||||
authenticateMiddleware([{"bearerAuth":["management-role","admin"]}]),
|
||||
...(fetchMiddlewares<RequestHandler>(StorageController)),
|
||||
...(fetchMiddlewares<RequestHandler>(StorageController.prototype.folderSize)),
|
||||
|
||||
function StorageController_folderSize(request: any, response: any, next: any) {
|
||||
const args = {
|
||||
body: {"in":"body","name":"body","required":true,"ref":"FolderBody"},
|
||||
};
|
||||
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
|
||||
let validatedArgs: any[] = [];
|
||||
try {
|
||||
validatedArgs = getValidatedArgs(args, request, response);
|
||||
|
||||
const controller = new StorageController();
|
||||
|
||||
|
||||
const promise = controller.folderSize.apply(controller, validatedArgs as any);
|
||||
promiseHandler(controller, promise, response, undefined, next);
|
||||
} catch (err) {
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
|
||||
app.delete('/storage/folder',
|
||||
authenticateMiddleware([{"bearerAuth":["management-role","admin"]}]),
|
||||
...(fetchMiddlewares<RequestHandler>(StorageController)),
|
||||
|
|
|
|||
|
|
@ -2197,6 +2197,54 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"/storage/folder/size": {
|
||||
"post": {
|
||||
"operationId": "FolderSize",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Ok",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"size": {
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"size"
|
||||
],
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"Storage Folder"
|
||||
],
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": [
|
||||
"management-role",
|
||||
"admin"
|
||||
]
|
||||
}
|
||||
],
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"required": true,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/FolderBody"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/storage/file": {
|
||||
"post": {
|
||||
"operationId": "PostFile",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue