fix: move file failed
This commit is contained in:
parent
bbeda11fc6
commit
73673f7ae3
4 changed files with 22 additions and 17 deletions
|
|
@ -467,7 +467,7 @@ export class StorageController extends Controller {
|
|||
@Put("file")
|
||||
@Tags("Storage File")
|
||||
@Security("bearerAuth", ["management-role", "admin"])
|
||||
@SuccessResponse(HttpStatusCode.NO_CONTENT, "สำเร็จ")
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
public async moveFile(
|
||||
@Request() request: { user: { preferred_username: string } },
|
||||
@Body() body: PutFileBody,
|
||||
|
|
@ -494,17 +494,16 @@ export class StorageController extends Controller {
|
|||
});
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบไฟล์ดังกล่าว");
|
||||
}
|
||||
if (body.to && !(await checkPathExist(DEFAULT_BUCKET, body.to.path.join("/")))) {
|
||||
throw new HttpError(HttpStatusCode.PRECONDITION_FAILED, "ไม่พบตำแหน่งที่ต้องการย้าย");
|
||||
}
|
||||
if (
|
||||
body.to &&
|
||||
(await checkFileExist(DEFAULT_BUCKET, body.to.path.join("/") + `/${body.to.file}`))
|
||||
) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.PRECONDITION_FAILED,
|
||||
"พบไฟล์ในต้ำแหน่งปลายทาง ไม่สามารถย้ายได้",
|
||||
);
|
||||
if (body.to && JSON.stringify(body.from) !== JSON.stringify(body.to)) {
|
||||
if (!(await checkPathExist(DEFAULT_BUCKET, body.to.path.join("/")))) {
|
||||
throw new HttpError(HttpStatusCode.PRECONDITION_FAILED, "ไม่พบตำแหน่งที่ต้องการย้าย");
|
||||
}
|
||||
if (await checkFileExist(DEFAULT_BUCKET, body.to.path.join("/") + `/${body.to.file}`)) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.PRECONDITION_FAILED,
|
||||
"พบไฟล์ในต้ำแหน่งปลายทาง ไม่สามารถย้ายได้",
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!search.hits.hits[0]._source) {
|
||||
// This should not possible.
|
||||
|
|
@ -526,7 +525,7 @@ export class StorageController extends Controller {
|
|||
updatedBy: request.user.preferred_username,
|
||||
};
|
||||
|
||||
if (from && to) {
|
||||
if (from && to && JSON.stringify(from) !== JSON.stringify(to)) {
|
||||
const src = [DEFAULT_BUCKET, ...from.path, ""].join("/") + from.file;
|
||||
const dst = to.path.join("/") + `/${to.file}`;
|
||||
|
||||
|
|
@ -544,11 +543,15 @@ export class StorageController extends Controller {
|
|||
...metadata,
|
||||
path: to.path.join("/") + "/",
|
||||
pathname: dst,
|
||||
fileName: to.file,
|
||||
...dateMeta,
|
||||
},
|
||||
refresh: "wait_for",
|
||||
})
|
||||
.then(async () => await minioClient.removeObject(DEFAULT_INDEX, src))
|
||||
.then(
|
||||
async () =>
|
||||
await minioClient.removeObject(DEFAULT_BUCKET, from.path.join("/") + `/${from.file}`),
|
||||
)
|
||||
.catch((e) => console.error(`ElasticSearch Error: ${e}`));
|
||||
|
||||
io.getInstance()?.emit("FileMove", {
|
||||
|
|
@ -558,6 +561,7 @@ export class StorageController extends Controller {
|
|||
...metadata,
|
||||
path: to.path.join("/") + "/",
|
||||
pathname: dst,
|
||||
fileName: to.file,
|
||||
...dateMeta,
|
||||
},
|
||||
});
|
||||
|
|
@ -566,6 +570,7 @@ export class StorageController extends Controller {
|
|||
const presignedUrl = await minioClient.presignedPutObject(DEFAULT_BUCKET, dst);
|
||||
return { uploadUrl: presignedUrl };
|
||||
}
|
||||
return this.setStatus(HttpStatusCode.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue