feat: 图片Base64编解码组件统一(Encode并入方向切换,Decode隐藏), 验证任务归并: 图像OCR未测任务 41->7 (Base64/CV/OCR票据卡证证照通用离线)

This commit is contained in:
yu committed 2026-11-03 14:28:23 +08:00
1 parent 4486c57536
commit 8fdc62d98d
4 files changed
+96 -8

No files matched your search

+19 -1
View File
@@ -165,7 +165,25 @@ async function captureScreen(file: string) {
fs.mkdirSync(path.dirname(file), { recursive: true });
await powershell(`Add-Type -AssemblyName System.Drawing;Add-Type -AssemblyName System.Windows.Forms;$bounds=[System.Windows.Forms.Screen]::PrimaryScreen.Bounds;$bitmap=New-Object System.Drawing.Bitmap $bounds.Width,$bounds.Height;$graphics=[System.Drawing.Graphics]::FromImage($bitmap);$graphics.CopyFromScreen($bounds.Location,[System.Drawing.Point]::Empty,$bounds.Size);$bitmap.Save(${psString(file)});$graphics.Dispose();$bitmap.Dispose()`);
}
register("Image_Base64Encode", async (_ctx, _node, args) => fs.readFileSync(path.resolve(text(args, ["path", "image"]))).toString("base64"));
// 图片Base64编解码: 统一组件按 mode 分流(encode=图片→Base64, decode=Base64→图片)。
// Image_Base64Decode 已隐藏进该组件,但保留注册以防旧流程直接引用旧 id。
register("Image_Base64Encode", async (_ctx, node, args) => {
const mode = text(args, ["mode"], "encode");
if (mode === "decode") {
const value = text(args, ["val", "value"]).replace(/^data:[^;]+;base64,/, "");
if (!value.trim()) throw new RuntimeError("validation_error", "Base64编码不能为空", { nodeId: node.id, componentId: node.componentId, recommendation: "填写 base64 字符串,或用 ${变量} 引用上游编码输出" });
const custom = text(args, ["output"]).trim();
const file = custom ? path.resolve(custom) : path.resolve(process.cwd(), `image-${Date.now()}.png`);
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, Buffer.from(value, "base64"));
return file;
}
const imageArg = text(args, ["path", "image"]);
if (!imageArg.trim()) throw new RuntimeError("validation_error", "图片对象不能为空", { nodeId: node.id, componentId: node.componentId, recommendation: "填写源图片路径,或用 ${变量} 引用上游截图输出" });
const source = path.resolve(imageArg);
if (!fs.existsSync(source)) throw new RuntimeError("validation_error", `找不到图片文件:${source}`, { nodeId: node.id, componentId: node.componentId, recommendation: "确认路径正确,或先用「屏幕截图」组件生成图片" });
return fs.readFileSync(source).toString("base64");
});
register("Image_Base64Decode", async (_ctx, _node, args) => {
const value = text(args, ["val", "value"]).replace(/^data:[^;]+;base64,/, ""); const file = path.resolve(process.cwd(), `image-${Date.now()}.png`);
fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, Buffer.from(value, "base64")); return file;