fix: render image description when chunk has no bbox (no broken crop)
29 image chunks have an empty bbox {}, and `fm.bbox ?? default` doesn't catch
an empty object, so the crop URL got w=undefined → /api/crop 400 → broken-image
icon. Now validate bbox (w/h > 0); without it, render the image's textual
description instead of requesting an impossible crop.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
504b20fa5c
commit
b94f4869de
1 changed files with 27 additions and 0 deletions
|
|
@ -141,6 +141,33 @@ function ChunkCard({
|
|||
|
||||
// Image chunks: render crop inline
|
||||
if (fm.type === "image" || fm.image_type) {
|
||||
const hasValidBbox =
|
||||
bbox &&
|
||||
typeof bbox.w === "number" && typeof bbox.h === "number" &&
|
||||
typeof bbox.x === "number" && typeof bbox.y === "number" &&
|
||||
bbox.w > 0 && bbox.h > 0;
|
||||
|
||||
// No crop coordinates → don't request a broken crop (400). Render the
|
||||
// image's textual description so the content is still surfaced.
|
||||
if (!hasValidBbox) {
|
||||
const descEn = fm.image_description_en || content_en;
|
||||
const descPt = fm.image_description_pt_br || content_pt;
|
||||
if (!descEn && !descPt) return null;
|
||||
return (
|
||||
<figure className="relative my-8" id={fm.chunk_id}>
|
||||
{anchor}
|
||||
<div className="border border-[rgba(0,255,156,0.20)] bg-[#0a121e] rounded p-4 text-sm text-[#c8d4e6]">
|
||||
<div className="font-mono text-[10px] text-[#7fdbff] mb-2">
|
||||
🖼 {fm.chunk_id} · p{fm.page}
|
||||
{fm.image_type ? ` · ${fm.image_type}` : ""} · descrição (sem recorte)
|
||||
</div>
|
||||
{showEn && descEn && <p className="mb-1"><b>EN:</b> {descEn}</p>}
|
||||
{showPt && descPt && <p><b>PT-BR:</b> {descPt}</p>}
|
||||
</div>
|
||||
</figure>
|
||||
);
|
||||
}
|
||||
|
||||
const cropUrl =
|
||||
`/api/crop?doc=${encodeURIComponent(docId)}` +
|
||||
`&page=${fm.page}&x=${bbox.x}&y=${bbox.y}&w=${bbox.w}&h=${bbox.h}&w_px=800`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue