From 046b915fc3e1fd89902791b0d56120fed73c81c8 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 28 Nov 2023 16:27:49 +0700 Subject: [PATCH] fix: get list of file under folder return all file in subfolder --- .../server/src/controllers/fileController.ts | 6 +- .../controllers/subFolderFileController.ts | 5 +- Services/server/src/interfaces/storage-fs.ts | 4 +- Services/server/src/rabbitmq/handler.ts | 2 + Services/server/src/routes.ts | 78 ++++++++++ Services/server/src/swagger.json | 146 ++++++++++++++++++ 6 files changed, 234 insertions(+), 7 deletions(-) diff --git a/Services/server/src/controllers/fileController.ts b/Services/server/src/controllers/fileController.ts index 0528c52..e31cd7c 100644 --- a/Services/server/src/controllers/fileController.ts +++ b/Services/server/src/controllers/fileController.ts @@ -43,8 +43,8 @@ export class FileController extends Controller { const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { - prefix: { - pathname: `${cabinetName}/${drawerName}/${folderName}/`, + match: { + path: `${cabinetName}/${drawerName}/${folderName}/`, }, }, size: 10000, @@ -115,6 +115,7 @@ export class FileController extends Controller { const metadata: Partial = { pathname, + path: basePath, fileName: body.file, fileSize: 0, fileType: "", @@ -201,6 +202,7 @@ export class FileController extends Controller { id, doc: { pathname: destination, + path: basePath, fileName: body.file, updatedAt: new Date().toISOString(), updatedBy: request.user.preferred_username ?? "n/a", diff --git a/Services/server/src/controllers/subFolderFileController.ts b/Services/server/src/controllers/subFolderFileController.ts index 95bf33d..f450a22 100644 --- a/Services/server/src/controllers/subFolderFileController.ts +++ b/Services/server/src/controllers/subFolderFileController.ts @@ -46,8 +46,8 @@ export class SubFolderFileController extends Controller { const search = await esClient.search }>({ index: DEFAULT_INDEX!, query: { - prefix: { - pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}`, + match: { + path: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/`, }, }, size: 10000, @@ -119,6 +119,7 @@ export class SubFolderFileController extends Controller { const metadata: Partial = { pathname, + path: basePath, fileName: body.file, fileSize: 0, fileType: "", diff --git a/Services/server/src/interfaces/storage-fs.ts b/Services/server/src/interfaces/storage-fs.ts index 58737fd..5e7693f 100644 --- a/Services/server/src/interfaces/storage-fs.ts +++ b/Services/server/src/interfaces/storage-fs.ts @@ -27,9 +27,7 @@ export interface StorageFile { category: string[]; keyword: string[]; - /** - * @private For internal use only. - */ + path: string; upload: boolean; updatedAt: string | Date; diff --git a/Services/server/src/rabbitmq/handler.ts b/Services/server/src/rabbitmq/handler.ts index 82c51ae..f02d48b 100644 --- a/Services/server/src/rabbitmq/handler.ts +++ b/Services/server/src/rabbitmq/handler.ts @@ -94,11 +94,13 @@ async function handleNotFoundRecord( buffer: Buffer, stat: { size: number; type: string }, ) { + const path = pathname.split("/").slice(0, -1).join("/") + "/"; const filename = pathname.split("/").at(-1); const base64 = Buffer.from(buffer).toString("base64"); const metadata = { pathname, + path, fileName: filename ?? "n/a", // should not possible to fallback, but just in case. fileSize: stat.size, fileType: stat.type, diff --git a/Services/server/src/routes.ts b/Services/server/src/routes.ts index 845fb8b..75ce028 100644 --- a/Services/server/src/routes.ts +++ b/Services/server/src/routes.ts @@ -48,6 +48,7 @@ const models: TsoaRoute.Models = { "description": {"dataType":"string","required":true}, "category": {"dataType":"array","array":{"dataType":"string"},"required":true}, "keyword": {"dataType":"array","array":{"dataType":"string"},"required":true}, + "path": {"dataType":"string","required":true}, "upload": {"dataType":"boolean","required":true}, "updatedAt": {"dataType":"union","subSchemas":[{"dataType":"string"},{"dataType":"datetime"}],"required":true}, "updatedBy": {"dataType":"string","required":true}, @@ -576,6 +577,83 @@ 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.get('/storage/d', + ...(fetchMiddlewares(StorageController)), + ...(fetchMiddlewares(StorageController.prototype.getFolder)), + + function StorageController_getFolder(request: any, response: any, next: any) { + const args = { + path: {"in":"query","name":"path","required":true,"dataType":"string"}, + bucket: {"in":"query","name":"bucket","dataType":"string"}, + }; + + // 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.getFolder.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, 200, 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.post('/storage/d', + ...(fetchMiddlewares(StorageController)), + ...(fetchMiddlewares(StorageController.prototype.createFolder)), + + function StorageController_createFolder(request: any, response: any, next: any) { + const args = { + path: {"in":"query","name":"path","required":true,"dataType":"string"}, + bucket: {"in":"query","name":"bucket","dataType":"string"}, + }; + + // 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.createFolder.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, 201, 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.put('/storage/d', + ...(fetchMiddlewares(StorageController)), + ...(fetchMiddlewares(StorageController.prototype.updateFolder)), + + function StorageController_updateFolder(request: any, response: any, next: any) { + const args = { + body: {"in":"body","name":"body","required":true,"dataType":"nestedObjectLiteral","nestedProperties":{"to":{"dataType":"nestedObjectLiteral","nestedProperties":{"path":{"dataType":"string","required":true},"bucket":{"dataType":"string","required":true}},"required":true},"from":{"dataType":"nestedObjectLiteral","nestedProperties":{"path":{"dataType":"string","required":true},"bucket":{"dataType":"string","required":true}},"required":true}}}, + }; + + // 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.updateFolder.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, 204, 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.get('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/subfolder', authenticateMiddleware([{"bearerAuth":[]}]), ...(fetchMiddlewares(SubFolderController)), diff --git a/Services/server/src/swagger.json b/Services/server/src/swagger.json index ebdf260..c9ff752 100644 --- a/Services/server/src/swagger.json +++ b/Services/server/src/swagger.json @@ -79,6 +79,9 @@ }, "type": "array" }, + "path": { + "type": "string" + }, "upload": { "type": "boolean" }, @@ -120,6 +123,7 @@ "description", "category", "keyword", + "path", "upload", "updatedAt", "updatedBy", @@ -974,6 +978,9 @@ "upload": { "type": "boolean" }, + "path": { + "type": "string" + }, "keyword": { "items": { "type": "string" @@ -1015,6 +1022,7 @@ "updatedBy", "updatedAt", "upload", + "path", "keyword", "category", "description", @@ -1364,6 +1372,140 @@ } } }, + "/storage/d": { + "get": { + "operationId": "GetFolder", + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "items": { + "properties": { + "name": { + "type": "string" + }, + "pathname": { + "type": "string" + } + }, + "required": [ + "name", + "pathname" + ], + "type": "object" + }, + "type": "array" + } + } + } + } + }, + "security": [], + "parameters": [ + { + "in": "query", + "name": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "query", + "name": "bucket", + "required": false, + "schema": { + "type": "string" + } + } + ] + }, + "post": { + "operationId": "CreateFolder", + "responses": { + "201": { + "description": "Success" + } + }, + "security": [], + "parameters": [ + { + "in": "query", + "name": "path", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "query", + "name": "bucket", + "required": false, + "schema": { + "type": "string" + } + } + ] + }, + "put": { + "operationId": "UpdateFolder", + "responses": { + "204": { + "description": "Success" + } + }, + "security": [], + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "properties": { + "to": { + "properties": { + "path": { + "type": "string" + }, + "bucket": { + "type": "string" + } + }, + "required": [ + "path", + "bucket" + ], + "type": "object" + }, + "from": { + "properties": { + "path": { + "type": "string" + }, + "bucket": { + "type": "string" + } + }, + "required": [ + "path", + "bucket" + ], + "type": "object" + } + }, + "required": [ + "to", + "from" + ], + "type": "object" + } + } + } + } + } + }, "/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/subfolder": { "get": { "operationId": "ListFolder", @@ -2070,6 +2212,9 @@ "upload": { "type": "boolean" }, + "path": { + "type": "string" + }, "keyword": { "items": { "type": "string" @@ -2111,6 +2256,7 @@ "updatedBy", "updatedAt", "upload", + "path", "keyword", "category", "description",