fix: get list of file under folder return all file in subfolder
This commit is contained in:
parent
93f0ac3431
commit
046b915fc3
6 changed files with 234 additions and 7 deletions
|
|
@ -43,8 +43,8 @@ export class FileController extends Controller {
|
||||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||||
index: DEFAULT_INDEX!,
|
index: DEFAULT_INDEX!,
|
||||||
query: {
|
query: {
|
||||||
prefix: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/`,
|
path: `${cabinetName}/${drawerName}/${folderName}/`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
size: 10000,
|
size: 10000,
|
||||||
|
|
@ -115,6 +115,7 @@ export class FileController extends Controller {
|
||||||
|
|
||||||
const metadata: Partial<StorageFile> = {
|
const metadata: Partial<StorageFile> = {
|
||||||
pathname,
|
pathname,
|
||||||
|
path: basePath,
|
||||||
fileName: body.file,
|
fileName: body.file,
|
||||||
fileSize: 0,
|
fileSize: 0,
|
||||||
fileType: "",
|
fileType: "",
|
||||||
|
|
@ -201,6 +202,7 @@ export class FileController extends Controller {
|
||||||
id,
|
id,
|
||||||
doc: {
|
doc: {
|
||||||
pathname: destination,
|
pathname: destination,
|
||||||
|
path: basePath,
|
||||||
fileName: body.file,
|
fileName: body.file,
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
updatedBy: request.user.preferred_username ?? "n/a",
|
updatedBy: request.user.preferred_username ?? "n/a",
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ export class SubFolderFileController extends Controller {
|
||||||
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
const search = await esClient.search<StorageFile & { attachment: Record<string, string> }>({
|
||||||
index: DEFAULT_INDEX!,
|
index: DEFAULT_INDEX!,
|
||||||
query: {
|
query: {
|
||||||
prefix: {
|
match: {
|
||||||
pathname: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}`,
|
path: `${cabinetName}/${drawerName}/${folderName}/${subFolderName}/`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
size: 10000,
|
size: 10000,
|
||||||
|
|
@ -119,6 +119,7 @@ export class SubFolderFileController extends Controller {
|
||||||
|
|
||||||
const metadata: Partial<StorageFile> = {
|
const metadata: Partial<StorageFile> = {
|
||||||
pathname,
|
pathname,
|
||||||
|
path: basePath,
|
||||||
fileName: body.file,
|
fileName: body.file,
|
||||||
fileSize: 0,
|
fileSize: 0,
|
||||||
fileType: "",
|
fileType: "",
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@ export interface StorageFile {
|
||||||
category: string[];
|
category: string[];
|
||||||
keyword: string[];
|
keyword: string[];
|
||||||
|
|
||||||
/**
|
path: string;
|
||||||
* @private For internal use only.
|
|
||||||
*/
|
|
||||||
upload: boolean;
|
upload: boolean;
|
||||||
|
|
||||||
updatedAt: string | Date;
|
updatedAt: string | Date;
|
||||||
|
|
|
||||||
|
|
@ -94,11 +94,13 @@ async function handleNotFoundRecord(
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
stat: { size: number; type: string },
|
stat: { size: number; type: string },
|
||||||
) {
|
) {
|
||||||
|
const path = pathname.split("/").slice(0, -1).join("/") + "/";
|
||||||
const filename = pathname.split("/").at(-1);
|
const filename = pathname.split("/").at(-1);
|
||||||
const base64 = Buffer.from(buffer).toString("base64");
|
const base64 = Buffer.from(buffer).toString("base64");
|
||||||
|
|
||||||
const metadata = {
|
const metadata = {
|
||||||
pathname,
|
pathname,
|
||||||
|
path,
|
||||||
fileName: filename ?? "n/a", // should not possible to fallback, but just in case.
|
fileName: filename ?? "n/a", // should not possible to fallback, but just in case.
|
||||||
fileSize: stat.size,
|
fileSize: stat.size,
|
||||||
fileType: stat.type,
|
fileType: stat.type,
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ const models: TsoaRoute.Models = {
|
||||||
"description": {"dataType":"string","required":true},
|
"description": {"dataType":"string","required":true},
|
||||||
"category": {"dataType":"array","array":{"dataType":"string"},"required":true},
|
"category": {"dataType":"array","array":{"dataType":"string"},"required":true},
|
||||||
"keyword": {"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},
|
"upload": {"dataType":"boolean","required":true},
|
||||||
"updatedAt": {"dataType":"union","subSchemas":[{"dataType":"string"},{"dataType":"datetime"}],"required":true},
|
"updatedAt": {"dataType":"union","subSchemas":[{"dataType":"string"},{"dataType":"datetime"}],"required":true},
|
||||||
"updatedBy": {"dataType":"string","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
|
// 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',
|
app.get('/cabinet/:cabinetName/drawer/:drawerName/folder/:folderName/subfolder',
|
||||||
authenticateMiddleware([{"bearerAuth":[]}]),
|
authenticateMiddleware([{"bearerAuth":[]}]),
|
||||||
...(fetchMiddlewares<RequestHandler>(SubFolderController)),
|
...(fetchMiddlewares<RequestHandler>(SubFolderController)),
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@
|
||||||
},
|
},
|
||||||
"type": "array"
|
"type": "array"
|
||||||
},
|
},
|
||||||
|
"path": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"upload": {
|
"upload": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|
@ -120,6 +123,7 @@
|
||||||
"description",
|
"description",
|
||||||
"category",
|
"category",
|
||||||
"keyword",
|
"keyword",
|
||||||
|
"path",
|
||||||
"upload",
|
"upload",
|
||||||
"updatedAt",
|
"updatedAt",
|
||||||
"updatedBy",
|
"updatedBy",
|
||||||
|
|
@ -974,6 +978,9 @@
|
||||||
"upload": {
|
"upload": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"path": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"keyword": {
|
"keyword": {
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
@ -1015,6 +1022,7 @@
|
||||||
"updatedBy",
|
"updatedBy",
|
||||||
"updatedAt",
|
"updatedAt",
|
||||||
"upload",
|
"upload",
|
||||||
|
"path",
|
||||||
"keyword",
|
"keyword",
|
||||||
"category",
|
"category",
|
||||||
"description",
|
"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": {
|
"/cabinet/{cabinetName}/drawer/{drawerName}/folder/{folderName}/subfolder": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "ListFolder",
|
"operationId": "ListFolder",
|
||||||
|
|
@ -2070,6 +2212,9 @@
|
||||||
"upload": {
|
"upload": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"path": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"keyword": {
|
"keyword": {
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
@ -2111,6 +2256,7 @@
|
||||||
"updatedBy",
|
"updatedBy",
|
||||||
"updatedAt",
|
"updatedAt",
|
||||||
"upload",
|
"upload",
|
||||||
|
"path",
|
||||||
"keyword",
|
"keyword",
|
||||||
"category",
|
"category",
|
||||||
"description",
|
"description",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue