fix: get list of file under folder return all file in subfolder

This commit is contained in:
Methapon2001 2023-11-28 16:27:49 +07:00
parent 93f0ac3431
commit 046b915fc3
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
6 changed files with 234 additions and 7 deletions

View file

@ -43,8 +43,8 @@ export class FileController extends Controller {
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
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<StorageFile> = {
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",

View file

@ -46,8 +46,8 @@ export class SubFolderFileController extends Controller {
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
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<StorageFile> = {
pathname,
path: basePath,
fileName: body.file,
fileSize: 0,
fileType: "",

View file

@ -27,9 +27,7 @@ export interface StorageFile {
category: string[];
keyword: string[];
/**
* @private For internal use only.
*/
path: string;
upload: boolean;
updatedAt: string | Date;

View file

@ -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,

View file

@ -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<RequestHandler>(StorageController)),
...(fetchMiddlewares<RequestHandler>(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<RequestHandler>(StorageController)),
...(fetchMiddlewares<RequestHandler>(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<RequestHandler>(StorageController)),
...(fetchMiddlewares<RequestHandler>(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<RequestHandler>(SubFolderController)),

View file

@ -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",