fix(ascii-gen): handle raw HTML response from ascii-art service
The ascii-art service returns raw HTML, not JSON. Wrap response in
{html, text} JSON envelope and strip tags for plain text version.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
46c326278a
commit
d4612d6fb8
|
|
@ -1902,7 +1902,7 @@ app.post("/api/ascii-gen", async (c) => {
|
||||||
prompt,
|
prompt,
|
||||||
width: width || 80,
|
width: width || 80,
|
||||||
height: height || 40,
|
height: height || 40,
|
||||||
palette: palette || "ansi",
|
palette: palette || "classic",
|
||||||
output_format: output_format || "html",
|
output_format: output_format || "html",
|
||||||
}),
|
}),
|
||||||
signal: AbortSignal.timeout(30_000),
|
signal: AbortSignal.timeout(30_000),
|
||||||
|
|
@ -1911,8 +1911,11 @@ app.post("/api/ascii-gen", async (c) => {
|
||||||
const err = await res.text();
|
const err = await res.text();
|
||||||
return c.json({ error: `ASCII art service error: ${err}` }, res.status as any);
|
return c.json({ error: `ASCII art service error: ${err}` }, res.status as any);
|
||||||
}
|
}
|
||||||
const data = await res.json();
|
// Service returns raw HTML — wrap in JSON for the client
|
||||||
return c.json(data);
|
const htmlContent = await res.text();
|
||||||
|
// Strip HTML tags to get plain text version
|
||||||
|
const textContent = htmlContent.replace(/<[^>]*>/g, "").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
||||||
|
return c.json({ html: htmlContent, text: textContent });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("[ascii-gen] error:", e);
|
console.error("[ascii-gen] error:", e);
|
||||||
return c.json({ error: `ASCII art service unavailable: ${e.message}` }, 502);
|
return c.json({ error: `ASCII art service unavailable: ${e.message}` }, 502);
|
||||||
|
|
@ -1931,8 +1934,9 @@ app.post("/api/ascii-gen/render", async (c) => {
|
||||||
const err = await res.text();
|
const err = await res.text();
|
||||||
return c.json({ error: `ASCII render error: ${err}` }, res.status as any);
|
return c.json({ error: `ASCII render error: ${err}` }, res.status as any);
|
||||||
}
|
}
|
||||||
const data = await res.json();
|
const htmlContent = await res.text();
|
||||||
return c.json(data);
|
const textContent = htmlContent.replace(/<[^>]*>/g, "").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
||||||
|
return c.json({ html: htmlContent, text: textContent });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("[ascii-gen] render error:", e);
|
console.error("[ascii-gen] render error:", e);
|
||||||
return c.json({ error: `ASCII art service unavailable: ${e.message}` }, 502);
|
return c.json({ error: `ASCII art service unavailable: ${e.message}` }, 502);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue