guanghulab/video-ai-system/engines/image-api-bridge.js
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

65 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* image-api-bridge.js · Python ↔ Node 图片API桥接
* D144 · 铸渊 ICE-GL-ZY001
*
* Python 通过 subprocess 调用本脚本stdin 输入 JSON 命令stdout 输出 JSON 结果。
* 解决 char-hero-design-packer.py 依赖 JS image-api-adapter 的问题。
*
* 用法:
* echo '{"action":"generate_character_ref","charId":"CHAR-003","l0":"...","l1":"..."}' | node image-api-bridge.js
* echo '{"action":"generate_image","prompt":"...","size":"2048x2048","filename":"test.png"}' | node image-api-bridge.js
*/
// 桥接模式:所有日志输出到 stderrstdout 只输出最终 JSON 结果
console.log = (...args) => process.stderr.write(args.join(' ') + '\n');
console.warn = (...args) => process.stderr.write(args.join(' ') + '\n');
console.error = (...args) => process.stderr.write(args.join(' ') + '\n');
const { generateImage, generateCharacterRef } = require('./image-api-adapter');
let input = '';
process.stdin.setEncoding('utf8');
process.stdin.on('data', chunk => input += chunk);
process.stdin.on('end', async () => {
try {
const req = JSON.parse(input || '{}');
let result;
switch (req.action) {
case 'generate_character_ref': {
const { charId, l0, l1 } = req;
if (!charId) throw new Error('缺少 charId');
result = await generateCharacterRef({
charId,
l0Descriptor: l0 || '中国古代修仙少年16岁亚洲面孔',
l1Config: l1 ? { clothing: l1 } : undefined,
});
break;
}
case 'generate_image': {
const { prompt, size, filename, outputPath } = req;
if (!prompt) throw new Error('缺少 prompt');
result = await generateImage({ prompt, size, filename, outputPath });
break;
}
default:
throw new Error(`未知操作: ${req.action}`);
}
process.stdout.write(JSON.stringify({ ok: true, data: result }) + '\n');
process.exit(0);
} catch (err) {
process.stdout.write(JSON.stringify({ ok: false, error: err.message }) + '\n');
process.exit(1);
}
});
// stdin 已关闭pipe 模式),直接触发 end
if (process.stdin.isTTY) {
process.stderr.write('用法: echo \'{"action":"..."}\' | node image-api-bridge.js\n');
process.exit(1);
}