Finish the audit leftovers

- One mediaUrl in media.ts instead of 12 identical aliases and a
  kind map; orgPath builds on hrefs.ts's orgHref
- One Logo component (hides itself or shows a fallback when the file
  is missing) for event cards, org lists and chapter marks
- useHistory is a thin wrapper over useRecord
- adminSchema.ts split into adminSchema/, one file per entity plus
  shared.ts; the registry is unchanged (checked by loading both)
- JS smooth scrolls respect reduced motion (lib/motion.ts)
- Content-Security-Policy in Report-Only, with /api/csp-report logging
  what it would block

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 22:49:07 -05:00
parent c74ad746f5
commit e4a9c96f7e
42 changed files with 1968 additions and 2043 deletions

View file

@ -24,72 +24,17 @@
const ABSOLUTE = /^(https?:|\/|data:)/
function inDir(dir: string) {
return (file?: string | null): string | null => {
if (!file) return null
if (ABSOLUTE.test(file)) return file
return `${dir}/${file}`
}
}
const UPLOADS = '/uploads'
export const UPLOADS = '/uploads'
const inUploads = inDir(UPLOADS)
/* One helper per field, all the same rule, so a caller says what the
image is and a future exception is one line here. */
export const personPhoto = inUploads
export const eventLogo = inUploads
export const eventBackground = inUploads
export const orgLogo = inUploads
export const teamLogo = inUploads
export const awardLogo = inUploads
/* front_page_slides.media, the hero's photos. */
export const heroPhoto = inUploads
/* front_page.video_url when it names a file rather than a link.
Videos can't be uploaded through the media library, so a file is
one copied into the uploads directory by hand. */
export const heroVideo = inUploads
/* content_blocks.media and content_block_items.media. */
export const blockMedia = inUploads
/* featured_cards.image. */
export const featuredImage = inUploads
/* blog_posts.cover_image and guest_photo. */
export const blogImage = inUploads
/* ── By record kind ────────────────────────────────────────────
The timeline sends `logo: { file, kind }` rather than a path,
because v_timeline COALESCEs across five tables and only the
ref_kind says which one the filename came from. Featured cards
send the same shape. Every kind resolves to the uploads directory
today; the map is what lets one kind differ later.
───────────────────────────────────────────────────────────── */
const BY_KIND: Record<string, (file?: string | null) => string | null> = {
event: eventLogo,
organization: orgLogo,
team: teamLogo,
award: awardLogo,
person: personPhoto,
// Featured cards (loadFeaturedCards in shape.js) add two of their own.
'event-background': eventBackground,
featured: featuredImage,
}
export function logoForKind(
kind?: string | null,
file?: string | null,
): string | null {
/* Any record image or media field (photos, logos, backgrounds, hero
slides and video files, block and card images, blog covers), and
the timeline's and featured cards' `{ file, kind }` logos by their
file. One rule for all of them; if a kind ever needs its own
directory, that's the time to add a parameter. */
export function mediaUrl(file?: string | null): string | null {
if (!file) return null
// An unrecognised kind still renders: a filename with no home
// directory is a bug, but a broken <img> says so louder than a
// silently absent one.
return (BY_KIND[kind ?? ''] ?? blockMedia)(file)
if (ABSOLUTE.test(file)) return file
return `${UPLOADS}/${file}`
}
/* Initials for a photo that is missing or fails to load. Same