Add image uploads with a media library, and event card backgrounds
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>
This commit is contained in:
parent
cd393e4ab2
commit
eaff23839f
26 changed files with 1234 additions and 22 deletions
41
server/src/migrations/028_media.sql
Normal file
41
server/src/migrations/028_media.sql
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 028 MEDIA: UPLOADED IMAGES
|
||||
--
|
||||
-- One row per file in UPLOADS_DIR (/var/lib/ngu/uploads in
|
||||
-- production, outside the deployed app so an rsync can't touch
|
||||
-- it). nginx serves the directory at /uploads/; the API only
|
||||
-- writes and deletes.
|
||||
--
|
||||
-- An image field stores the file's public path, '/uploads/<file>',
|
||||
-- not this row's id. That keeps every image column a plain TEXT
|
||||
-- that also takes a filename in public/ or a full URL, as before,
|
||||
-- and means media.ts needs no lookup. The cost is no foreign key:
|
||||
-- deleting a file a record still names leaves that record showing
|
||||
-- nothing (the <Logo> and <img> fallbacks already handle a missing
|
||||
-- file), so the Media page warns before a delete.
|
||||
--
|
||||
-- filename the stored name: random, so it can't collide or
|
||||
-- be guessed from the original. '3f9c…e1.webp'
|
||||
-- original_name what the uploader's file was called, for the
|
||||
-- library's search and display
|
||||
-- processed 1 when resized and converted to WebP, 0 when
|
||||
-- kept as uploaded
|
||||
-- width, height null for an SVG, which has no pixel size
|
||||
--
|
||||
-- PRAGMA user_version; -- reads 27 before this file
|
||||
-- ═══════════════════════════════════════════════════════════════
|
||||
|
||||
CREATE TABLE media (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
filename TEXT NOT NULL UNIQUE,
|
||||
original_name TEXT NOT NULL,
|
||||
content_type TEXT NOT NULL,
|
||||
bytes INTEGER NOT NULL CHECK (bytes >= 0),
|
||||
width INTEGER,
|
||||
height INTEGER,
|
||||
processed INTEGER NOT NULL DEFAULT 1 CHECK (processed IN (0, 1)),
|
||||
uploaded_by INTEGER REFERENCES admin_users (id) ON DELETE SET NULL,
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
) STRICT;
|
||||
|
||||
CREATE INDEX media_created_idx ON media (created_at DESC);
|
||||
Loading…
Add table
Add a link
Reference in a new issue