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:
Jeff Emmett 2026-04-03 14:31:22 -07:00
parent 46c326278a
commit d4612d6fb8
1 changed files with 9 additions and 5 deletions

View File

@ -1902,7 +1902,7 @@ app.post("/api/ascii-gen", async (c) => {
prompt,
width: width || 80,
height: height || 40,
palette: palette || "ansi",
palette: palette || "classic",
output_format: output_format || "html",
}),
signal: AbortSignal.timeout(30_000),
@ -1911,8 +1911,11 @@ app.post("/api/ascii-gen", async (c) => {
const err = await res.text();
return c.json({ error: `ASCII art service error: ${err}` }, res.status as any);
}
const data = await res.json();
return c.json(data);
// Service returns raw HTML — wrap in JSON for the client
const htmlContent = await res.text();
// Strip HTML tags to get plain text version
const textContent = htmlContent.replace(/<[^>]*>/g, "").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
return c.json({ html: htmlContent, text: textContent });
} catch (e: any) {
console.error("[ascii-gen] error:", e);
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();
return c.json({ error: `ASCII render error: ${err}` }, res.status as any);
}
const data = await res.json();
return c.json(data);
const htmlContent = await res.text();
const textContent = htmlContent.replace(/<[^>]*>/g, "").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
return c.json({ html: htmlContent, text: textContent });
} catch (e: any) {
console.error("[ascii-gen] render error:", e);
return c.json({ error: `ASCII art service unavailable: ${e.message}` }, 502);