diff --git a/Services/server/src/controllers/fileController.ts b/Services/server/src/controllers/fileController.ts index e39752b..6baec35 100644 --- a/Services/server/src/controllers/fileController.ts +++ b/Services/server/src/controllers/fileController.ts @@ -270,9 +270,11 @@ export class FileController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์"); } + const { file, ...metadata } = body; + // assume user will probably replace file by re-upload but maybe just rename - if (body.file) { - const destination = `${basePath}${replaceIllegalChars(body.file)}`; + if (file) { + const destination = `${basePath}${replaceIllegalChars(file)}`; const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`; const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond); @@ -291,9 +293,10 @@ export class FileController extends Controller { index, id, doc: { + ...metadata, pathname: destination, path: basePath, - fileName: replaceIllegalChars(body.file), + fileName: replaceIllegalChars(file), updatedAt: new Date().toISOString(), updatedBy: request.user.preferred_username ?? "n/a", }, @@ -318,7 +321,7 @@ export class FileController extends Controller { index, id, doc: { - ...body, + ...metadata, 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 7729314..48544f2 100644 --- a/Services/server/src/controllers/subFolderFileController.ts +++ b/Services/server/src/controllers/subFolderFileController.ts @@ -277,9 +277,11 @@ export class SubFolderFileController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์"); } + const { file, ...metadata } = body; + // assume user will probably replace file by re-upload but maybe just rename - if (body.file) { - const destination = `${basePath}${replaceIllegalChars(body.file)}`; + if (file) { + const destination = `${basePath}${replaceIllegalChars(file)}`; const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`; const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond); @@ -298,8 +300,10 @@ export class SubFolderFileController extends Controller { index, id, doc: { + ...metadata, pathname: destination, - fileName: replaceIllegalChars(body.file), + path: basePath, + fileName: replaceIllegalChars(file), updatedAt: new Date().toISOString(), updatedBy: request.user.preferred_username ?? "n/a", }, @@ -324,7 +328,7 @@ export class SubFolderFileController extends Controller { index, id, doc: { - ...body, + ...metadata, updatedAt: new Date().toISOString(), updatedBy: request.user.preferred_username ?? "n/a", },