Serve downloadable PDFs from a PocketBase documents collection
- New collection "documents" (title, slug, file, category, order, public); editors upload PDFs in the admin, no developer or redeploy needed - The app serves each file at /dokumente/<slug>.pdf, a URL that survives a new upload (PocketBase's own file name gets a random suffix) - New "documents" embed lists them as file cards, grouped by category; /downloads uses it - List/view rules are "public = true", so a draft PDF is not reachable through the PocketBase API either - Dev seed adds example documents with generated PDFs and fixes the const reassignment that broke seeding a fresh volume - Docs: editor guide, architecture, and the manual production setup steps Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
97321e2b49
commit
f1a06956f7
18 files changed
+641
-31
No files matched your search
@@ -128,6 +128,25 @@ app.MapGet("/events/{id}.ics", async (string id, PocketBaseClient pocketBase, Ca
|
||||
: Results.NotFound();
|
||||
});
|
||||
|
||||
// A document's PDF, uploaded by an editor in PocketBase. The app passes the file
|
||||
// through instead of linking PocketBase's own file URL: that URL changes with every new
|
||||
// upload, this one stays /dokumente/<slug>.pdf (see Document). An unknown or non-public
|
||||
// slug is a 404; PocketBase being down is a 503, like the single-event calendar file.
|
||||
app.MapGet("/dokumente/{slug}.pdf", async (string slug, PocketBaseClient pocketBase, CancellationToken token) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var documents = await pocketBase.GetDocumentsAsync(token);
|
||||
return documents.FirstOrDefault(document => document.Slug == slug) is { } match
|
||||
? Results.Stream(await pocketBase.OpenDocumentFileAsync(match, token), "application/pdf")
|
||||
: Results.NotFound();
|
||||
}
|
||||
catch (PocketBaseUnavailableException)
|
||||
{
|
||||
return Results.StatusCode(StatusCodes.Status503ServiceUnavailable);
|
||||
}
|
||||
});
|
||||
|
||||
// Status page for an outside monitor (Uptime Kuma) to check. One check tells all
|
||||
// three states apart: no reply = the app is down, 503 = the app runs but PocketBase
|
||||
// is down, 200 = both are fine. It talks to PocketBase directly, not through the
|
||||
|
||||
Reference in new issue
Block a user