From 1bb28e3368fbf9ee7e9eafb551bf9060c48d855b Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Mon, 2 Nov 2026 15:09:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=88=AA=E5=9B=BE=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E5=85=BC=E5=AE=B9=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 目标文件路径语义为完整文件路径(含文件名), 提示文案不变 - 容错: 填的是已存在文件夹或以分隔符结尾时, 自动往里存默认文件名(screenshot_时间戳.png 或配置的文件名称), 不再报 EISDIR --- src/main/capabilities/vision.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/capabilities/vision.ts b/src/main/capabilities/vision.ts index c9eaa80..6193755 100644 --- a/src/main/capabilities/vision.ts +++ b/src/main/capabilities/vision.ts @@ -75,6 +75,18 @@ export function cropPng(source: PNG, region: { x: number; y: number; width: numb return cropped; } +/** 目标路径容错:填的是文件夹(已存在或以分隔符结尾)时,自动往里存默认文件名 */ +async function resolveOutputPath(outputPath: string, defaultName: string): Promise { + if (/[\\/]$/.test(outputPath)) return path.join(outputPath, defaultName); + try { + const stat = await fs.stat(outputPath); + if (stat.isDirectory()) return path.join(outputPath, defaultName); + } catch { + // 路径不存在说明是要新建的文件,原样返回 + } + return outputPath; +} + register("Image_Screenshot", async (ctx, node, args) => { const folder = text(args, ["outImagePath", "folder"]); const name = text(args, ["outImageName", "name"], `screenshot_${Date.now()}.png`); @@ -95,9 +107,12 @@ register("Image_Screenshot", async (ctx, node, args) => { image = PNG.sync.read(await fs.readFile(sourceFile)); output = folder ? path.resolve(path.join(folder, name)) : sourceFile; } else { - // 当前屏幕来源:image_path 即保存路径,缺省用 输出目录+文件名;再缺省落流程证据目录(路径可预期) + // 当前屏幕来源:image_path 即保存路径(文件夹则自动追加默认文件名),缺省用 输出目录+文件名;再缺省落流程证据目录(路径可预期) image = await capturePrimaryScreenPng(); - output = path.resolve(imageArg || (folder ? path.join(folder, name) : path.join(ctx.evidenceDir, name))); + output = await resolveOutputPath( + path.resolve(imageArg || (folder ? path.join(folder, name) : path.join(ctx.evidenceDir, name))), + name + ); } if (range === "2") {