From 73673f7ae3de40256e2fb640cd6270634c37385d Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Thu, 14 Dec 2023 15:05:05 +0700 Subject: [PATCH 1/6] fix: move file failed --- Services/server/src/app.ts | 2 +- .../src/controllers/storageController.ts | 33 +++++++++++-------- Services/server/src/routes.ts | 2 +- Services/server/src/swagger.json | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Services/server/src/app.ts b/Services/server/src/app.ts index 02c5ce0..d735caa 100644 --- a/Services/server/src/app.ts +++ b/Services/server/src/app.ts @@ -49,4 +49,4 @@ server.listen(PORT, "0.0.0.0", () => console.log(`[APP] Application is running on http://localhost:${PORT}`), ); -rabbitmq.init(amqHandler).catch((e) => console.error(e)); +// rabbitmq.init(amqHandler).catch((e) => console.error(e)); diff --git a/Services/server/src/controllers/storageController.ts b/Services/server/src/controllers/storageController.ts index c592a2c..337eda7 100644 --- a/Services/server/src/controllers/storageController.ts +++ b/Services/server/src/controllers/storageController.ts @@ -467,7 +467,7 @@ export class StorageController extends Controller { @Put("file") @Tags("Storage File") @Security("bearerAuth", ["management-role", "admin"]) - @SuccessResponse(HttpStatusCode.NO_CONTENT, "สำเร็จ") + @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") public async moveFile( @Request() request: { user: { preferred_username: string } }, @Body() body: PutFileBody, @@ -494,17 +494,16 @@ export class StorageController extends Controller { }); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์ดังกล่าว"); } - if (body.to && !(await checkPathExist(DEFAULT_BUCKET, body.to.path.join("/")))) { - throw new HttpError(HttpStatusCode.PRECONDITION_FAILED, "ไม่พบตำแหน่งที่ต้องการย้าย"); - } - if ( - body.to && - (await checkFileExist(DEFAULT_BUCKET, body.to.path.join("/") + `/${body.to.file}`)) - ) { - throw new HttpError( - HttpStatusCode.PRECONDITION_FAILED, - "พบไฟล์ในต้ำแหน่งปลายทาง ไม่สามารถย้ายได้", - ); + if (body.to && JSON.stringify(body.from) !== JSON.stringify(body.to)) { + if (!(await checkPathExist(DEFAULT_BUCKET, body.to.path.join("/")))) { + throw new HttpError(HttpStatusCode.PRECONDITION_FAILED, "ไม่พบตำแหน่งที่ต้องการย้าย"); + } + if (await checkFileExist(DEFAULT_BUCKET, body.to.path.join("/") + `/${body.to.file}`)) { + throw new HttpError( + HttpStatusCode.PRECONDITION_FAILED, + "พบไฟล์ในต้ำแหน่งปลายทาง ไม่สามารถย้ายได้", + ); + } } if (!search.hits.hits[0]._source) { // This should not possible. @@ -526,7 +525,7 @@ export class StorageController extends Controller { updatedBy: request.user.preferred_username, }; - if (from && to) { + if (from && to && JSON.stringify(from) !== JSON.stringify(to)) { const src = [DEFAULT_BUCKET, ...from.path, ""].join("/") + from.file; const dst = to.path.join("/") + `/${to.file}`; @@ -544,11 +543,15 @@ export class StorageController extends Controller { ...metadata, path: to.path.join("/") + "/", pathname: dst, + fileName: to.file, ...dateMeta, }, refresh: "wait_for", }) - .then(async () => await minioClient.removeObject(DEFAULT_INDEX, src)) + .then( + async () => + await minioClient.removeObject(DEFAULT_BUCKET, from.path.join("/") + `/${from.file}`), + ) .catch((e) => console.error(`ElasticSearch Error: ${e}`)); io.getInstance()?.emit("FileMove", { @@ -558,6 +561,7 @@ export class StorageController extends Controller { ...metadata, path: to.path.join("/") + "/", pathname: dst, + fileName: to.file, ...dateMeta, }, }); @@ -566,6 +570,7 @@ export class StorageController extends Controller { const presignedUrl = await minioClient.presignedPutObject(DEFAULT_BUCKET, dst); return { uploadUrl: presignedUrl }; } + return this.setStatus(HttpStatusCode.NO_CONTENT); } } diff --git a/Services/server/src/routes.ts b/Services/server/src/routes.ts index cdbba04..31f7bc9 100644 --- a/Services/server/src/routes.ts +++ b/Services/server/src/routes.ts @@ -891,7 +891,7 @@ export function RegisterRoutes(app: Router) { const promise = controller.moveFile.apply(controller, validatedArgs as any); - promiseHandler(controller, promise, response, 204, next); + promiseHandler(controller, promise, response, 200, next); } catch (err) { return next(err); } diff --git a/Services/server/src/swagger.json b/Services/server/src/swagger.json index a2d430c..9952e03 100644 --- a/Services/server/src/swagger.json +++ b/Services/server/src/swagger.json @@ -2298,7 +2298,7 @@ "put": { "operationId": "MoveFile", "responses": { - "204": { + "200": { "description": "สำเร็จ", "content": { "application/json": { From 7b13566757c6ba6ba8ab0ba35bdd79d944cb08cf Mon Sep 17 00:00:00 2001 From: somnetsak123 Date: Wed, 13 Dec 2023 14:49:27 +0700 Subject: [PATCH 2/6] refactor: Folder size --- Services/client/src/components/ListView.vue | 54 +++++++++++++++++++-- Services/client/src/stores/storage.ts | 4 ++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Services/client/src/components/ListView.vue b/Services/client/src/components/ListView.vue index 4762cdf..4a2f722 100644 --- a/Services/client/src/components/ListView.vue +++ b/Services/client/src/components/ListView.vue @@ -1,7 +1,8 @@