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
+6
-4
@@ -28,8 +28,10 @@ architecture. Never global.
|
||||
## AE-2: Content in PocketBase, read per request (revised)
|
||||
|
||||
**Decision:** All visible content lives in **PocketBase** (collections `pages`,
|
||||
`posts`, `events`, `faq_topics`, `faqs`); the app reads it over the REST API per
|
||||
request via a typed `PocketBaseClient`. Documents remain PDFs under `wwwroot`.
|
||||
`posts`, `events`, `faq_topics`, `faqs`, `documents`); the app reads it over the
|
||||
REST API per request via a typed `PocketBaseClient`. Downloadable PDFs are uploads in
|
||||
`documents`; the app passes them through at `/dokumente/<slug>.pdf`, a URL that stays
|
||||
stable when an editor uploads a new version (PocketBase's own file URL does not).
|
||||
|
||||
**Original decision (stage 1):** Content as files in the repo — Markdown with YAML
|
||||
frontmatter, events as `Content/events.yml`. The rationale then was: no DB backup,
|
||||
@@ -51,8 +53,8 @@ the content — the backup is now `pb_data` (see AE-3 and `deployment.md`).
|
||||
## AE-3: Content lives in PocketBase's `pb_data`, not baked into the image (revised)
|
||||
|
||||
**Decision:** The editable content lives in PocketBase's `pb_data`, a persistent
|
||||
volume separate from the app image. Only the static assets under `wwwroot/` (CSS,
|
||||
fonts, PDFs) are baked into the image.
|
||||
volume separate from the app image, uploaded PDFs included. Only the static assets
|
||||
under `wwwroot/` (CSS, fonts, images) are baked into the image.
|
||||
|
||||
**Original decision (stage 1):** `Content/` and `wwwroot/` were both baked into the
|
||||
image, deliberately **not** a mounted volume, so the live state could never drift
|
||||
|
||||
+29
-1
@@ -213,6 +213,33 @@ when the runner is down. It does not deploy.
|
||||
|
||||
---
|
||||
|
||||
## Schema changes in production
|
||||
|
||||
Production is never seeded from the repo, so a new collection or field that a
|
||||
release depends on is set up by hand in the production admin
|
||||
(`redaktion.elternbeirat-igmh.info/_/`) — **before** merging the release, because
|
||||
the app reads the new collection as soon as it is live. A missing collection only
|
||||
degrades (the embed stays empty, the route answers 503), it does not break pages.
|
||||
|
||||
The repo's `pb/pb_migrations/collections_schema.json` is the reference for what
|
||||
production should look like. Current one-time steps:
|
||||
|
||||
**`documents` (downloads):**
|
||||
|
||||
1. *Settings → Import collections*, paste a JSON array holding **only** the
|
||||
`documents` object from `collections_schema.json`, keep the merge option on so
|
||||
the review lists **no** collection to delete, then confirm.
|
||||
2. *Collections → pages → Edit collection* → field `embed`: add the value
|
||||
`documents`, set *Max select* to 3, save the field **and** the collection.
|
||||
3. On the `downloads` page record: set `embed` to `documents` and cut the
|
||||
hard-coded PDF list out of its body (the links pointed to files that never
|
||||
existed in the image).
|
||||
4. Upload the PDFs as `documents` records (see `redaktion.md`, *Dokumente*).
|
||||
|
||||
Uploaded files live in `pb_data/storage`, so the `pb_data` backup (#9) covers them.
|
||||
|
||||
---
|
||||
|
||||
## The compose files
|
||||
|
||||
`compose.yaml` is the **production** base; the workflow deploys it to Unraid as
|
||||
@@ -245,7 +272,8 @@ answers every **page** request with the static `wwwroot/maintenance.html`:
|
||||
| `/health` | **503** `PocketBase unreachable` (for Uptime Kuma) |
|
||||
| `/events.ics` | 200 with an empty calendar, so subscriptions keep working |
|
||||
| `/events/{id}.ics` | 503 |
|
||||
| Static files (CSS, fonts, PDFs, `/maintenance.html`) | served as usual |
|
||||
| `/dokumente/{slug}.pdf` | 503 (the file lives in PocketBase) |
|
||||
| Static files (CSS, fonts, `/maintenance.html`) | served as usual |
|
||||
|
||||
The gate caches the health check for **10 seconds** (`PocketBaseHealthCache`). So
|
||||
after PocketBase stops, pages can render for up to 10 s more (the components
|
||||
|
||||
+3
-3
@@ -108,8 +108,8 @@ and the dev overlay mounts that folder into PocketBase (`./pb/pb_migrations:/pb_
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `collections_schema.json` | The five content collections (`pages`, `posts`, `events`, `faq_topics`, `faqs`) as PocketBase exports them. **The single source of truth for the schema** — the test fixture imports this same file. |
|
||||
| `<timestamp>_dev_seed.js` | The PocketBase migration. Reads the schema file, creates any missing collection, then inserts the example records. |
|
||||
| `collections_schema.json` | The content collections (`pages`, `posts`, `events`, `faq_topics`, `faqs`, `documents`) as PocketBase exports them. **The single source of truth for the schema** — the test fixture imports this same file. |
|
||||
| `<timestamp>_dev_seed.js` | The PocketBase migration. Reads the schema file, creates any missing collection, then inserts the example records. The example `documents` get a one-page PDF generated at seed time, so the repo holds no binary files. |
|
||||
|
||||
Both steps are **idempotent**: a collection is created only if it is missing, and
|
||||
filled only while it is empty. So a populated volume — or the production DB, should
|
||||
@@ -131,7 +131,7 @@ The seed is generated from a running dev instance, not hand-edited. When you
|
||||
change a collection's schema in the admin UI, or want to capture the current
|
||||
example content as the new seed, re-export from the running dev PocketBase
|
||||
(authenticated as the dev superuser) and regenerate the two files. The schema file
|
||||
is the plain export of the four collections; the migration embeds the records the
|
||||
is the plain export of the collections; the migration embeds the records the
|
||||
same way. After regenerating, prove it end to end:
|
||||
|
||||
```bash
|
||||
|
||||
+56
-7
@@ -162,6 +162,7 @@ der passenden Collection (Button *New record*).
|
||||
| `events` | Termine (Kalender) | `/events` und der `.ics`-Feed |
|
||||
| `faq_topics` | Themen der häufigen Fragen (z. B. „Mensa und Mittagessen") | Als aufklappbare Gruppen auf `/faqs` |
|
||||
| `faqs` | Häufige Fragen | Auf `/faqs`, in der Gruppe ihres Themas |
|
||||
| `documents` | PDF-Dokumente zum Herunterladen (Formulare, Elternbriefe …) | `/dokumente/<slug>.pdf`, als Liste auf jeder Seite mit `embed = documents` (z. B. `/downloads`) |
|
||||
|
||||
Jede Collection hat als **letztes Feld `public`** (ja/nein). Nur Records mit
|
||||
`public = true` erscheinen auf der Website — so lässt sich ein Entwurf anlegen,
|
||||
@@ -176,7 +177,8 @@ Redaktion arbeitet mit **Daten**, nicht mit Struktur. Konkret:
|
||||
| Beitrag / Termin / Frage hinzufügen | **Ja** | Neuer Record in `posts` / `events` / `faqs` — erscheint sofort in der jeweiligen Liste |
|
||||
| Neues FAQ-Thema (neue Gruppe auf `/faqs`) | **Ja** | Neuer Record in `faq_topics` (siehe *Häufige Fragen*) |
|
||||
| Neue Textseite | **Ja** | Neuer Record in `pages` (siehe unten) |
|
||||
| Eine Seite mit einer Liste anteasern | **Ja** | Feld `embed` der Seite (`posts`/`events`) |
|
||||
| PDF zum Herunterladen bereitstellen oder ersetzen | **Ja** | Record in `documents` (siehe *Dokumente*) |
|
||||
| Eine Seite mit einer Liste anteasern | **Ja** | Feld `embed` der Seite (`posts`/`events`/`documents`) |
|
||||
| **Neue Art von Liste** (eigene Seite mit eigener Sortierung/Gruppierung und eigener Adresse, z. B. „Protokolle") | **Nein** | Braucht Entwicklung: neue Collection **plus** Code |
|
||||
|
||||
Das heißt: **Bestehende Listen lassen sich beliebig erweitern**, aber eine *neue*
|
||||
@@ -219,8 +221,9 @@ sofort live, ohne Code und ohne Rebuild:
|
||||
`location` (`header` oder `footer`) und `order` (Reihenfolge, ab 1). Die App
|
||||
baut Kopf- und Fußnavigation daraus; nichts wird im Markup angefasst.
|
||||
- **Eingebettete Blöcke:** Das Feld `embed` (Mehrfachauswahl aus
|
||||
`posts`/`events`) hängt unter den Text der Seite dynamische Blöcke. So ist die
|
||||
Startseite (`home`) eine normale Seite mit `embed = [posts, events]`. Leeres
|
||||
`posts`/`events`/`documents`) hängt unter den Text der Seite dynamische Blöcke.
|
||||
So ist die Startseite (`home`) eine normale Seite mit `embed = [posts, events]`,
|
||||
und die Seite `downloads` hat `embed = [documents]`. Leeres
|
||||
`embed` = reine Textseite. Die FAQ-Liste ist kein `embed`: `/faqs` ist eine
|
||||
feste Ansicht (siehe *Häufige Fragen*).
|
||||
|
||||
@@ -375,6 +378,49 @@ Eine Frage hat `question`, `answer` (Markdown), `topic`, `order` und `public`.
|
||||
|
||||
---
|
||||
|
||||
## Dokumente (`documents`)
|
||||
|
||||
Ein Dokument ist ein PDF, das du im Admin **hochlädst** — kein Entwickler, kein
|
||||
Rebuild. Es ist sofort unter einer festen Adresse erreichbar und erscheint in der
|
||||
Download-Liste.
|
||||
|
||||
Ein Dokument hat `title`, `slug`, `file`, `category` (optional), `order` und
|
||||
`public`.
|
||||
|
||||
- `title` ist der Name auf der Datei-Karte (z. B. `Aufnahmeantrag Förderverein`).
|
||||
- `slug` bestimmt die Adresse: `slug = einzugsermaechtigung` ergibt
|
||||
`/dokumente/einzugsermaechtigung.pdf`. Englisch oder deutsch, aber klein und
|
||||
**ohne Umlaute** — dieselbe Regel wie bei Seiten. Jeder Slug darf nur einmal
|
||||
vorkommen.
|
||||
- `file` ist das PDF selbst (Button *Upload new file*). Nur PDF, höchstens 20 MB.
|
||||
- `category` gruppiert die Liste: Dokumente mit derselben Kategorie (z. B.
|
||||
`Förderverein`) stehen unter einer gemeinsamen Zwischenüberschrift. Leer = ohne
|
||||
Überschrift.
|
||||
- `order` legt die Reihenfolge fest (kleinere Zahl zuerst). Die Gruppen stehen in
|
||||
der Reihenfolge ihres ersten Dokuments.
|
||||
|
||||
**Wo die Liste erscheint:** auf jeder Seite, deren `embed` den Wert `documents`
|
||||
enthält — also auf `/downloads`. Ein einzelnes Dokument kannst du außerdem in
|
||||
jedem Text verlinken; es wird dort zur Datei-Karte, wenn der Link allein in einer
|
||||
Zeile steht (siehe *Links, die sich automatisch verändern*):
|
||||
|
||||
```markdown
|
||||
[Einzugsermächtigung](/dokumente/einzugsermaechtigung.pdf)
|
||||
```
|
||||
|
||||
**Neue Fassung hochladen:** im bestehenden Record die Datei ersetzen und
|
||||
speichern. Der `slug` bleibt, also bleibt auch die Adresse — Links in Seiten,
|
||||
Briefen oder auf einem QR-Code funktionieren weiter. Deshalb einen Slug nicht
|
||||
nachträglich ändern, wenn er schon verteilt wurde.
|
||||
|
||||
> **Wichtig:** Ein hochgeladenes PDF ist **öffentlich**, sobald `public` gesetzt
|
||||
> ist. Ohne `public` ist es auch über die PocketBase-Schnittstelle nicht abrufbar
|
||||
> (die API-Regeln von `documents` lauten `public = true`, anders als bei den
|
||||
> übrigen Collections). PocketBase ist trotzdem kein Ablageort für Vorstandsinterna,
|
||||
> und PDFs mit Namen, Adressen oder Unterschriften vorher prüfen (`docs/recht.md`).
|
||||
|
||||
---
|
||||
|
||||
## Gestaltungsbausteine
|
||||
|
||||
Alle Texte (`body` von Seiten und Beiträgen, `intro` und `answer` bei den FAQs)
|
||||
@@ -490,8 +536,8 @@ Bei dringenden Angelegenheiten wenden Sie sich bitte direkt an das Sekretariat.
|
||||
- [Einzugsermächtigung](/dokumente/einzugsermaechtigung.pdf)
|
||||
```
|
||||
|
||||
Die PDF-Dateien selbst liegen nicht in PocketBase, sondern im Code unter
|
||||
`wwwroot/dokumente/` (ein neues PDF braucht also einen Entwickler).
|
||||
Die PDF-Dateien selbst lädst du in der Collection `documents` hoch (siehe
|
||||
*Dokumente*); deren Adresse ist `/dokumente/<slug>.pdf`.
|
||||
- **E-Mail-Link allein in einem Absatz** wird zum Button:
|
||||
|
||||
```markdown
|
||||
@@ -518,8 +564,11 @@ ab. Auf dem Handy lässt sich eine breite Tabelle seitlich schieben.
|
||||
|
||||
- **Nach dem Ändern einer Zugriffsregel** immer den Haupt-*Save* der Collection
|
||||
drücken, sonst greift die Änderung nicht.
|
||||
- Die fünf Collections sind öffentlich **lesbar** (List/View offen), aber nur
|
||||
- Die Inhalts-Collections sind öffentlich **lesbar** (List/View offen), aber nur
|
||||
eingeloggt **schreibbar** — ein Schreibversuch ohne Login wird abgewiesen. Das
|
||||
ist Absicht; nicht „vereinfachen".
|
||||
- **Backup:** Der gesamte Inhalt liegt in `pb_data`. Ein Backup dieses
|
||||
- Ausnahme `documents`: List/View lauten `public = true`, damit ein PDF-Entwurf
|
||||
auch über die Schnittstelle unsichtbar bleibt. Ebenfalls Absicht.
|
||||
- **Backup:** Der gesamte Inhalt liegt in `pb_data` — auch die hochgeladenen
|
||||
PDFs (unter `pb_data/storage`). Ein Backup dieses
|
||||
Verzeichnisses (plus Restore-Test) ist der Sicherungsweg — eingerichtet in #9.
|
||||
Reference in new issue
Block a user