Improve file overwrite confirm

This commit is contained in:
killerprojecte 2024-08-08 16:20:29 +08:00
parent 65a2664cf7
commit a89df0266a
2 changed files with 13 additions and 27 deletions

View File

@ -251,14 +251,4 @@ export default class FileManager {
}
return true;
}
exists(uploadDir: string, fileName: string): boolean {
const fileSaveRelativePath = path.normalize(path.join(uploadDir, fileName));
if (!FileManager.checkFileName(path.basename(fileName)))
throw new Error("Access denied: Malformed file name");
if (!this.checkPath(fileSaveRelativePath))
throw new Error("Access denied: Invalid destination");
const fileSaveAbsolutePath = this.toAbsolutePath(fileSaveRelativePath);
return fs.existsSync(fileSaveAbsolutePath)
}
}

View File

@ -369,23 +369,19 @@ export const useFileManager = (instanceId?: string, daemonId?: string) => {
let shouldOverwrite = false;
if (dataSource.value?.find((dataType) => dataType.name === file.name)) {
var complete: (value: boolean) => void, reject: (reason?: any) => void;
var promise: Promise<boolean> = new Promise((onComplete, onReject) => {
complete = onComplete;
reject = onReject;
});
Modal.confirm({
title: t("TXT_CODE_99ca8563"),
icon: createVNode(ExclamationCircleOutlined),
content: t("TXT_CODE_ec99ddaa") + ` ${file.name} ` + t("TXT_CODE_8bd1f5d2"),
onOk() {
complete(true);
},
onCancel() {
complete(false);
percentComplete.value = 0;
}
let promise: Promise<boolean> = new Promise((onComplete, onReject) => {
Modal.confirm({
title: t("TXT_CODE_99ca8563"),
icon: createVNode(ExclamationCircleOutlined),
content: t("TXT_CODE_ec99ddaa") + ` ${file.name} ` + t("TXT_CODE_8bd1f5d2"),
onOk() {
onComplete(true);
},
onCancel() {
onComplete(false);
percentComplete.value = 0;
}
});
});
shouldOverwrite = await promise;