@blockrun/clawrouter 0.11.2 → 0.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +34 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +34 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4934,6 +4934,27 @@ async function proxyPartnerRequest(req, res, apiBase, payFetch) {
|
|
|
4934
4934
|
}).catch(() => {
|
|
4935
4935
|
});
|
|
4936
4936
|
}
|
|
4937
|
+
async function uploadDataUriToHost(dataUri) {
|
|
4938
|
+
const match = dataUri.match(/^data:(image\/\w+);base64,(.+)$/);
|
|
4939
|
+
if (!match) throw new Error("Invalid data URI format");
|
|
4940
|
+
const [, mimeType, b64Data] = match;
|
|
4941
|
+
const ext = mimeType === "image/jpeg" ? "jpg" : mimeType.split("/")[1] ?? "png";
|
|
4942
|
+
const buffer = Buffer.from(b64Data, "base64");
|
|
4943
|
+
const blob = new Blob([buffer], { type: mimeType });
|
|
4944
|
+
const form = new FormData();
|
|
4945
|
+
form.append("reqtype", "fileupload");
|
|
4946
|
+
form.append("fileToUpload", blob, `image.${ext}`);
|
|
4947
|
+
const resp = await fetch("https://catbox.moe/user/api.php", {
|
|
4948
|
+
method: "POST",
|
|
4949
|
+
body: form
|
|
4950
|
+
});
|
|
4951
|
+
if (!resp.ok) throw new Error(`catbox.moe upload failed: HTTP ${resp.status}`);
|
|
4952
|
+
const result = await resp.text();
|
|
4953
|
+
if (result.startsWith("https://")) {
|
|
4954
|
+
return result.trim();
|
|
4955
|
+
}
|
|
4956
|
+
throw new Error(`catbox.moe upload failed: ${result}`);
|
|
4957
|
+
}
|
|
4937
4958
|
async function startProxy(options) {
|
|
4938
4959
|
const apiBase = options.apiBase ?? BLOCKRUN_API;
|
|
4939
4960
|
const listenPort = options.port ?? getProxyPort();
|
|
@@ -5551,7 +5572,19 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5551
5572
|
} else {
|
|
5552
5573
|
const lines = [];
|
|
5553
5574
|
for (const img of images) {
|
|
5554
|
-
if (img.url)
|
|
5575
|
+
if (img.url) {
|
|
5576
|
+
if (img.url.startsWith("data:")) {
|
|
5577
|
+
try {
|
|
5578
|
+
const hostedUrl = await uploadDataUriToHost(img.url);
|
|
5579
|
+
lines.push(hostedUrl);
|
|
5580
|
+
} catch (uploadErr) {
|
|
5581
|
+
console.error(`[ClawRouter] /imagegen: failed to upload data URI: ${uploadErr instanceof Error ? uploadErr.message : String(uploadErr)}`);
|
|
5582
|
+
lines.push("Image generated but upload failed. Try again or use --model dall-e-3.");
|
|
5583
|
+
}
|
|
5584
|
+
} else {
|
|
5585
|
+
lines.push(img.url);
|
|
5586
|
+
}
|
|
5587
|
+
}
|
|
5555
5588
|
if (img.revised_prompt) lines.push(`Revised prompt: ${img.revised_prompt}`);
|
|
5556
5589
|
}
|
|
5557
5590
|
lines.push("", `Model: ${imageModel} | Size: ${imageSize}`);
|