feat(media): primary media storage, growth goals, retention and delivery tools
CI / build (push) Has been cancelled

Event photos and videos are now stored only on the NFS/local share named in
Settings -> Media storage. Uploads, photo editing, video processing and the
per-event filing step refuse to run until that share is configured and
writable, so nothing is silently written inside the container. Video
originals, renditions, posters and sidecars share one folder on the share.

Also adds volunteer growth goals with a mentor queue, an admin retention and
storage sweep with a cron entry point, cached gallery thumbnails with
per-folder ZIP downloads, a server-rendered booth-sheet PDF, and in-app
confirm/release for every upcoming assignment.

Service reminders now ignore the one-off event reminder rule, which had been
queueing an extra bogus reminder for each published service.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-20 23:21:34 +00:00
parent cb5976edb2
commit f7a0c8618f
68 changed files with 3237 additions and 297 deletions
+24 -21
View File
@@ -50,7 +50,7 @@ Built with Next.js 15, React 19, TypeScript, PostgreSQL 16, and Drizzle ORM. It
- Database outbox with atomic claiming, a `queued → sending → sent` state machine, retry backoff (5/30/120 minutes, three attempts), and stale-send recovery.
- Per-user email preference, lead time, digest flag, and quiet hours (quiet hours only gate SMS; there is no SMS transport).
- Admin-editable reminder rules: default 7 days out, Friday before at 18:00, and a day-of rule. Timing and channel set are runtime data, not code.
- Publish-time assignment email and reminders, with signed single-use confirm/decline links that work without signing in.
- Publish-time assignment email and reminders, with signed single-use confirm/decline links that work without signing in; every upcoming assignment can also be confirmed or released in-app from the home page.
- Declines cancel that assignment's queued mail; late assignments enqueue their own mail; unpublishing cancels the week's queued mail.
- Admin outbox log with retry and test-send.
@@ -61,13 +61,15 @@ Built with Next.js 15, React 19, TypeScript, PostgreSQL 16, and Drizzle ORM. It
- Volunteers record self-comfort; mentors/admins verify the real level. Every level change appends an assessment-history row.
- Per-skill mentor opt-in and persisted admin approval; trainee shadow seats require a paired, mentor-ready volunteer.
- Skills matrix, readiness scoring, and growth-goal domain rules.
- Rich-text training lessons with headings, lists, links, inline images (align, resize, drag to reorder), and PDF/Word/text manuals up to 25 MB, plus draft/publish controls and separate admin/volunteer guides.
- Rich-text training lessons with headings, lists, links, inline images (align, resize, caption, drag to reorder), and PDF/Word/text manuals up to 25 MB, plus draft/publish controls and separate admin/volunteer guides.
- Growth goals: volunteers ask to level up a skill, coordinators assign a mentor who is actually mentor-ready, and shadows are logged until the goal is achieved (verification itself stays in the matrix).
- Retention and storage report in the admin console: what the outbox, token tables and upload volume hold, and an explicit sweep for finished mail, used tokens and orphan files.
### Events and media
- One-off events with a shot brief, location, times, photographer/editor assignments, and per-event shared folders.
- RAW and JPEG uploads streamed to disk, SHA-256 dedupe per folder, authenticated downloads, and manager-only event deletion with file cleanup.
- Photo gallery with preview, non-destructive adjustments/presets, export, and NFS archive of originals + edits + manifest.
- Photo gallery with cached grid thumbnails (RAW included), preview, non-destructive adjustments/presets, export, per-folder or whole-event ZIP download, and filing a finished event into a dated delivery folder with a manifest. Every photo and video byte lives on the configured media storage share — never in container-local storage.
- Video upload with FFmpeg probe/transcode to web H.264/AAC, generated poster, non-destructive trim re-render, and retry after a failed encode.
- Media visibility: team-only, unlisted link, or public. Ready public videos get `/watch/<id>`, a minimal `/embed/<id>` iframe, and an oEmbed endpoint.
- Announcements feed with draft/publish/delete for coordinators and admins.
@@ -75,8 +77,8 @@ Built with Next.js 15, React 19, TypeScript, PostgreSQL 16, and Drizzle ORM. It
### Calendars, exports, and admin
- Personal ICS calendar feed with a rotatable token.
- Schedule and service-history CSV exports; browser print-to-PDF for rosters and run sheets.
- Admin console: people, skill matrix, positions and requirements, service templates, reminder rules, email delivery, notification log, archive storage, and backup/restore.
- Schedule and service-history CSV exports; a server-rendered PDF booth sheet for any service; browser print-to-PDF for rosters.
- Admin console: people, skill matrix, positions and requirements, service templates, reminder rules, email delivery, notification log, media storage, and backup/restore.
- Runtime settings stored in Postgres, including encrypted Gmail credentials, so mail identity and storage paths change without a deploy.
## Stack
@@ -171,12 +173,12 @@ Copy `.env.example` to `.env`; never commit real secrets (`.env*` is ignored, `.
| `CRON_SECRET` | Bearer/query secret for the cron HTTP routes. Empty means session-only. |
| `POSTMARK_SERVER_TOKEN`, `POSTMARK_FROM` | Optional Postmark fallback and default sender. Admin email settings take precedence. |
| `OUTBOX_DIR` | Console email transport directory (`/tmp/outbox` in compose). |
| `UPLOAD_DIR` | Training attachments and event photo/video bytes (`/tmp/uploads` in compose). |
| `ARCHIVE_DIR`, `NFS_SHARE`, `ARCHIVE_FOLDER` | Archive mount path inside the container, the reported NFS share, and the default archive subfolder. |
| `UPLOAD_DIR` | Training attachments only (`/tmp/uploads` in compose). Event photos and videos never live here. |
| `ARCHIVE_DIR`, `NFS_SHARE`, `ARCHIVE_FOLDER` | Mount path inside the container, the reported share, and the default folder. This is the primary storage for original event photos and videos; a named share plus a writable path is required or uploads and photo editing stay disabled. |
| `MEDIA_ARCHIVE_DIR` | **Compose-only host path** mounted at `/archive` for the NFS export. |
| `SENTRY_DSN` | Declared but not wired to any integration. |
Volumes in Compose: `pgdata`, `outbox-data`, `uploads-data`, and either `archive-data` or the host `MEDIA_ARCHIVE_DIR` bind mount. Back these up together.
Volumes in Compose: `pgdata`, `outbox-data`, `uploads-data`, and either `archive-data` or the host `MEDIA_ARCHIVE_DIR` bind mount (the latter is what holds original photos and videos). Back these up together.
## Email delivery
@@ -206,8 +208,8 @@ Set `CRON_SECRET` before enabling the timer; without it the routes only accept a
Admin → Backup & restore downloads one ZIP containing:
- `dump.sql` — schema, data, constraints, indexes, and the migration ledger;
- `uploads/` — training attachments, event photos, and video derivatives;
- `archive/` — the NFS/archive mount, including untouched camera originals and finished photo archives;
- `uploads/` — training attachments;
- `archive/` — the media storage mount: original event photos, video originals/derivatives, and dated delivery folders;
- `manifest.json` — timestamp, app version, SHA-256 checksum, and included areas.
The manifest excludes `.env` and the console outbox. **Store `NEXTAUTH_SECRET` with the backup** — it decrypts the stored Gmail app password.
@@ -259,7 +261,7 @@ This is the full path for a fresh Ubuntu 22.04/24.04 host using Docker. The resu
- 2 vCPU and 2 GB RAM minimum (4 GB for heavy video processing), 20 GB free disk plus space for media.
- A DNS `A` record (and `AAAA` if using IPv6) for the hostname, pointing at the server.
- Inbound TCP 22, 80, and 443 allowed. Do **not** expose 3000 or 5433.
- Optional: an NFS export for the media archive.
- An NFS export or host directory for original photo/video storage (required for event media).
### 1. Install Docker Engine and Compose
@@ -453,9 +455,11 @@ Schedule it in root's crontab (`sudo crontab -e`):
The daily job runs instances → slots → complete in that order. Run the script manually once and check its exit status after changing `.env`.
### 9. Media archive on NFS (optional)
### 9. Media storage on NFS or a local path (required for event media)
Without NFS the app uses the `archive-data` Docker volume, which is included in the admin backup. To store originals and photo archives on a NAS:
Original event photos and videos are stored **only** on the configured media storage share — it is their primary home, not a backup. Without a named share and a writable mounted path, the uploader and the photo editor are disabled with a warning; the app never falls back to storing media inside the container or on the `archive-data` volume. Photos live in `<share>/<folder>/events/<eventId>/`, and each video keeps its original, renditions, poster and sidecar together in `<share>/<folder>/videos/<eventId>/<videoId>/`.
A bind-mounted host directory works too — set `MEDIA_ARCHIVE_DIR` to any local path and name it in Settings. To store media on a NAS:
```bash
sudo apt-get install -y nfs-common
@@ -480,7 +484,7 @@ docker compose up -d app
docker compose exec app sh -c 'test -w /archive && echo "archive writable"'
```
Adjust NFS export ownership or ID mapping so UID 100 can write. Set the archive subfolder in Settings → Media archive (NFS).
Adjust NFS export ownership or ID mapping so UID 100 can write. Then, in Settings → Media storage, enter the share name (for example `nas.example.org:/export`) and the storage subfolder, and save. Uploads unlock only after that check succeeds.
### 10. Email delivery
@@ -530,8 +534,8 @@ git switch main
| `password authentication failed` | `POSTGRES_PASSWORD` changed after the volume was initialized. Use the original role password or rotate it with SQL. Changing the env alone does not update Postgres. |
| Secure-cookie/login loop | `NEXTAUTH_URL` and `PUBLIC_ORIGIN` must exactly match the HTTPS origin in the browser. |
| Wrong links in email | Set `PUBLIC_ORIGIN`; otherwise links derive from the request Host header. |
| Video upload/encode fails | Free disk space, `UPLOAD_DIR` writability, and `docker compose logs app` for FFmpeg errors. |
| Archive unavailable | NFS mount exists on the host, `MEDIA_ARCHIVE_DIR` is set, and UID 100 can write to `/archive`. |
| Video upload/encode fails | Free disk space on the media storage share and `docker compose logs app` for FFmpeg errors. |
| Uploads/editing are disabled | Settings → Media storage needs a share name and a mounted path that UID 100 can write to; the banner states the exact failure. |
| Cron returns 401 | `CRON_SECRET` is set in `.env` and matches the value read by `/usr/local/bin/media-hub-cron`. |
| Disk filling up | Docker log rotation is capped at 10 MB × 3 per service; remove old backups, exports, and unused media. |
@@ -546,7 +550,7 @@ git switch main
- [ ] Gmail/Postmark configured and a test email received.
- [ ] Cron jobs installed and returning success.
- [ ] Backup downloaded, stored off-host, and restore tested once.
- [ ] NFS archive writable (if used).
- [ ] Media storage share configured in Settings → Media storage and writable (required for event photos and videos).
- [ ] The `/api/dev/*` prefix is historical: the guards, not the URL, are the security boundary.
## Project structure
@@ -605,10 +609,9 @@ The planning documents describe the original long-range product and still mentio
## Known gaps
- **SMS is not implemented.** SMS delivery was removed; queued SMS rows are suppressed. Default reminder rules may include an SMS channel, but only email is sent.
- Rich-text editing (TipTap) is not built; lesson and announcement bodies are plain text.
- Exports are CSV plus browser print-to-PDF. There is no server-generated PDF/XLSX export or volunteer swap-request workflow beyond the coverage board.
- Growth goals have a data model and rules but no UI.
- Announcement bodies are still plain text; training lessons use the rich-text editor.
- Run sheets have a server-generated PDF booth sheet; rosters and history export as CSV, and the schedule/run-sheet pages still print from the browser. There is no XLSX export.
- Event seats/reminders are separate from the recurring-service slot pipeline.
- Reminder templates live in code; timing, channel set, sender identity, and storage paths are runtime settings.
- No built-in cron runner, delivery webhooks/bounce handling, observability integration, or retention job for notification/token rows.
- No built-in cron runner, delivery webhooks/bounce handling, or observability integration. Retention is implemented (`/api/dev/cron/retention`) but still needs a scheduler entry.
- `PUBLIC_ORIGIN` must be set in production, otherwise emailed links are derived from the request host.