fix: metadata not update

This commit is contained in:
Methapon2001 2023-12-04 15:36:35 +07:00
parent a7f012bda2
commit 0202e0e0f8
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
2 changed files with 15 additions and 8 deletions

View file

@ -270,9 +270,11 @@ export class FileController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์");
} }
const { file, ...metadata } = body;
// assume user will probably replace file by re-upload but maybe just rename // assume user will probably replace file by re-upload but maybe just rename
if (body.file) { if (file) {
const destination = `${basePath}${replaceIllegalChars(body.file)}`; const destination = `${basePath}${replaceIllegalChars(file)}`;
const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`; const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`;
const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond); const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond);
@ -291,9 +293,10 @@ export class FileController extends Controller {
index, index,
id, id,
doc: { doc: {
...metadata,
pathname: destination, pathname: destination,
path: basePath, path: basePath,
fileName: replaceIllegalChars(body.file), fileName: replaceIllegalChars(file),
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a", updatedBy: request.user.preferred_username ?? "n/a",
}, },
@ -318,7 +321,7 @@ export class FileController extends Controller {
index, index,
id, id,
doc: { doc: {
...body, ...metadata,
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a", updatedBy: request.user.preferred_username ?? "n/a",
}, },

View file

@ -277,9 +277,11 @@ export class SubFolderFileController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์");
} }
const { file, ...metadata } = body;
// assume user will probably replace file by re-upload but maybe just rename // assume user will probably replace file by re-upload but maybe just rename
if (body.file) { if (file) {
const destination = `${basePath}${replaceIllegalChars(body.file)}`; const destination = `${basePath}${replaceIllegalChars(file)}`;
const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`; const source = `/${DEFAULT_BUCKET}/${basePath}${fileName}`;
const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond); const copy = await minioClient.copyObject(DEFAULT_BUCKET!, destination, source, copyCond);
@ -298,8 +300,10 @@ export class SubFolderFileController extends Controller {
index, index,
id, id,
doc: { doc: {
...metadata,
pathname: destination, pathname: destination,
fileName: replaceIllegalChars(body.file), path: basePath,
fileName: replaceIllegalChars(file),
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a", updatedBy: request.user.preferred_username ?? "n/a",
}, },
@ -324,7 +328,7 @@ export class SubFolderFileController extends Controller {
index, index,
id, id,
doc: { doc: {
...body, ...metadata,
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
updatedBy: request.user.preferred_username ?? "n/a", updatedBy: request.user.preferred_username ?? "n/a",
}, },