diff --git a/src/main/capabilities/files.ts b/src/main/capabilities/files.ts index 6ca2641..31387da 100644 --- a/src/main/capabilities/files.ts +++ b/src/main/capabilities/files.ts @@ -59,7 +59,10 @@ register("File_Write", async (_ctx, node, args) => { }); register(["File_CreateFile"], async (_ctx, node, args) => { - const filePath = requirePath(pick(args, ["path", "file", "file_path"]), "文件路径", node.id, node.componentId); + // catalog 字段为 folder_path + name(组合成完整路径),兼容旧键 path + const base = pick(args, ["folder_path", "path", "file", "file_path"]); + const name = pick(args, ["name"]); + const filePath = requirePath(name ? path.join(base, name) : base, "文件路径", node.id, node.componentId); await fs.mkdir(path.dirname(filePath), { recursive: true }); await fs.writeFile(filePath, "", { flag: "a" }); return filePath; @@ -80,8 +83,15 @@ register("File_Copy", async (_ctx, node, args) => { }); register(["File_File_Move", "File_Move"], async (_ctx, node, args) => { - const source = requirePath(pick(args, ["pathSrc", "src", "source"]), "源路径", node.id, node.componentId); - const target = requirePath(pick(args, ["pathDest", "dest", "target"]), "目标路径", node.id, node.componentId); + // File_Move 的 catalog 字段为 file_type + file_path/folder_path + target_path(+name),与 File_File_Move 的 pathSrc/pathDest 兼容 + const isFolder = String(args.file_type ?? "file") === "folder"; + const source = requirePath(pick(args, ["pathSrc", isFolder ? "folder_path" : "file_path", "src", "source"]), "源路径", node.id, node.componentId); + let target = pick(args, ["pathDest", "dest"]); + if (!target) { + const destDir = pick(args, ["target_path"]); + const newName = truthy(args.rename) ? pick(args, ["name"]) : ""; + target = requirePath(newName ? path.join(destDir, newName) : destDir, "目的地路径", node.id, node.componentId); + } await fs.mkdir(path.dirname(target), { recursive: true }); try { await fs.rename(source, target); @@ -152,7 +162,8 @@ register(["File_PathSize", "File_PathSizeNew"], async (_ctx, node, args) => { }); register("File_GetFileInfo", async (_ctx, node, args) => { - const target = requirePath(pick(args, ["path", "file"]), "路径", node.id, node.componentId); + // catalog 字段为 file_path,兼容 path/file + const target = requirePath(pick(args, ["file_path", "path", "file"]), "路径", node.id, node.componentId); const stat = await fs.stat(target); return { path: target, @@ -165,7 +176,8 @@ register("File_GetFileInfo", async (_ctx, node, args) => { }); register("File_WaitFile", async (ctx, node, args) => { - const target = requirePath(pick(args, ["path", "file"]), "文件路径", node.id, node.componentId); + // catalog 字段为 file_path,兼容 path/file + const target = requirePath(pick(args, ["file_path", "path", "file"]), "文件路径", node.id, node.componentId); const timeout = Math.max(1, Number(args.time_out ?? args.timeout ?? 30)) * 1000; const started = Date.now(); while (Date.now() - started < timeout) { @@ -185,7 +197,8 @@ register("File_WaitFile", async (ctx, node, args) => { }); register("File_CompressFile", async (_ctx, node, args) => { - const source = requirePath(pick(args, ["pathSrc", "path", "folder_path"]), "源路径", node.id, node.componentId); + // catalog 字段为 file_path(文件模式)/folder_path(文件夹模式)+ out_path,兼容旧键 + const source = requirePath(pick(args, ["file_path", "pathSrc", "path", "folder_path"]), "源路径", node.id, node.componentId); const target = requirePath(pick(args, ["pathDest", "zip_path", "out_path"]), "压缩包路径", node.id, node.componentId); const zip = new AdmZip(); const stat = await fs.stat(source);