feat: subfolder file download
This commit is contained in:
parent
2f36e325af
commit
1e2b26558c
3 changed files with 408 additions and 0 deletions
|
|
@ -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<EhrFile & { attachment: Record<string, string> }>({
|
||||
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}`,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<RequestHandler>(FileController)),
|
||||
...(fetchMiddlewares<RequestHandler>(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<RequestHandler>(FolderController)),
|
||||
...(fetchMiddlewares<RequestHandler>(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<RequestHandler>(MinioController)),
|
||||
...(fetchMiddlewares<RequestHandler>(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<RequestHandler>(SearchController)),
|
||||
...(fetchMiddlewares<RequestHandler>(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<RequestHandler>(SubFolderFileController)),
|
||||
...(fetchMiddlewares<RequestHandler>(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
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue