From 1e2b26558c385dc4e0367b68f1c19172d57fd1bd Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:45:56 +0700 Subject: [PATCH] feat: subfolder file download --- .../controllers/subFolderFileController.ts | 40 +++ Prototype/server/src/routes.ts | 84 ++++++ Prototype/server/src/swagger.json | 284 ++++++++++++++++++ 3 files changed, 408 insertions(+) diff --git a/Prototype/server/src/controllers/subFolderFileController.ts b/Prototype/server/src/controllers/subFolderFileController.ts index 93605ea..4162877 100644 --- a/Prototype/server/src/controllers/subFolderFileController.ts +++ b/Prototype/server/src/controllers/subFolderFileController.ts @@ -287,4 +287,44 @@ export class SubFolderFileController extends Controller { return this.setStatus(HttpStatusCode.NO_CONTENT); } + + @Get("/{fileName}") + @Tags("File") + @SuccessResponse(HttpStatusCode.OK) + public async downloadFile( + @Path() cabinetName: string, + @Path() drawerName: string, + @Path() folderName: string, + @Path() subFolderName: string, + @Path() fileName: string, + ) { + const search = await esClient.search }>({ + index: "ehr-api-client", + query: { + match: { + pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`, + }, + }, + }); + + if (search && search.hits.hits.length === 0) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "Not found"); + } + + const data = search.hits.hits[0]._source; + + if (!data) { + throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "Found data but no info."); + } + + const { attachment, ...rest } = data; + + return { + ...rest, + download: await minioClient.presignedGetObject( + "ehr", + `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/${fileName}`, + ), + }; + } } diff --git a/Prototype/server/src/routes.ts b/Prototype/server/src/routes.ts index a028c3e..3068d7a 100644 --- a/Prototype/server/src/routes.ts +++ b/Prototype/server/src/routes.ts @@ -11,6 +11,8 @@ import { FileController } from './controllers/fileController'; // 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 import { FolderController } from './controllers/folderController'; // 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 +import { MinioController } from './controllers/minioController'; +// 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 import { SearchController } from './controllers/searchController'; // 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 import { SubFolderController } from './controllers/subFolderController'; @@ -414,6 +416,34 @@ 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('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/file/:fileName', + ...(fetchMiddlewares(FileController)), + ...(fetchMiddlewares(FileController.prototype.downloadFile)), + + function FileController_downloadFile(request: any, response: any, next: any) { + const args = { + cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, + drawerName: {"in":"path","name":"drawerName","required":true,"dataType":"string"}, + folderName: {"in":"path","name":"folderName","required":true,"dataType":"string"}, + fileName: {"in":"path","name":"fileName","required":true,"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 FileController(); + + + const promise = controller.downloadFile.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.get('/cabinet/:cabinetName/drawer/:drawerName/folder', ...(fetchMiddlewares(FolderController)), ...(fetchMiddlewares(FolderController.prototype.listFolder)), @@ -526,6 +556,31 @@ 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('/minio', + ...(fetchMiddlewares(MinioController)), + ...(fetchMiddlewares(MinioController.prototype.hook)), + + function MinioController_hook(request: any, response: any, next: any) { + const args = { + req: {"in":"request","name":"req","required":true,"dataType":"object"}, + }; + + // 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 MinioController(); + + + const promise = controller.hook.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.post('/search', ...(fetchMiddlewares(SearchController)), ...(fetchMiddlewares(SearchController.prototype.searchFile)), @@ -798,6 +853,35 @@ 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('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/subfolder/:subFolderName/file/:fileName', + ...(fetchMiddlewares(SubFolderFileController)), + ...(fetchMiddlewares(SubFolderFileController.prototype.downloadFile)), + + function SubFolderFileController_downloadFile(request: any, response: any, next: any) { + const args = { + cabinetName: {"in":"path","name":"cabinetName","required":true,"dataType":"string"}, + drawerName: {"in":"path","name":"drawerName","required":true,"dataType":"string"}, + folderName: {"in":"path","name":"folderName","required":true,"dataType":"string"}, + subFolderName: {"in":"path","name":"subFolderName","required":true,"dataType":"string"}, + fileName: {"in":"path","name":"fileName","required":true,"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 SubFolderFileController(); + + + const promise = controller.downloadFile.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 // 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 diff --git a/Prototype/server/src/swagger.json b/Prototype/server/src/swagger.json index 7778788..1128fbb 100644 --- a/Prototype/server/src/swagger.json +++ b/Prototype/server/src/swagger.json @@ -751,6 +751,138 @@ } } ] + }, + "get": { + "operationId": "DownloadFile", + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "properties": { + "createdBy": { + "type": "string" + }, + "createdAt": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "string", + "format": "date-time" + } + ] + }, + "updatedBy": { + "type": "string" + }, + "updatedAt": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "string", + "format": "date-time" + } + ] + }, + "keyword": { + "items": { + "type": "string" + }, + "type": "array" + }, + "category": { + "items": { + "type": "string" + }, + "type": "array" + }, + "description": { + "type": "string" + }, + "title": { + "type": "string" + }, + "fileType": { + "type": "string" + }, + "fileSize": { + "type": "number", + "format": "double" + }, + "fileName": { + "type": "string" + }, + "pathname": { + "type": "string" + }, + "download": { + "type": "string" + } + }, + "required": [ + "createdBy", + "createdAt", + "updatedBy", + "updatedAt", + "keyword", + "category", + "description", + "title", + "fileType", + "fileSize", + "fileName", + "pathname", + "download" + ], + "type": "object" + } + } + } + } + }, + "tags": [ + "File" + ], + "security": [], + "parameters": [ + { + "in": "path", + "name": "cabinetName", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "drawerName", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "folderName", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "fileName", + "required": true, + "schema": { + "type": "string" + } + } + ] } }, "/cabinet/{cabinetName}/drawer/{drawerName}/folder": { @@ -961,6 +1093,18 @@ ] } }, + "/minio": { + "post": { + "operationId": "Hook", + "responses": { + "204": { + "description": "No content" + } + }, + "security": [], + "parameters": [] + } + }, "/search": { "post": { "operationId": "SearchFile", @@ -1598,6 +1742,146 @@ } } ] + }, + "get": { + "operationId": "DownloadFile", + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "properties": { + "createdBy": { + "type": "string" + }, + "createdAt": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "string", + "format": "date-time" + } + ] + }, + "updatedBy": { + "type": "string" + }, + "updatedAt": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "string", + "format": "date-time" + } + ] + }, + "keyword": { + "items": { + "type": "string" + }, + "type": "array" + }, + "category": { + "items": { + "type": "string" + }, + "type": "array" + }, + "description": { + "type": "string" + }, + "title": { + "type": "string" + }, + "fileType": { + "type": "string" + }, + "fileSize": { + "type": "number", + "format": "double" + }, + "fileName": { + "type": "string" + }, + "pathname": { + "type": "string" + }, + "download": { + "type": "string" + } + }, + "required": [ + "createdBy", + "createdAt", + "updatedBy", + "updatedAt", + "keyword", + "category", + "description", + "title", + "fileType", + "fileSize", + "fileName", + "pathname", + "download" + ], + "type": "object" + } + } + } + } + }, + "tags": [ + "File" + ], + "security": [], + "parameters": [ + { + "in": "path", + "name": "cabinetName", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "drawerName", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "folderName", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "subFolderName", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "fileName", + "required": true, + "schema": { + "type": "string" + } + } + ] } } },