第三步补全接入

This commit is contained in:
Ukawka
2026-09-20 22:21:50 +08:00
parent f095c28858
commit 99d65377ab
14 changed files with 912 additions and 14 deletions
+4 -2
View File
@@ -36,8 +36,10 @@ export async function decodeEditedImages(payload, stage, {fetchImpl = fetch} = {
const decoded = [];
for (const item of items) {
let bytes;
if (typeof item.b64_json === 'string') bytes = Buffer.from(item.b64_json, 'base64');
else if (typeof item.url === 'string') bytes = await downloadImage(item.url, stage, fetchImpl);
// Some relays return both fields, with an empty b64_json for URL output.
// Only a nonempty inline value takes precedence over the download URL.
if (typeof item.b64_json === 'string' && item.b64_json.trim()) bytes = Buffer.from(item.b64_json.trim(), 'base64');
else if (typeof item.url === 'string' && item.url.trim()) bytes = await downloadImage(item.url.trim(), stage, fetchImpl);
else throw new Error('图片编辑响应缺少 b64_json/url');
decoded.push({bytes, ...imageFormat(bytes)});
}