@blockrun/clawrouter 0.12.31 → 0.12.32

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/index.js CHANGED
@@ -6337,14 +6337,29 @@ async function startProxy(options) {
6337
6337
  await mkdir3(IMAGE_DIR, { recursive: true });
6338
6338
  const port2 = server.address()?.port ?? 8402;
6339
6339
  for (const img of result.data) {
6340
- const m = img.url?.match(/^data:(image\/\w+);base64,(.+)$/);
6341
- if (m) {
6342
- const [, mimeType, b64] = m;
6340
+ const dataUriMatch = img.url?.match(/^data:(image\/\w+);base64,(.+)$/);
6341
+ if (dataUriMatch) {
6342
+ const [, mimeType, b64] = dataUriMatch;
6343
6343
  const ext = mimeType === "image/jpeg" ? "jpg" : mimeType.split("/")[1] ?? "png";
6344
6344
  const filename = `${Date.now()}-${Math.random().toString(36).slice(2, 10)}.${ext}`;
6345
6345
  await writeFile2(join5(IMAGE_DIR, filename), Buffer.from(b64, "base64"));
6346
6346
  img.url = `http://localhost:${port2}/images/${filename}`;
6347
6347
  console.log(`[ClawRouter] Image saved \u2192 ${img.url}`);
6348
+ } else if (img.url?.startsWith("https://") || img.url?.startsWith("http://")) {
6349
+ try {
6350
+ const imgResp = await fetch(img.url);
6351
+ if (imgResp.ok) {
6352
+ const contentType = imgResp.headers.get("content-type") ?? "image/png";
6353
+ const ext = contentType.includes("jpeg") || contentType.includes("jpg") ? "jpg" : contentType.includes("webp") ? "webp" : "png";
6354
+ const filename = `${Date.now()}-${Math.random().toString(36).slice(2, 10)}.${ext}`;
6355
+ const buf = Buffer.from(await imgResp.arrayBuffer());
6356
+ await writeFile2(join5(IMAGE_DIR, filename), buf);
6357
+ img.url = `http://localhost:${port2}/images/${filename}`;
6358
+ console.log(`[ClawRouter] Image downloaded & saved \u2192 ${img.url}`);
6359
+ }
6360
+ } catch (downloadErr) {
6361
+ console.warn(`[ClawRouter] Failed to download image, using original URL: ${downloadErr instanceof Error ? downloadErr.message : String(downloadErr)}`);
6362
+ }
6348
6363
  }
6349
6364
  }
6350
6365
  }