From 14a22ca44da4b15c49592c03b87697fa76fc095f Mon Sep 17 00:00:00 2001 From: Aidan Dona Date: Thu, 8 Oct 2026 12:10:44 -0500 Subject: [PATCH] Video stills: Frame at on video blocks and the front page's video, and Tools > Video thumbnails (migration 074) Frame at (a still from a YouTube or Facebook video at a typed time) now also fills a video block's still and the front page's new Video still, which the hero shows before its featured video plays. Tools > Video thumbnails takes one from any link, to download or copy into a field. All go through the existing POST /api/admin/video-frame. Co-Authored-By: Claude Opus 5.5 --- docs/video-clips.md | 17 +- server/src/admin-schema/frontPage.js | 1 + .../migrations/074_front_page_video_still.sql | 11 ++ server/src/routes/home.js | 2 +- src/App.tsx | 4 + src/components/admin/MediaLibrary.tsx | 5 +- src/lib/adminSchema/frontPage.ts | 10 + src/lib/adminSchema/shared.ts | 6 +- src/lib/useFrontPage.ts | 3 +- src/pages/admin/AdminVideoFrames.tsx | 171 ++++++++++++++++++ src/pages/admin/adminNav.ts | 6 + src/pages/sections/home/HeroStage.tsx | 17 +- 12 files changed, 240 insertions(+), 13 deletions(-) create mode 100644 server/src/migrations/074_front_page_video_still.sql create mode 100644 src/pages/admin/AdminVideoFrames.tsx diff --git a/docs/video-clips.md b/docs/video-clips.md index c83f006..6cf588f 100644 --- a/docs/video-clips.md +++ b/docs/video-clips.md @@ -14,11 +14,18 @@ it: **Save to library** and **Save to Drive** on the download itself. It stays on the server to cut clips from either way (until the day's sweep). -The same tools take stills: a video featured card's Image field has -**Frame at** (editors and up), which saves the frame at a typed time to -`/uploads/thumbnails/` (`grabFrame` in `server/src/clips.js`). It -downloads only that frame, outside the queue. A link's own `t=` (eg. -`?t=83`) fills in the time. +The same tools take stills (editors and up), each saving the frame at +a typed time to `/uploads/thumbnails/` (`grabFrame` in +`server/src/clips.js`, `POST /api/admin/video-frame`). It downloads only +that frame, outside the queue. A link's own `t=` (eg. `?t=83`) fills in +the time. **Frame at** is on: + +- a video featured card's Image field (the front page, a region) +- a video content block's Image field (its still) +- the front page's Video still (the hero's featured video, migration 074) + +and **Tools → Video thumbnails** (`AdminVideoFrames.tsx`) takes one from +any link, to download or copy its path into a field. Clips queue and run one at a time. A finished clip is deleted from the server once it's downloaded, unless **Save to library** is pressed first, diff --git a/server/src/admin-schema/frontPage.js b/server/src/admin-schema/frontPage.js index 0edc04d..bc2be0b 100644 --- a/server/src/admin-schema/frontPage.js +++ b/server/src/admin-schema/frontPage.js @@ -49,6 +49,7 @@ export const frontPage = { text("countdown_scope_id"), enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]), int("featured_columns"), + text("video_still"), ], children: [ diff --git a/server/src/migrations/074_front_page_video_still.sql b/server/src/migrations/074_front_page_video_still.sql new file mode 100644 index 0000000..fb914c9 --- /dev/null +++ b/server/src/migrations/074_front_page_video_still.sql @@ -0,0 +1,11 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 074 FRONT PAGE VIDEO STILL +-- +-- The hero's featured video gets a still of its own: the picture +-- shown before it plays (a /uploads/ path, a bare filename or a +-- URL, like every image field). Null keeps YouTube's thumbnail, or +-- for a video file, its first frame. The editor's Frame at fills it +-- from the video at a typed time. +-- ═══════════════════════════════════════════════════════════════ + +ALTER TABLE front_page ADD COLUMN video_still TEXT; diff --git a/server/src/routes/home.js b/server/src/routes/home.js index 2b67d19..1c5b1c5 100644 --- a/server/src/routes/home.js +++ b/server/src/routes/home.js @@ -225,7 +225,7 @@ home.get("/front-page", (c) => { ? { url: page.livestream_url, title: page.livestream_title } : null, video: page.video_url - ? { url: page.video_url, title: page.video_title, captions: page.video_captions } + ? { url: page.video_url, title: page.video_title, captions: page.video_captions, still: page.video_still } : null, event: shapeHeroEvent(db, heroEvent), }, diff --git a/src/App.tsx b/src/App.tsx index 5f3fc56..2f66b03 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -80,6 +80,7 @@ const AdminHome = lazyPage(() => import("./pages/admin/AdminHome.tsx")) const AdminFeedback = lazyPage(() => import("./pages/admin/AdminFeedback.tsx")) const AdminMedia = lazyPage(() => import("./pages/admin/AdminMedia.tsx")) const AdminClips = lazyPage(() => import("./pages/admin/AdminClips.tsx")) +const AdminVideoFrames = lazyPage(() => import("./pages/admin/AdminVideoFrames.tsx")) const AdminNewsletter = lazyPage(() => import("./pages/admin/AdminNewsletter.tsx")) const EntityList = lazyPage(() => import("./pages/admin/EntityList.tsx")) const EntityEdit = lazyPage(() => import("./pages/admin/EntityEdit.tsx")) @@ -145,6 +146,9 @@ export default function App() { } /> } /> } /> + }> + } /> + }> } /> diff --git a/src/components/admin/MediaLibrary.tsx b/src/components/admin/MediaLibrary.tsx index 4cac05d..73f9304 100644 --- a/src/components/admin/MediaLibrary.tsx +++ b/src/components/admin/MediaLibrary.tsx @@ -647,8 +647,9 @@ export function ImageInput({ /* ── Frame from a video ──────────────────────────────────────── */ /* A link's own start time (YouTube's t=83 or t=83s), so a link - copied at the moment wanted starts the picker there. */ -function startOf(url: string): number { + copied at the moment wanted starts the picker there. Tools → + Video thumbnails (AdminVideoFrames.tsx) reads it too. */ +export function startOf(url: string): number { try { const t = new URL(url).searchParams.get("t") ?? ""; return /^\d+s?$/.test(t) ? parseInt(t, 10) : 0; diff --git a/src/lib/adminSchema/frontPage.ts b/src/lib/adminSchema/frontPage.ts index 58e76f2..cfaf6e4 100644 --- a/src/lib/adminSchema/frontPage.ts +++ b/src/lib/adminSchema/frontPage.ts @@ -107,6 +107,16 @@ export const frontPage = { "A YouTube, Vimeo or Facebook link, or a video file: a filename in " + "the uploads folder, or a link ending in .mp4 or .webm", }, + { + path: "video_still", + label: "Video still", + widget: "image", + crop: 16 / 9, + resolve: mediaUrl, + full: true, + frameFrom: "video_url", + help: "Shown before it plays. Default: YouTube's own thumbnail, or a video file's first frame. Frame at takes a still from a YouTube or Facebook video.", + }, { path: "video_captions", label: "Video captions", diff --git a/src/lib/adminSchema/shared.ts b/src/lib/adminSchema/shared.ts index 1b2f8d4..8d66e1d 100644 --- a/src/lib/adminSchema/shared.ts +++ b/src/lib/adminSchema/shared.ts @@ -408,8 +408,12 @@ export const blocksChild = { resolve: mediaUrl, full: true, when: { path: "type", value: ["image", "video"] }, + frameFrom: "href", + frameWhen: { path: "type", value: "video" }, help: (row) => - row?.type === "video" ? "Still shown before it plays. Default: YouTube's own thumbnail." : undefined, + row?.type === "video" + ? "Still shown before it plays. Default: YouTube's own thumbnail. Frame at takes a still from a YouTube or Facebook video." + : undefined, }, { path: "captions", diff --git a/src/lib/useFrontPage.ts b/src/lib/useFrontPage.ts index 065d2e0..767336b 100644 --- a/src/lib/useFrontPage.ts +++ b/src/lib/useFrontPage.ts @@ -51,7 +51,8 @@ export type Hero = { slides: HeroSlide[] livestream: { url: string; title?: string | null } | null /** A link to embed or a video file; see videoSource in embeds.ts. */ - video: { url: string; title?: string | null; captions?: string | null } | null + /** `still` is shown before it plays; resolve it with mediaUrl. */ + video: { url: string; title?: string | null; captions?: string | null; still?: string | null } | null /** With the 'event' feature: the pinned event, else the countdown's. */ event: HeroEvent | null } diff --git a/src/pages/admin/AdminVideoFrames.tsx b/src/pages/admin/AdminVideoFrames.tsx new file mode 100644 index 0000000..b0ff2f9 --- /dev/null +++ b/src/pages/admin/AdminVideoFrames.tsx @@ -0,0 +1,171 @@ +/* ═══════════════════════════════════════════════════════════════ + ADMIN: VIDEO THUMBNAILS (Tools → Video thumbnails, editors and up) + + Paste a YouTube or Facebook link and a time, and the server takes + that one frame (grabFrame in server/src/clips.js, the same as an + image field's Frame at) and saves it to the media library's + Previews folder (thumbnails/). A link's own t= fills in the time. + + Frames taken here are listed until the page is left, each with a + full-size link, a download and its path to copy into a field. + They stay in the library (Tools → Media) after that. + ═══════════════════════════════════════════════════════════════ */ + +import { useId, useState, type FormEvent } from "react"; +import { Link } from "react-router-dom"; + +import { ApiError, post } from "../../lib/api.ts"; +import { clock, parseClock } from "../../lib/clock.ts"; +import { startOf, type MediaItem } from "../../components/admin/MediaLibrary.tsx"; + +const MUTED = "var(--color-muted)"; + +const button = + "btn border border-brand px-4 py-2 text-sm text-link transition-colors hover:bg-tint disabled:cursor-default disabled:opacity-50"; +const primary = + "btn bg-action px-5 py-2.5 text-white transition-colors hover:bg-action-hover disabled:bg-muted/25"; +const input = + "border border-muted/25 bg-surface px-3 py-2 text-sm text-body outline-none focus:border-brand focus:ring-2 focus:ring-brand/25"; + +type Taken = { media: MediaItem; url: string; seconds: number }; + +function Frame({ frame }: { frame: Taken }) { + const [copied, setCopied] = useState(false); + + async function copy() { + try { + await navigator.clipboard.writeText(frame.media.url); + setCopied(true); + setTimeout(() => setCopied(false), 1500); + } catch { + setCopied(false); + } + } + + return ( +
  • + + + +
    +
    +

    At {clock(frame.seconds)}

    +

    + {frame.url} +

    + {frame.media.width && frame.media.height && ( +

    + {frame.media.width} × {frame.media.height} +

    + )} +
    +
    + + Download + + +
    +
    +
  • + ); +} + +export default function AdminVideoFrames() { + const [url, setUrl] = useState(""); + const [time, setTime] = useState("0:00"); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(null); + const [frames, setFrames] = useState([]); + const urlId = useId(); + const timeId = useId(); + + const seconds = parseClock(time); + + // A pasted link that carries its own time (t=83) sets the box. + function changeUrl(next: string) { + setUrl(next); + const start = startOf(next.trim()); + if (start > 0) setTime(clock(start)); + } + + async function take(e: FormEvent) { + e.preventDefault(); + if (seconds == null) return; + setBusy(true); + setError(null); + try { + const link = url.trim(); + const { media } = await post("/admin/video-frame", { url: link, seconds }); + setFrames((list) => [{ media, url: link, seconds }, ...list]); + } catch (err) { + setError(err instanceof ApiError ? err.message : "Couldn't take that frame."); + } finally { + setBusy(false); + } + } + + return ( +
    +
    +

    Video thumbnails

    +

    + Take a still from one of our YouTube or Facebook videos at any moment. +

    +
    + +
    +
    +
    + + changeUrl(e.target.value)} + placeholder="eg. https://www.youtube.com/watch?v=…" + className={`mt-1 w-full ${input}`} + /> +
    +
    + + setTime(e.target.value)} + placeholder="eg. 1:23" + className={`mt-1 w-full ${input}`} + /> +
    + +
    +

    + YouTube and Facebook links only, and only videos NGU owns or has permission to use. A link copied with + its time (eg. Share → Start at) fills in the time. Frames are saved to{" "} + + Media + {" "} + → Previews. +

    + {seconds == null &&

    Write the time as seconds or m:ss, eg. 83 or 1:23.

    } + {error &&

    {error}

    } +
    + + {frames.length > 0 && ( +
      + {frames.map((frame) => ( + + ))} +
    + )} +
    + ); +} diff --git a/src/pages/admin/adminNav.ts b/src/pages/admin/adminNav.ts index 8a48db7..8b614b4 100644 --- a/src/pages/admin/adminNav.ts +++ b/src/pages/admin/adminNav.ts @@ -190,6 +190,12 @@ export const TOOLS_NAV = { blurb: "Cut clips from our YouTube and Facebook videos: trimmed, reshaped for Reels, or audio only.", minRole: "admin", }, + { + to: "/admin/thumbnails", + label: "Video thumbnails", + blurb: "A still from one of our YouTube or Facebook videos at any moment, saved to the media library.", + minRole: "editor", + }, { to: "/admin/newsletter", label: "Newsletter", diff --git a/src/pages/sections/home/HeroStage.tsx b/src/pages/sections/home/HeroStage.tsx index eed30e1..45f58d5 100644 --- a/src/pages/sections/home/HeroStage.tsx +++ b/src/pages/sections/home/HeroStage.tsx @@ -113,7 +113,13 @@ export default function HeroStage({ hero }: { hero: Hero | null }) { {feature === 'video' && hero?.video && (
    - +
    )} @@ -493,18 +499,22 @@ function LiveFrame({ src, url, title }: { src: string | null; url: string; title "metadata" fetches enough for the first frame and the length, not the whole file. An embed is a VideoPlayer: a still until pressed, so the video's host sets nothing before then. A link - that is neither still gets a button out to it. */ + that is neither still gets a button out to it. `still` is the + editor's chosen picture (074): the embed's still, or the file's + poster; without one, YouTube's thumbnail or the first frame. */ function VideoFrame({ source, url, title, captions, + still, }: { source: VideoSource | null url: string title?: string | null /** A WebVTT file's URL; only a file plays it, an embed has its own. */ captions?: string | null + still?: string | null }) { return (
    {captions && } ) : source?.kind === 'embed' ? ( - + ) : (