mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-04-06 17:10:29 +08:00
Optimized implement method, use frontend filemanager to check file
This commit is contained in:
parent
955be538ad
commit
65a2664cf7
@ -203,18 +203,3 @@ routerApp.on("file/compress", async (ctx, data) => {
|
||||
protocol.responseError(ctx, error);
|
||||
}
|
||||
});
|
||||
|
||||
// Check file is exists in path
|
||||
routerApp.on("file/exists", async (ctx, data) => {
|
||||
try {
|
||||
const fileName = data.uploadFilename;
|
||||
const dir = data.uploadDir;
|
||||
const fileManager = getFileManager(data.instanceUuid);
|
||||
|
||||
const exists = fileManager.exists(dir, fileName);
|
||||
protocol.response(ctx, exists);
|
||||
} catch (error: any) {
|
||||
console.log(error);
|
||||
protocol.responseError(ctx, error);
|
||||
}
|
||||
});
|
||||
|
@ -18,8 +18,7 @@ import {
|
||||
uploadAddress,
|
||||
uploadFile as uploadFileApi,
|
||||
downloadAddress,
|
||||
changePermission as changePermissionApi,
|
||||
prepareUploadFile as prepareUploadFileApi
|
||||
changePermission as changePermissionApi
|
||||
} from "@/services/apis/fileManager";
|
||||
import type {
|
||||
DataType,
|
||||
@ -350,7 +349,6 @@ export const useFileManager = (instanceId?: string, daemonId?: string) => {
|
||||
|
||||
const selectedFile = async (file: File) => {
|
||||
const { execute: uploadFile } = uploadFileApi();
|
||||
const { state: prepareUploadFileResp, execute: prepareUploadFile } = prepareUploadFileApi();
|
||||
const { state: uploadCfg, execute: getUploadCfg } = uploadAddress();
|
||||
try {
|
||||
percentComplete.value = 1;
|
||||
@ -368,29 +366,14 @@ export const useFileManager = (instanceId?: string, daemonId?: string) => {
|
||||
throw new Error(t("TXT_CODE_e8ce38c2"));
|
||||
}
|
||||
|
||||
var shouldOverwrite = false;
|
||||
let shouldOverwrite = false;
|
||||
|
||||
await prepareUploadFile({
|
||||
params: {
|
||||
daemonId: daemonId!,
|
||||
uuid: instanceId!,
|
||||
uploadDir: uploadDir,
|
||||
uploadFilename: file.name
|
||||
}
|
||||
}).then((bl) => {
|
||||
console.log(bl);
|
||||
});
|
||||
|
||||
console.log(prepareUploadFileResp.value);
|
||||
if (prepareUploadFileResp.value == undefined) {
|
||||
percentComplete.value = 0;
|
||||
throw new Error(t("TXT_CODE_4caa5237"));
|
||||
} else if (prepareUploadFileResp.value.exists) {
|
||||
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"),
|
||||
@ -399,15 +382,17 @@ export const useFileManager = (instanceId?: string, daemonId?: string) => {
|
||||
onOk() {
|
||||
complete(true);
|
||||
},
|
||||
onCancel() {
|
||||
onCancel() {
|
||||
complete(false);
|
||||
percentComplete.value = 0;
|
||||
}
|
||||
});
|
||||
|
||||
shouldOverwrite = await promise;
|
||||
if (!shouldOverwrite) {
|
||||
return reportErrorMsg(t("TXT_CODE_8b14426e"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!shouldOverwrite) {
|
||||
return reportErrorMsg(t("TXT_CODE_8b14426e"));
|
||||
}
|
||||
|
||||
const uploadFormData = new FormData();
|
||||
|
@ -153,8 +153,7 @@ export const uploadAddress = useDefineApi<
|
||||
params: {
|
||||
upload_dir: string;
|
||||
daemonId: string;
|
||||
uuid: string,
|
||||
file_name: string;
|
||||
uuid: string;
|
||||
};
|
||||
},
|
||||
{
|
||||
@ -230,21 +229,4 @@ export const changePermission = useDefineApi<
|
||||
>({
|
||||
url: "/api/files/chmod",
|
||||
method: "PUT"
|
||||
});
|
||||
|
||||
export const prepareUploadFile = useDefineApi<
|
||||
{
|
||||
params: {
|
||||
daemonId: string;
|
||||
uuid: string,
|
||||
uploadDir: string,
|
||||
uploadFilename: string;
|
||||
};
|
||||
},
|
||||
{
|
||||
exists: boolean
|
||||
}
|
||||
>({
|
||||
url: "/api/files/pre_upload",
|
||||
method: "GET"
|
||||
});
|
||||
});
|
@ -161,8 +161,7 @@ const selectedFile = async () => {
|
||||
await getCfg({
|
||||
params: {
|
||||
upload_dir: ".",
|
||||
daemonId: props.daemonId,
|
||||
file_name: uFile.value?.name
|
||||
daemonId: props.daemonId
|
||||
},
|
||||
data: formData
|
||||
});
|
||||
|
@ -1902,7 +1902,6 @@
|
||||
"TXT_CODE_e039b9b5": "normal",
|
||||
"TXT_CODE_a788e3eb": "Memory & Processor",
|
||||
"TXT_CODE_c5ed896f": "The instantaneous output content is too long and has been rejected....",
|
||||
"TXT_CODE_4caa5237": "Failed to resolve file pre-upload status",
|
||||
"TXT_CODE_99ca8563": "Overwriting File",
|
||||
"TXT_CODE_ec99ddaa": "File",
|
||||
"TXT_CODE_8bd1f5d2": "is already exists in this folder, should overwrite it?",
|
||||
|
@ -1902,7 +1902,6 @@
|
||||
"TXT_CODE_6b4a27dd": "网页前端无法与节点建立 WebSocket 连接,请检查网络代理配置或防火墙配置!",
|
||||
"TXT_CODE_a788e3eb": "内存 & 处理器",
|
||||
"TXT_CODE_c5ed896f": "此刻瞬时输出内容过长,已拒绝显示...",
|
||||
"TXT_CODE_4caa5237": "获取文件存在状态失败",
|
||||
"TXT_CODE_99ca8563": "覆盖文件",
|
||||
"TXT_CODE_ec99ddaa": "您上传的文件",
|
||||
"TXT_CODE_8bd1f5d2": "已经在目录中存在, 是否覆盖原文件?",
|
||||
|
@ -316,7 +316,6 @@ router.all(
|
||||
const daemonId = String(ctx.query.daemonId);
|
||||
const instanceUuid = String(ctx.query.uuid);
|
||||
const uploadDir = String(ctx.query.upload_dir);
|
||||
const uploadFilename = String(ctx.query.file_name);
|
||||
const remoteService = RemoteServiceSubsystem.getInstance(daemonId);
|
||||
const addr = `${remoteService?.config.ip}:${remoteService?.config.port}${
|
||||
remoteService?.config.prefix ? removeTrail(remoteService.config.prefix, "/") : ""
|
||||
@ -327,8 +326,7 @@ router.all(
|
||||
password: password,
|
||||
parameter: {
|
||||
uploadDir,
|
||||
instanceUuid,
|
||||
uploadFilename
|
||||
instanceUuid
|
||||
}
|
||||
});
|
||||
ctx.body = {
|
||||
@ -341,31 +339,4 @@ router.all(
|
||||
}
|
||||
);
|
||||
|
||||
router.get(
|
||||
"/pre_upload",
|
||||
permission({ level: ROLE.USER }),
|
||||
validator({
|
||||
query: { daemonId: String, uuid: String, uploadDir: String, uploadFilename: String },
|
||||
}),
|
||||
async (ctx) => {
|
||||
try {
|
||||
const daemonId = String(ctx.query.daemonId);
|
||||
const instanceUuid = String(ctx.query.uuid);
|
||||
const uploadDir = String(ctx.query.uploadDir);
|
||||
const uploadFilename = String(ctx.query.uploadFilename);
|
||||
const remoteService = RemoteServiceSubsystem.getInstance(daemonId);
|
||||
const result = await new RemoteRequest(remoteService).request("file/exists", {
|
||||
instanceUuid,
|
||||
uploadDir,
|
||||
uploadFilename
|
||||
});
|
||||
ctx.body = {
|
||||
exists: result
|
||||
};
|
||||
} catch (err) {
|
||||
ctx.body = err;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export default router;
|
||||
|
Loading…
x
Reference in New Issue
Block a user