Uploads (migration 028, server/src/media.js, routes/media.js): editors and up upload JPEG, PNG, GIF, WebP or SVG. Photos are resized to 2400px and saved as WebP by default, or kept as uploaded on request. Files live in UPLOADS_DIR, served by nginx in production and by the API in dev. Admins and up delete, after seeing what still uses the file. Every image field in the editor is now an image widget: preview, the path as text, Upload and Choose from library. A new Media page lists the library. Org lists and event cards now resolve logos through media.ts, so uploaded paths work there. Events get a card_image (migration 029): a photo behind the card under a light veil so the text stays readable. The card's size is unchanged. Setup for production is in docs/media-uploads.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.4 KiB
Markdown
71 lines
2.4 KiB
Markdown
# Media uploads
|
|
|
|
Images uploaded in the admin (Media page, or the Upload and Choose
|
|
from library buttons on any image field) are stored on disk and listed
|
|
in the `media` table (`server/src/migrations/028_media.sql`).
|
|
|
|
## How files are stored
|
|
|
|
- An image field stores the file's public path, `/uploads/<file>`. It
|
|
still accepts a bare filename in that field's `public/` directory or a
|
|
full URL, as before.
|
|
- By default a photo is turned upright, shrunk to fit 2400px on its
|
|
longest side, and saved as WebP. This also strips its metadata,
|
|
camera location included. Limit: 25 MB per file.
|
|
- **Keep original** stores the file exactly as uploaded (up to 10 MB),
|
|
metadata and all.
|
|
- SVGs are always kept as they are.
|
|
- Accepted types: JPEG, PNG, GIF, WebP, SVG. The type is read from the
|
|
file's contents, not its name.
|
|
- Editors and up can upload. Admins and up can delete. The Media page
|
|
shows which tables still use a file before deleting it, because
|
|
nothing stops a file a record uses from being deleted.
|
|
|
|
Limits and sizes are constants at the top of `server/src/media.js`.
|
|
|
|
## Local development
|
|
|
|
The API reads `UPLOADS_DIR` (default `./uploads`, so `server/uploads/`,
|
|
which git ignores). The API serves `/uploads/` itself, and Vite proxies
|
|
`/uploads` to the same target as `/api`.
|
|
|
|
## Production
|
|
|
|
1. Create the directory, owned by the service user:
|
|
|
|
```sh
|
|
sudo mkdir -p /var/lib/ngu/uploads
|
|
sudo chown <ngu-api user>: /var/lib/ngu/uploads
|
|
```
|
|
|
|
2. Set it in the `ngu-api` unit (`systemctl edit ngu-api`):
|
|
|
|
```ini
|
|
[Service]
|
|
Environment=UPLOADS_DIR=/var/lib/ngu/uploads
|
|
```
|
|
|
|
It lives outside `/srv/ngu-api` so an rsync deploy never deletes it.
|
|
Back it up alongside the database.
|
|
|
|
3. In the nginx site, let uploads through and serve them from disk:
|
|
|
|
```nginx
|
|
# In the server block. nginx's default is 1 MB.
|
|
client_max_body_size 26m;
|
|
|
|
location /uploads/ {
|
|
alias /var/lib/ngu/uploads/;
|
|
expires 30d;
|
|
add_header Cache-Control "public, immutable";
|
|
add_header X-Content-Type-Options nosniff;
|
|
# An uploaded SVG opened on its own can't run script.
|
|
add_header Content-Security-Policy "default-src 'none'; style-src 'unsafe-inline'; sandbox";
|
|
}
|
|
```
|
|
|
|
Filenames are random and never reused, so `immutable` is safe.
|
|
|
|
4. `sharp` is a server dependency now: run `pnpm install` in
|
|
`/srv/ngu-api` after the deploy. It ships prebuilt Linux binaries,
|
|
so no build tools are needed.
|