diff --git a/api/src/routes/admin.ts b/api/src/routes/admin.ts index 171d582..028cab8 100644 --- a/api/src/routes/admin.ts +++ b/api/src/routes/admin.ts @@ -668,7 +668,21 @@ router.get("/api/v1/admin/compliance-orders/:order_number/documents", requireAdm const exists = await pool.query("SELECT 1 FROM compliance_orders WHERE order_number = $1", [req.params.order_number]); if (exists.rows.length === 0) { res.status(404).json({ error: "Order not found." }); return; } const docs = await collectOrderDocuments(req.params.order_number); - res.json({ order_number: req.params.order_number, documents: docs }); + // Verify each object actually exists in storage so the UI can disable dead + // links (a key can be recorded in the DB before the object is uploaded, e.g. + // a prepared-filing path written for an order whose prep never completed). + const checked = await Promise.all(docs.map(async (d) => { + let present = false; + try { + const url = await presignInternal(d.key); + if (url) { + const head = await fetch(url, { method: "HEAD" }); + present = head.ok; + } + } catch { /* treat as missing */ } + return { ...d, exists: present }; + })); + res.json({ order_number: req.params.order_number, documents: checked }); } catch (err) { console.error("[admin/compliance-orders/documents] Error:", err); res.status(500).json({ error: "Could not list documents." }); @@ -696,6 +710,10 @@ router.get("/api/v1/admin/compliance-orders/:order_number/document", requireAdmi if (!url) { res.status(502).json({ error: "Could not generate object URL." }); return; } const upstream = await fetch(url); + if (upstream.status === 404) { + res.status(404).json({ error: "Document not found in storage (it may not have been generated yet)." }); + return; + } if (!upstream.ok || !upstream.body) { res.status(502).json({ error: `Object fetch failed (${upstream.status}).` }); return; diff --git a/site/public/admin/compliance-orders/index.html b/site/public/admin/compliance-orders/index.html index 86595c0..644fdf6 100644 --- a/site/public/admin/compliance-orders/index.html +++ b/site/public/admin/compliance-orders/index.html @@ -386,12 +386,13 @@ box.innerHTML = documents.map((d) => { const u = API + "/api/v1/admin/compliance-orders/" + encodeURIComponent(orderNumber) + "/document?key=" + encodeURIComponent(d.key) + "&token=" + tok; + const action = (d.exists === false) + ? `not generated yet` + : `View`; return `
${esc(d.label)} ${esc(d.key.split("/").pop())} -
- View -
`; +
${action}
`; }).join(""); } catch (e) { box.innerHTML = `
Could not load documents: ${esc(e.message)}
`;