fix: two bugs in Cloud Storage PDF viewing surfaced by live testing

- PDF viewer hung on "Loading" forever for cloud-backed PDFs: streamFileTo
  pipes with {end: false} (by design, so cloud-storage.ts's own routes can
  call res.end() themselves), but the new /pdf-files/:id cloud branch never
  did, so the HTTP response never completed.
- Documents page showed nothing for patients whose PDFs are only in Cloud
  Storage: the page lists categories from the legacy PdfGroup table, which
  new saves stopped populating. savePdfToCloudStorage now also ensures a
  blob-less PdfGroup row exists per patient/category so the category still
  appears, with actual files served from Cloud Storage via the existing
  merge in the pdf-files/group listing routes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-08 14:36:02 -04:00
co-authored by Claude Sonnet 5
parent 3582da8510
commit 0f0f3a6db9
2 changed files with 25 additions and 0 deletions
+2
View File
@@ -290,9 +290,11 @@ router.get(
);
try {
await storage.streamFileTo(res, cloudId);
if (!res.writableEnded) res.end();
} catch (streamErr) {
console.error("Error streaming cloud PDF file:", streamErr);
if (!res.headersSent) res.status(500).json({ error: "Failed to stream PDF" });
else if (!res.writableEnded) res.end();
}
return;
}