fix(rsplat): handle formData parse errors in image-stage endpoint
Wrap formData() in try/catch with logging to diagnose Content-Type issues through Cloudflare tunnel. Also fix client-side error handling to clear progress timer and show actual error message on failure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fd63c2bc6f
commit
f1de3b654e
|
|
@ -678,8 +678,10 @@ export class FolkSplatViewer extends HTMLElement {
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
status.textContent = "Network error — could not reach server";
|
clearInterval(ticker);
|
||||||
|
document.removeEventListener("visibilitychange", onVisChange);
|
||||||
|
status.textContent = e?.message || "Network error — could not reach server";
|
||||||
progress.style.display = "none";
|
progress.style.display = "none";
|
||||||
actions.style.display = "flex";
|
actions.style.display = "flex";
|
||||||
submitBtn.disabled = false;
|
submitBtn.disabled = false;
|
||||||
|
|
|
||||||
|
|
@ -1179,7 +1179,26 @@ app.post("/api/video-gen/i2v", async (c) => {
|
||||||
// Stage image for 3D generation (binary upload → HTTPS URL for fal.ai)
|
// Stage image for 3D generation (binary upload → HTTPS URL for fal.ai)
|
||||||
const PUBLIC_ORIGIN = process.env.PUBLIC_ORIGIN || "https://rspace.online";
|
const PUBLIC_ORIGIN = process.env.PUBLIC_ORIGIN || "https://rspace.online";
|
||||||
app.post("/api/image-stage", async (c) => {
|
app.post("/api/image-stage", async (c) => {
|
||||||
const formData = await c.req.formData();
|
const ct = c.req.header("content-type") || "";
|
||||||
|
console.log("[image-stage] Content-Type:", ct);
|
||||||
|
|
||||||
|
let formData: FormData;
|
||||||
|
try {
|
||||||
|
formData = await c.req.formData();
|
||||||
|
} catch (e: any) {
|
||||||
|
console.error("[image-stage] formData parse failed:", e.message, "| Content-Type:", ct);
|
||||||
|
// Fallback: try reading raw body as binary if it's not multipart
|
||||||
|
if (ct.startsWith("application/octet-stream") || !ct.includes("multipart")) {
|
||||||
|
const buf = Buffer.from(await c.req.arrayBuffer());
|
||||||
|
if (!buf.length) return c.json({ error: "Empty body" }, 400);
|
||||||
|
const dir = resolve(process.env.FILES_DIR || "./data/files", "generated");
|
||||||
|
const filename = `stage-${Date.now()}-${Math.random().toString(36).slice(2, 6)}.jpg`;
|
||||||
|
await Bun.write(resolve(dir, filename), buf);
|
||||||
|
return c.json({ url: `${PUBLIC_ORIGIN}/data/files/generated/${filename}` });
|
||||||
|
}
|
||||||
|
return c.json({ error: "Invalid upload format. Expected multipart/form-data." }, 400);
|
||||||
|
}
|
||||||
|
|
||||||
const file = formData.get("file") as File | null;
|
const file = formData.get("file") as File | null;
|
||||||
if (!file) return c.json({ error: "file required" }, 400);
|
if (!file) return c.json({ error: "file required" }, 400);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue