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:
Zaldimmar 2026-09-27 15:04:45 -05:00
parent cd393e4ab2
commit eaff23839f
26 changed files with 1234 additions and 22 deletions

View file

@ -17,6 +17,16 @@
import { preview } from "./text.ts";
import { PLATFORMS } from "./platforms.ts";
import {
awardLogo,
blockMedia,
eventBackground,
eventLogo,
heroPhoto,
orgLogo,
personPhoto,
teamLogo,
} from "./media.ts";
const PLACE_FIELDS = [
{ path: "venue", label: "Venue" },
@ -228,7 +238,7 @@ const blocksChild = {
],
},
{ path: "text", label: "Text", widget: "textarea", full: true },
{ path: "media", label: "Media", help: "Filename or URL" },
{ path: "media", label: "Media", widget: "image", resolve: blockMedia, full: true },
{ path: "href", label: "Link" },
],
children: [
@ -288,7 +298,7 @@ const organizations = {
{ path: "short_name", label: "Short name" },
{ path: "tagline", label: "Tagline", full: true },
{ path: "color", label: "Colour", widget: "color" },
{ path: "logo", label: "Logo", help: "Filename in /org-logos/" },
{ path: "logo", label: "Logo", widget: "image", resolve: orgLogo, full: true },
],
},
{
@ -495,10 +505,18 @@ const events = {
{
legend: "Appearance",
fields: [
{ path: "event_logo", label: "Event logo", help: "Filename in /event-logos/" },
{ path: "org_logo", label: "Org logo override" },
{ path: "event_logo", label: "Event logo", widget: "image", resolve: eventLogo, full: true },
{ path: "org_logo", label: "Org logo override", widget: "image", resolve: orgLogo, full: true },
{ path: "color", label: "Colour", widget: "color" },
{ path: "gradient", label: "Gradient", full: true },
{
path: "card_image",
label: "Card background",
widget: "image",
resolve: eventBackground,
full: true,
help: "A photo behind the event's card, faded so the text stays readable.",
},
],
},
timelineGroup("event"),
@ -577,7 +595,7 @@ const people = {
{ path: "sort_name", label: "Sort name", help: "Doe, Jane" },
{ path: "pronouns", label: "Pronouns" },
{ path: "tagline", label: "Tagline", full: true },
{ path: "photo", label: "Photo", help: "Filename in /people/" },
{ path: "photo", label: "Photo", widget: "image", resolve: personPhoto, full: true },
{
path: "primary_org_id",
label: "Home organization",
@ -738,7 +756,7 @@ const teams = {
{ path: "name", label: "Name", required: true, help: "Board, Leadership Team" },
{ path: "tagline", label: "Tagline", full: true },
{ path: "color", label: "Colour", widget: "color" },
{ path: "logo", label: "Logo", help: "Filename in /org-logos/" },
{ path: "logo", label: "Logo", widget: "image", resolve: teamLogo, full: true },
],
},
{ legend: "Publishing", fields: PUBLISH_FIELDS },
@ -814,7 +832,7 @@ const awards = {
},
{ path: "name", label: "Name", required: true },
{ path: "description", label: "Description", widget: "textarea", full: true },
{ path: "logo", label: "Logo", help: "Filename in public/org-logos/" },
{ path: "logo", label: "Logo", widget: "image", resolve: awardLogo, full: true },
],
},
{
@ -1151,7 +1169,7 @@ const frontPage = {
title: (row) => row.caption || row.media || "New photo",
blank: { media: "", alt: "", caption: "" },
fields: [
{ path: "media", label: "Photo", required: true, help: "Filename in /front-page/, or a URL" },
{ path: "media", label: "Photo", required: true, widget: "image", resolve: heroPhoto, full: true },
{ path: "alt", label: "Description", help: "For screen readers" },
{ path: "caption", label: "Caption", full: true },
{ path: "link_url", label: "Link", help: "Optional; makes the caption a link" },

View file

@ -115,3 +115,9 @@ export function patch(path, data) {
export function del(path) {
return request(path, { method: "DELETE" });
}
/* A multipart body. No Content-Type here: the browser sets it,
boundary included, from the FormData itself. */
export function upload(path, form: FormData) {
return request(path, { method: "POST", body: form });
}

View file

@ -17,6 +17,10 @@
const ABSOLUTE = /^(https?:|\/|data:)/
/* An uploaded file ('/uploads/…'), a path anywhere on the site, or
a full URL: something to use as it is rather than resolve. */
export const isAbsoluteMedia = (file?: string | null) => Boolean(file && ABSOLUTE.test(file))
function inDir(dir: string) {
return (file?: string | null): string | null => {
if (!file) return null
@ -27,6 +31,7 @@ function inDir(dir: string) {
export const personPhoto = inDir('/people') // confirmed
export const eventLogo = inDir('/event-logos') // confirmed
export const eventBackground = inDir('/event-backgrounds')
export const orgLogo = inDir('/org-logos') // ⚠ guess
export const teamLogo = inDir('/team-logos') // ⚠ guess
export const awardLogo = inDir('/award-logos') // ⚠ guess

View file

@ -101,6 +101,8 @@ export type EventRecord = {
event_logo?: string | null
color?: string | null
gradient?: string | null
/** Behind the card. See 029_event_card_image.sql. */
card_image?: string | null
/* In billing order. The first is the one `color` and `org_logo`
fell back to when the event set neither. */
hosts: EventHost[]