@blockrun/clawrouter 0.11.2 → 0.11.3
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/cli.js
CHANGED
|
@@ -4784,6 +4784,27 @@ async function proxyPartnerRequest(req, res, apiBase, payFetch) {
|
|
|
4784
4784
|
}).catch(() => {
|
|
4785
4785
|
});
|
|
4786
4786
|
}
|
|
4787
|
+
async function uploadDataUriToHost(dataUri) {
|
|
4788
|
+
const match = dataUri.match(/^data:(image\/\w+);base64,(.+)$/);
|
|
4789
|
+
if (!match) throw new Error("Invalid data URI format");
|
|
4790
|
+
const [, mimeType, b64Data] = match;
|
|
4791
|
+
const ext = mimeType === "image/jpeg" ? "jpg" : mimeType.split("/")[1] ?? "png";
|
|
4792
|
+
const buffer = Buffer.from(b64Data, "base64");
|
|
4793
|
+
const blob = new Blob([buffer], { type: mimeType });
|
|
4794
|
+
const form = new FormData();
|
|
4795
|
+
form.append("file", blob, `image.${ext}`);
|
|
4796
|
+
const resp = await fetch("https://telegra.ph/upload", {
|
|
4797
|
+
method: "POST",
|
|
4798
|
+
body: form
|
|
4799
|
+
});
|
|
4800
|
+
if (!resp.ok) throw new Error(`telegra.ph upload failed: HTTP ${resp.status}`);
|
|
4801
|
+
const result = await resp.json();
|
|
4802
|
+
if (Array.isArray(result) && result[0]?.src) {
|
|
4803
|
+
return `https://telegra.ph${result[0].src}`;
|
|
4804
|
+
}
|
|
4805
|
+
const errMsg = !Array.isArray(result) && result.error ? result.error : "unknown error";
|
|
4806
|
+
throw new Error(`telegra.ph upload failed: ${errMsg}`);
|
|
4807
|
+
}
|
|
4787
4808
|
async function startProxy(options) {
|
|
4788
4809
|
const apiBase = options.apiBase ?? BLOCKRUN_API;
|
|
4789
4810
|
const listenPort = options.port ?? getProxyPort();
|
|
@@ -5401,7 +5422,19 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
5401
5422
|
} else {
|
|
5402
5423
|
const lines = [];
|
|
5403
5424
|
for (const img of images) {
|
|
5404
|
-
if (img.url)
|
|
5425
|
+
if (img.url) {
|
|
5426
|
+
if (img.url.startsWith("data:")) {
|
|
5427
|
+
try {
|
|
5428
|
+
const hostedUrl = await uploadDataUriToHost(img.url);
|
|
5429
|
+
lines.push(hostedUrl);
|
|
5430
|
+
} catch (uploadErr) {
|
|
5431
|
+
console.error(`[ClawRouter] /imagegen: failed to upload data URI: ${uploadErr instanceof Error ? uploadErr.message : String(uploadErr)}`);
|
|
5432
|
+
lines.push("Image generated but upload failed. Try again or use --model dall-e-3.");
|
|
5433
|
+
}
|
|
5434
|
+
} else {
|
|
5435
|
+
lines.push(img.url);
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5405
5438
|
if (img.revised_prompt) lines.push(`Revised prompt: ${img.revised_prompt}`);
|
|
5406
5439
|
}
|
|
5407
5440
|
lines.push("", `Model: ${imageModel} | Size: ${imageSize}`);
|