The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Preset covers: fixes from the review of cover versions
Adarshee1a51082eae
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex cfe37e7d..8f4b63b2 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -526,7 +526,7 @@ Liner-inspired shell (pale frame, rounded inset sheet, 13px sidebar rows, serif- **Hubs** (Audio, Video tools, Upscale) have one prerendered path per mode (`src/lib/hubs.ts`, `ModeSwitchStudio` in `mode-switch-studio.tsx`, `[mode]/page.tsx`); old `?mode=` links redirect in `next.config.ts`, and an unknown mode is a real 404. Round 4 adds `/upscale/fps`, `/upscale/hdr`, `/upscale/export`, `/audio/transcribe`, `/audio/loop`, `/audio/join` and `/video-tools/remove-object`; round 5 part 1 adds `/video-tools/evolution`, and round 5 part 2 `/audio/split` (`SplitSoundtrackTool` in `TOOLS`).- **Composer** pieces: pure logic in `src/lib/composer.ts` (summary, blockers, `onImageChange`, `fitAttachments`, `firstMissingSlot`; since round 4 `blockerLine` for the phone's blocked-Generate line, `framesRequest` and the Frames strip helpers, the start token), `attachments.ts` (`useAttach`, `useUploadReaper`), `settings-panel.tsx`, `model-picker.tsx` (cmdk), `attach-menu.tsx`, `preset-chips.tsx` (lazy), `radio-keys.ts`, `frames-strip.tsx`, and since round 4 part 3 `look-chip.tsx` (lazy: Fuobe Soul's looks, a popover on desktop and a sheet on phones). Since round 4 part 3 the composer sends `engine` for a Fuobe Original, drops a look when the model changes to one without looks, moves to a motion's or effect's Original when one is picked, and follows a move across an engine switch (the pure helpers are in `src/lib/composer.ts`: see Fuobe Originals). Video finishing reads the attached clip's facts from `POST /api/media/probe` for its "24 → 60 fps · 5 s → 10 s" line and its prices. Since round 5 part 1 Edit video does too (`clipFacts`, fixes-5): a clip edit that keeps the clip's length is priced on its seconds, and `clipBlocker` blocks Generate with the reason when the clip is outside the model's window (`clip-windows.ts`; the server refuses the same for an API call that sends no length, after the clip is uploaded to the provider's storage, nothing billed). Lipsync reads the voice's length (`StudioConfig.voiceFacts`) to price talking avatars, and the Image studio prices a look's step after the picture (`postStepCost`, with the face mosaic's models in `extraModels`). The Look chip has a "No look" state (`none`, Storyboard). Since round 5 part 2 a price is read on the browser's day (`useToday` in `src/hooks/use-today.ts`: null on the server and while the page hydrates, so a launch-priced model shows no price until then, and it changes at UTC midnight): the composer's estimate, the model picker (`pickerPrice`) and the Models page (`rowPrice` with `ModelRow.launch`; `GET /api/models` answers the day's `price` and keeps `launch`). The slim studio catalog carries `Pricing.promo` as it is. A run with LoRAs on an endpoint with no published price shows "Price unknown", never free, in the composer and on Canvas nodes. The Image studio's controls chip reads "Options" (`StudioConfig.controlsTitle`), where MOSS-Image's Quality sits.- **Feed and results**: running tiles show elapsed time and, once progress has moved, time left (`use-now.ts`; `notePace` / `timeLeft` in `src/lib/format.ts`); the newest single result offers next steps (`nextSteps` in `output-actions.ts`); video tiles get a poster (`videoPoster`); ProRes, FFV1 and clips the browser can't decode show as a file card (`VideoFileCard` in `result-media.tsx`). Since round 4 part 2, `useCreateGeneration` (`src/lib/api.ts`) shows a run's `notes` (LoRAs left out, a length the API rounds) as a warning toast. Since round 4 part 3 every studio feed finishes Fuobe Soul pictures (`useSoulFinish`), the viewer's Details show a Look row and a Finish row, and a clip with `meta.grade` offers "Apply the … grade" first.-- **Galleries** get slim cards (`src/lib/preset-cards.ts`) with procedural previews (`preset-preview.tsx`, `move-glyphs.ts`); `previewFor` (`src/lib/preset-card-data.ts`) shows a real cover instead when `src/lib/preset-previews.generated.ts` lists one: a still cover is the card's picture as rendered (no tint, bleed, mirroring or move glyph), a clip cover is its first-frame poster with a muted `<video>` over it only while it plays (invisible until its first frame is ready, released when it stops). Every entry records the run, engine, model and variant that made it. `preset-card-data.ts` is the only module that reads the manifest, and only the server gallery pages and the preset header (loaded on its own with `next/dynamic`) import it, so the manifest never ships in the shared client chunks (`tests/preset-covers.test.ts` checks the importers, and checks the real manifest against `public/previews`). Every cover URL the site gives ends in its file's content version (`?v=` and 8 hex digits of its sha256; a poster's also covers its 320 px copy in `thumbs/`, whose URL keeps it), written into the manifests by `eval:covers` and `gen-preset-peaks.mjs` (`--versions` on either hashes the files as they are, without encoding), so a cover made again under its old name gets a new URL. Versioned covers are served for a year as `immutable`; one asked for without its version keeps a day's cache and a week of background revalidation (`next.config.ts`). Both stay outside the sign-in proxy like `samples/`. The file is written by the evaluation harness's `eval:covers`, from a measured run's promoted renders or, with `--from-masters <dir>`, from rendered masters kept outside the repo (`coversFromMasters()` in `scripts/eval/lib/covers.mjs`; it replaces only the ids it writes, and skips an id whose cover another run made elsewhere unless `--replace`). Stills are 4:2:0 JPEGs of at most 768 px; a clip cover is at most 4 s and 512 px, and its last 6 frames are crossfaded into its first ones so the card's loop has no jump (a clip that already ends where it starts is only cut). The first covers came that way: 480 of the 487 app, motion and effect cards (474 stills from Ideogram 4 and 6 clips from MiniMax H3, all rendered in ComfyUI; run `comfyui-previews-2026-10`, in `public/previews/presets/`), while the other 7 keep their procedural preview. Main's later cover work gave 43 apps a before/after reveal clip (Ideogram 4, then Qwen-Image 2.1 Edit), so 48 of the 480 now have a clip (the other 5 from MiniMax H3) and 432 are stills. `preview-playback.ts` decides which play: a clip card plays by itself while it's mostly in view, once scrolling stops, at most 6 at once (3 on a phone), the cards in full view and nearest the middle of the screen first; a procedural preview does so only where nothing can hover (phones), and the preset header plays whatever moves. Nothing plays by itself with reduced motion (turned on while the page is open, it stops at once), Save-Data, on 2G or in a hidden tab; a hover (after a short rest), keyboard focus, or a tap on the preset header still plays one (with reduced motion, only a clip).+- **Galleries** get slim cards (`src/lib/preset-cards.ts`) with procedural previews (`preset-preview.tsx`, `move-glyphs.ts`); `previewFor` (`src/lib/preset-card-data.ts`) shows a real cover instead when `src/lib/preset-previews.generated.ts` lists one: a still cover is the card's picture as rendered (no tint, bleed, mirroring or move glyph), a clip cover is its first-frame poster with a muted `<video>` over it only while it plays (invisible until its first frame is ready, released when it stops). Every entry records the run, engine, model and variant that made it. `preset-card-data.ts` is the only module that reads the manifest, and only the server gallery pages and Home's server-only showcase import it, so the manifest never ships in client code: the preset header builds the same preview from the slim covers map (`coverPreview` in `src/lib/preset-covers.ts`) (`tests/preset-covers.test.ts` checks the importers, and checks the real manifest against `public/previews`). Every cover URL the site gives ends in its file's content version (`?v=` and 8 hex digits of its sha256; a poster's also covers its 320 px copy in `thumbs/`, whose URL keeps it), written into the manifests by `eval:covers` and `gen-preset-peaks.mjs` (`--versions` on either hashes the files as they are; the covers' one first makes a poster's 320 px copy that's missing or older than its poster, and encodes nothing else), so a cover made again under its old name gets a new URL. Versioned covers are served as `immutable`, for a year in the browser and a day in the CDN (`s-maxage`, so a revert or rollback that gives an old version back never finds the wrong file pinned there); one asked for without its version keeps a day's cache and a week of background revalidation (`next.config.ts`). Both stay outside the sign-in proxy like `samples/`. The file is written by the evaluation harness's `eval:covers`, from a measured run's promoted renders or, with `--from-masters <dir>`, from rendered masters kept outside the repo (`coversFromMasters()` in `scripts/eval/lib/covers.mjs`; it replaces only the ids it writes, and skips an id whose cover another run made elsewhere unless `--replace`). Stills are 4:2:0 JPEGs of at most 768 px; a clip cover is at most 4 s and 512 px, and its last 6 frames are crossfaded into its first ones so the card's loop has no jump (a clip that already ends where it starts is only cut). The first covers came that way: 480 of the 487 app, motion and effect cards (474 stills from Ideogram 4 and 6 clips from MiniMax H3, all rendered in ComfyUI; run `comfyui-previews-2026-10`, in `public/previews/presets/`), while the other 7 keep their procedural preview. Main's later cover work gave 43 apps a before/after reveal clip (Ideogram 4, then Qwen-Image 2.1 Edit), so 48 of the 480 now have a clip (the other 5 from MiniMax H3) and 432 are stills. `preview-playback.ts` decides which play: a clip card plays by itself while it's mostly in view, once scrolling stops, at most 6 at once (3 on a phone), the cards in full view and nearest the middle of the screen first; a procedural preview does so only where nothing can hover (phones), and the preset header plays whatever moves. Nothing plays by itself with reduced motion (turned on while the page is open, it stops at once), Save-Data, on 2G or in a hidden tab; a hover (after a short rest), keyboard focus, or a tap on the preset header still plays one (with reduced motion, only a clip).- **Sidebar** (round 4 part 2): Studios gains AI Influencer (`/influencer`) and Content Factory (`/content-factory`) in `nav-items.ts`. Round 4 part 5 adds Character Swap Studio (`/character-swap`, short label "Character swap") after Genjutsu.- **Models page** (round 4 part 3): `ModelRow.engines` (`src/lib/model-rows.ts`) puts an Original under both the Cloud and Open source filters, with both engine icons, "Open source + cloud" (`enginesLabel`) and a "Free · $… / megapixel" price. Since round 4 part 4 models switched off leave the list (`models-table.tsx`), which says how many and links to Settings → Models & licences.- **Sharing** (round 4 part 4): the studio layout (`src/app/(studio)/layout.tsx`) wraps every page in `ShareProvider`, so any result menu can open the Share dialog; the Library gains the Shared tab and Publish in its selection bar, whose phone version folds Like, Pin and Review into a ⋯ menu (see Share links). The public share page lives outside the `(studio)` group, without the studio's frame.diff --git a/next.config.ts b/next.config.tsindex 588f38c3..efae3daa 100644--- a/next.config.ts+++ b/next.config.ts@@ -38,9 +38,12 @@ const nextConfig: NextConfig = {{ source: "/vendor/:path*", headers: [{ key: "Cache-Control", value: "public, max-age=86400, stale-while-revalidate=604800" }] },// Preset covers (public/previews, pnpm eval:covers) keep their name when a cover is made again, but every URL the// site gives them ends in the file's content version (?v=, 8 hex digits of its sha256, from the generated- // manifests): a changed file gets a new URL, so a versioned one is kept for a year and never revalidated. One- // asked for without its version (a link from elsewhere) keeps a day's cache, revalidated in the background.- { source: "/previews/:path*", has: [COVER_VERSION], headers: [{ key: "Cache-Control", value: "public, max-age=31536000, immutable" }] },+ // manifests): a changed file gets a new URL, so a browser keeps a versioned one for a year and never revalidates+ // it. The CDN keeps it a day (s-maxage): a page loaded before a deploy can still ask for an old version and get the+ // new file under it, and a revert or rollback that gives that version back must not find the wrong file pinned+ // there for a year. One asked for without its version (a link from elsewhere) keeps a day's cache, revalidated in+ // the background.+ { source: "/previews/:path*", has: [COVER_VERSION], headers: [{ key: "Cache-Control", value: "public, max-age=31536000, s-maxage=86400, immutable" }] },{ source: "/previews/:path*", missing: [COVER_VERSION], headers: [{ key: "Cache-Control", value: "public, max-age=86400, stale-while-revalidate=604800" }] },];},diff --git a/scripts/eval/README.md b/scripts/eval/README.mdindex 23c489f8..ff5aa2fa 100644--- a/scripts/eval/README.md+++ b/scripts/eval/README.md@@ -466,9 +466,12 @@ Every URL in both files ends in its file's content version: `?v=` and the firstsha256 of its bytes (a poster's with its small copy's, whose URL keeps the poster's version). So acover made again under its old name gets a new URL, and the site serves versioned covers for a year(`next.config.ts`). Each run versions the whole manifest after making its files.-`pnpm eval:covers --versions` does only that: it hashes the files as they are and encodes nothing-(`--dry-run` says how many URLs would change). `node scripts/gen-preset-peaks.mjs` versions Home's-peak frames the same way (`--versions` alone does only that).+`pnpm eval:covers --versions` does only that: it hashes the files as they are. The only thing it+encodes is a poster's small copy that's missing or older than its poster (a poster copied in by hand),+which it makes first, so the copy never keeps the old picture under the new version. `--dry-run` says+how many URLs would change and which copies it would make, and fails while any copy is due.+`node scripts/gen-preset-peaks.mjs` versions Home's peak frames the same way (`--versions` alone+does only that).- `--variant catalog` takes that variant's renders for every case instead, such as what ships today.- `--dry-run` lists what it would pick.diff --git a/scripts/eval/eval.mjs b/scripts/eval/eval.mjsindex 63d1a012..3ca9f1bf 100644--- a/scripts/eval/eval.mjs+++ b/scripts/eval/eval.mjs@@ -84,7 +84,8 @@ pnpm eval:covers --versions [--dry-run] [--public-dir public] [--manifest …]Every URL in the manifest ends in its file's content version (?v=, 8 hex digits of its sha256; a poster's alsocovers its small copy in thumbs/), so a cover made again gets a new URL. Both commands above write them; this- one versions the manifest from the files as they are, hashing only (nothing is encoded).`,+ one versions the manifest from the files as they are. It encodes only a poster's small copy that's missing or+ older than its poster (one copied in by hand), first; --dry-run lists those and fails until they're made.`,history: "pnpm eval:history [--suite soul] [--case soul/v1-general] [--limit 20]",validate: "pnpm eval:validate [suite files…] checks every case file and that the generated suites match the research",trash: "pnpm eval:trash <runId> [--dry-run] moves the run's generations to that Fuobe's Trash (its results here stay)",@@ -459,15 +460,25 @@ async function covers(args, ctx) {return 0;}-/** pnpm eval:covers --versions: the manifest's URLs versioned from the files as they are, without encoding anything. */+/**+ * pnpm eval:covers --versions: the manifest's URLs versioned from the files as they are, encoding only the posters'+ * missing or outdated small copies. Fails (1) when a URL is left without a version (its file is missing), or on a dry+ * run when a small copy is due: until it's made, the versions don't match what the site would serve.+ */function versionsCmd(v, ctx) {- const r = versionCovers({ dryRun: v["dry-run"], publicDir: v["public-dir"] && path.resolve(v["public-dir"]), manifest: v.manifest && path.resolve(v.manifest) });- if (v.json) return ctx.print(JSON.stringify(r, null, 2)), 0;- ctx.print(`${r.changed} of ${r.urls} cover URLs in ${r.entries} entries ${v["dry-run"] ? "would get" : "got"} a new version`);- for (const u of r.unversioned.slice(0, 10)) ctx.print(` · ${u}: no file, so no version`);- if (r.unversioned.length > 10) ctx.print(` · and ${r.unversioned.length - 10} more`);- if (r.changed && !v["dry-run"]) ctx.note(`Look at the diff of ${path.relative(REPO_DIR, r.manifest) || r.manifest} before committing it.`);- return r.unversioned.length ? 1 : 0;+ const dry = v["dry-run"];+ const r = versionCovers({ dryRun: dry, publicDir: v["public-dir"] && path.resolve(v["public-dir"]), manifest: v.manifest && path.resolve(v.manifest) });+ const status = r.unversioned.length || (dry && r.thumbs.length) ? 1 : 0;+ if (v.json) return ctx.print(JSON.stringify(r, null, 2)), status;+ ctx.print(`${r.changed} of ${r.urls} cover URLs in ${r.entries} entries ${dry ? "would get" : "got"} a new version`);+ const list = (items, why) => {+ for (const u of items.slice(0, 10)) ctx.print(` · ${u}: ${why}`);+ if (items.length > 10) ctx.print(` · and ${items.length - 10} more`);+ };+ list(r.thumbs, dry ? "small copy missing or older than its poster: would be made first" : "small copy made (it was missing or older than its poster)");+ list(r.unversioned, "no file, so no version");+ if ((r.changed || r.thumbs.length) && !dry) ctx.note(`Look at the diff of ${path.relative(REPO_DIR, r.manifest) || r.manifest}${r.thumbs.length ? " and the small copies it made" : ""} before committing them.`);+ return status;}/** pnpm eval:covers --from-masters <dir>: covers from rendered masters, merged into the manifest. */diff --git a/scripts/eval/lib/covers.mjs b/scripts/eval/lib/covers.mjsindex 854f03ac..3849d306 100644--- a/scripts/eval/lib/covers.mjs+++ b/scripts/eval/lib/covers.mjs@@ -154,19 +154,25 @@ export function withVersions(entries, publicDir = path.dirname(COVERS_DIR)) {/*** Version the manifest's URLs from its files as they are (pnpm eval:covers --versions): for covers listed before- * they had versions, or files changed by hand. Hashes only: nothing is encoded. Says how many URLs changed, and- * lists any left without a version (a file that's missing).+ * they had versions, or files changed by hand. First it makes each poster's small copy that's missing or older than+ * its poster (one copied in by hand), as every run does (writeThumbs), so a copy never shows the old picture under+ * the new version. Nothing else is encoded. Says how many URLs changed and which copies it made (`thumbs`), and lists+ * any URL left without a version (a file that's missing). A dry run writes nothing: `thumbs` lists the copies it+ * would make, and `changed` counts with the copies as they are.* @param {{ publicDir?: string, manifest?: string, dryRun?: boolean }} [opts]*/export function versionCovers(opts = {}) {+ const publicDir = opts.publicDir ?? path.dirname(COVERS_DIR);const before = readManifest(opts.manifest);- const after = withVersions(before, opts.publicDir);+ const thumbs = opts.dryRun ? dueThumbs(before, publicDir).map((t) => t.thumb) : writeThumbs(before, publicDir);+ const after = withVersions(before, publicDir);const urls = (m) => Object.values(m).flatMap((e) => [e.poster, e.video].filter((u) => u !== undefined));const [was, now] = [urls(before), urls(after)];const result = {entries: Object.keys(after).length,urls: now.length,changed: now.filter((u, i) => u !== was[i]).length,+ thumbs: thumbs.map((f) => `/${path.relative(publicDir, f).split(path.sep).join("/")}`),unversioned: now.filter((u) => String(u).startsWith("/previews/") && !urlVersion(u)),manifest: opts.manifest ?? MANIFEST_FILE,};@@ -174,16 +180,24 @@ export function versionCovers(opts = {}) {return result;}+/** The listed posters whose small copy is missing or older than the poster: the ones writeThumbs makes. */+function dueThumbs(entries, publicDir) {+ const due = [];+ for (const e of Object.values(entries)) {+ const poster = previewFile(e.poster, publicDir);+ const thumb = previewFile(typeof e.poster === "string" && thumbOf(e.poster), publicDir);+ if (poster && thumb && fs.existsSync(poster) && !newer(thumb, poster)) due.push({ poster, thumb });+ }+ return due;+}+/*** Make the small copy of every listed poster that the pickers' tiles show (thumbOf: THUMB_PX wide, about 5 to 12 KB* where the poster is 40 to 70), where it's missing or older than its poster. Returns the files it made.*/export function writeThumbs(entries, publicDir = path.dirname(COVERS_DIR)) {const made = [];- for (const e of Object.values(entries)) {- const poster = previewFile(e.poster, publicDir);- const thumb = previewFile(typeof e.poster === "string" && thumbOf(e.poster), publicDir);- if (!poster || !thumb || !fs.existsSync(poster) || newer(thumb, poster)) continue;+ for (const { poster, thumb } of dueThumbs(entries, publicDir)) {fs.mkdirSync(path.dirname(thumb), { recursive: true });run(["-i", poster, "-vf", `scale='min(${THUMB_PX},iw)':-2,format=yuvj420p`, "-frames:v", "1", "-q:v", "5", thumb]);made.push(thumb);diff --git a/src/components/preset-header.tsx b/src/components/preset-header.tsxindex 9e29e81a..38bd8c89 100644--- a/src/components/preset-header.tsx+++ b/src/components/preset-header.tsx@@ -7,9 +7,9 @@ import { openGpuSetup, useGpuBadges } from "@/hooks/use-gpu";import { useEngine } from "@/lib/api";import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";import type { Preset } from "@/lib/catalog/types";-// The covers manifest comes with toPresetCard: this component is loaded on its own (next/dynamic in studio-page.tsx).-import { toPresetCard } from "@/lib/preset-card-data";-import { onPeak, presetHowTo, presetRouteLines, previewFlip } from "@/lib/preset-cards";+import { onPeak, presetCard, presetHowTo, presetRouteLines, previewFlip } from "@/lib/preset-cards";+// The slim covers map comes with coverPreview: this component is loaded on its own (next/dynamic in studio-page.tsx).+import { coverPreview } from "@/lib/preset-covers";import { cn } from "@/lib/utils";/**@@ -35,8 +35,9 @@ export function PresetHeader({onClear?: () => void;className?: string;}) {- // On its clip's peak frame when it has one, as Home's card the visitor came from (onPeak).- const card = onPeak(toPresetCard(preset));+ // Its gallery card's cover (coverPreview, from the slim map), on its clip's peak frame when it has one, as Home's+ // card the visitor came from (onPeak).+ const card = onPeak(presetCard(preset, coverPreview(preset)));const { ref, playing, asked, handlers, onTap } = usePreviewPlayback<HTMLDivElement>(card.id, card.preview, { always: true });const routes = presetRouteLines(preset, modelName);// Its state on the viewer's GPU (open engine only): a pill that opens the guided fix.diff --git a/src/lib/preset-card-data.ts b/src/lib/preset-card-data.tsindex 736522af..d8fed41d 100644--- a/src/lib/preset-card-data.ts+++ b/src/lib/preset-card-data.ts@@ -1,10 +1,11 @@/**- * A preset's card as the galleries and the preset header show it: the slim card data (preset-cards.ts) with- * its real cover when it has one (preset-previews.generated.ts, pnpm eval:covers), else the procedural preview.+ * A preset's card as the galleries show it: the slim card data (preset-cards.ts) with its real cover when it has+ * one (preset-previews.generated.ts, pnpm eval:covers), else the procedural preview. The preset header shows the+ * same one, built from the slim covers map (coverPreview, preset-covers.ts).** The only module that reads the covers manifest, which lists every cover with its provenance. Import it from- * server pages, or from a component loaded on its own (next/dynamic, like the preset header): a client module- * that imports it ships the whole manifest in every chunk it is in. tests/preset-cards.test.ts checks the importers.+ * server pages or server-only modules: a client module that imports it ships the whole manifest in every chunk it+ * is in. tests/preset-covers.test.ts checks the importers.*/import type { Preset } from "./catalog/types";import { presetCard, proceduralPreview, previewScene, type PresetCardData, type PresetPreview } from "./preset-cards";diff --git a/src/lib/preset-covers.ts b/src/lib/preset-covers.tsindex d26bebee..731de2ad 100644--- a/src/lib/preset-covers.ts+++ b/src/lib/preset-covers.ts@@ -1,12 +1,13 @@/**- * A preset's real cover for the pickers (camera motions, effects, Mix, Cinema Studio's moves): the same still and- * clip its gallery card shows, at the same versioned URLs (?v=). Reads the slim covers map (preset-covers.generated.ts:- * which presets have a cover, and a clip, and their versions), never the manifest with its provenance- * (preset-previews.generated.ts), so client code can import it.- * Keep it to the pickers' own chunks all the same: tests/preset-covers.test.ts checks the importers.+ * A preset's real cover for the pickers (camera motions, effects, Mix, Cinema Studio's moves) and the preset header:+ * the same still and clip its gallery card shows, at the same versioned URLs (?v=). Reads the slim covers map+ * (preset-covers.generated.ts: which presets have a cover, and a clip, and their versions), never the manifest with+ * its provenance (preset-previews.generated.ts), so client code can import it.+ * Keep it to their own chunks all the same: tests/preset-covers.test.ts checks the importers.*/import type { CameraMove } from "./catalog/cinema";-import { thumbOf } from "./preset-cards";+import type { Preset } from "./catalog/types";+import { proceduralPreview, previewScene, thumbOf, type PresetPreview } from "./preset-cards";import { PRESET_COVERS } from "./preset-covers.generated";/** Where pnpm eval:covers puts a poster's small copy (scripts/eval/lib/covers.mjs, thumbOf). */@@ -38,6 +39,16 @@ export function presetCover(id: string | undefined): PresetCover | undefined {return { poster, thumb: thumbOf(poster), ...(video && { video }) };}+/**+ * A preset's preview as its gallery card shows it (previewFor, preset-card-data.ts), from the slim map: its own cover,+ * never another shot's (SAME_SHOT is for the pickers' tiles), else the procedural preview. The preset header reads+ * this, so its chunk carries the versions alone rather than the manifest with its provenance.+ */+export function coverPreview(p: Pick<Preset, "id" | "type" | "name" | "category">): PresetPreview {+ const own = Object.hasOwn(PRESET_COVERS, p.id) ? presetCover(p.id) : undefined;+ return own ? { poster: own.poster, ...(own.video && { video: own.video }), scene: previewScene(p) } : proceduralPreview(p);+}+/*** Moves whose camera motion shows another shot than the name says: Drone Orbit runs 360 Orbit, whose clip circles* a dancer at ground level, not from the air.diff --git a/tests/covers-from-masters.test.ts b/tests/covers-from-masters.test.tsindex 6dd4738d..64167fa1 100644--- a/tests/covers-from-masters.test.ts+++ b/tests/covers-from-masters.test.ts@@ -13,7 +13,7 @@ const covers = (await import("../scripts/eval/lib/covers.mjs")) as unknown as {readManifest: (file: string) => Record<string, Entry>;writeManifest: (entries: Record<string, Entry>, file: string) => void;withVersions: (entries: Record<string, Entry>, publicDir: string) => Record<string, Entry>;- versionCovers: (opts: { publicDir?: string; manifest?: string; dryRun?: boolean }) => { entries: number; urls: number; changed: number; unversioned: string[] };+ versionCovers: (opts: { publicDir?: string; manifest?: string; dryRun?: boolean }) => { entries: number; urls: number; changed: number; thumbs: string[]; unversioned: string[] };seamless: (frames: Buffer[], fade: number) => Buffer[];loopsAlready: (frames: Buffer[], luma: number) => boolean;};@@ -262,7 +262,7 @@ describe("covers from masters", () => {const was = media();const unwritten = fs.readFileSync(manifest, "utf8");- expect(versionCovers({ publicDir: pub, manifest, dryRun: true })).toMatchObject({ entries: 3, urls: 4, changed: 3, unversioned: ["/previews/presets/app-missing.jpg"] });+ expect(versionCovers({ publicDir: pub, manifest, dryRun: true })).toMatchObject({ entries: 3, urls: 4, changed: 3, thumbs: [], unversioned: ["/previews/presets/app-missing.jpg"] });expect(fs.readFileSync(manifest, "utf8")).toBe(unwritten);expect(versionCovers({ publicDir: pub, manifest })).toMatchObject({ changed: 3 });const m = readManifest(manifest);@@ -278,6 +278,43 @@ describe("covers from masters", () => {expect(versionCovers({ publicDir: pub, manifest })).toMatchObject({ changed: 0 });});+ it.runIf(hasFfmpeg)("makes a poster's small copy first when it's missing or older than a poster copied in by hand (--versions)", () => {+ const pub = path.join(dir, "byhand-public");+ const presets = path.join(pub, "previews", "presets");+ fs.mkdirSync(path.join(presets, "thumbs"), { recursive: true });+ const poster = path.join(presets, "app-relight.jpg");+ const thumb = path.join(presets, "thumbs", "app-relight.jpg");+ const newThumb = path.join(presets, "thumbs", "app-headshot.jpg");+ spawnSync("ffmpeg", ["-v", "error", "-y", "-i", still(), "-frames:v", "1", "-q:v", "4", poster]);+ fs.copyFileSync(poster, path.join(presets, "app-headshot.jpg"));+ // The relit poster was copied in by hand over an older one: its small copy still shows the old picture.+ fs.writeFileSync(thumb, "the old picture");+ const before = new Date(Date.now() - 60_000);+ fs.utimesSync(thumb, before, before);+ const manifest = path.join(dir, "byhand", "manifest.ts");+ const meta = { run: "r", engine: "comfyui", model: "m", variant: "v" };+ writeManifest(+ { "app-relight": { poster: "/previews/presets/app-relight.jpg?v=00000000", ...meta }, "app-headshot": { poster: "/previews/presets/app-headshot.jpg", ...meta } },+ manifest,+ );+ const unwritten = fs.readFileSync(manifest, "utf8");+ const thumbs = ["/previews/presets/thumbs/app-headshot.jpg", "/previews/presets/thumbs/app-relight.jpg"];++ // A dry run lists the copies it would make, and makes none.+ expect(versionCovers({ publicDir: pub, manifest, dryRun: true })).toMatchObject({ changed: 2, thumbs, unversioned: [] });+ expect(fs.readFileSync(thumb, "utf8")).toBe("the old picture");+ expect(fs.existsSync(newThumb)).toBe(false);+ expect(fs.readFileSync(manifest, "utf8")).toBe(unwritten);+ // Then it makes them before hashing, so each version is of the poster and its new small copy.+ expect(versionCovers({ publicDir: pub, manifest })).toMatchObject({ changed: 2, thumbs, unversioned: [] });+ for (const f of [thumb, newThumb]) expect(fs.readFileSync(f).subarray(0, 2), f).toEqual(Buffer.from([0xff, 0xd8]));+ const m = readManifest(manifest);+ expect(m["app-relight"].poster).toBe(`/previews/presets/app-relight.jpg?v=${sha8(poster, thumb)}`);+ expect(m["app-headshot"].poster).toBe(`/previews/presets/app-headshot.jpg?v=${sha8(path.join(presets, "app-headshot.jpg"), newThumb)}`);+ // Made once: the next run has nothing to make or change.+ expect(versionCovers({ publicDir: pub, manifest, dryRun: true })).toMatchObject({ changed: 0, thumbs: [] });+ });+it("makes a clip loop without a jump: its last frames fade into its first, which it then starts after (unless it loops already)", () => {const frames = Array.from({ length: 20 }, (_, i) => Buffer.from([i * 10, i * 10]));const out = seamless(frames, 4);diff --git a/tests/preset-covers.test.ts b/tests/preset-covers.test.tsindex f15d769e..58f3e97e 100644--- a/tests/preset-covers.test.ts+++ b/tests/preset-covers.test.ts@@ -5,9 +5,9 @@ import { describe, expect, it } from "vitest";import nextConfig from "../next.config";import { APPS, EFFECTS, MOTIONS } from "@/lib/catalog";import { SOUL_LOOK_CARDS } from "@/lib/catalog/soul-looks.generated";-import { toPresetCard } from "@/lib/preset-card-data";+import { previewFor, toPresetCard } from "@/lib/preset-card-data";import { isCover, onPeak } from "@/lib/preset-cards";-import { presetCover, thumbOf } from "@/lib/preset-covers";+import { coverPreview, presetCover, thumbOf } from "@/lib/preset-covers";import { PRESET_COVERS } from "@/lib/preset-covers.generated";import { PRESET_PEAKS } from "@/lib/preset-peaks.generated";import { PRESET_PREVIEWS } from "@/lib/preset-previews.generated";@@ -108,11 +108,16 @@ describe("the preset covers manifest", () => {for (const id of [undefined, "", "toString", "constructor", "__proto__"]) expect(presetCover(id), String(id)).toBeUndefined();});- it("is read only on the server and in the preset header's own chunk", () => {+ it("gives the preset header, from the slim map, the preview its gallery card shows", () => {+ // 3D Rotation's motion included: the header shows its procedural preview, as its card does, not the app's shot.+ for (const p of [...APPS, ...MOTIONS, ...EFFECTS]) expect(coverPreview(p), p.id).toEqual(previewFor(p));+ });++ it("is read only on the server", () => {// Client chunks keep whatever client code uses from a module. preset-cards.ts is in the galleries',// home's, shorts' and mixed media's chunks, so importing the manifest there (or preset-card-data.ts,- // which does) would ship it to all of them. A new importer belongs here only if it's a server page,- // server-only (Home's showcase) or loaded on its own (next/dynamic), like the preset header.+ // which does) would ship it to all of them. A new importer belongs here only if it's a server page or+ // server-only (Home's showcase). The preset header reads the slim map instead (coverPreview).const sources = fs.readdirSync(path.join(root, "src"), { recursive: true, encoding: "utf8" }).filter((f) => /\.tsx?$/.test(f))@@ -127,16 +132,20 @@ describe("the preset covers manifest", () => {"app/(studio)/apps/page.tsx","app/(studio)/effects/page.tsx","app/(studio)/motions/page.tsx",- "components/preset-header.tsx","lib/home-showcase.ts",]);expect(fs.readFileSync(path.join(root, "src", "lib", "home-showcase.ts"), "utf8")).toMatch(/^import "server-only";$/m);- // The slim map (which presets have a cover, and a clip, with their versions: about 8 KB gzipped) is for the pickers,- // each in its own chunk: the camera motion and Mix pickers (next/dynamic in composer.tsx) and Cinema Studio's moves- // (next/dynamic in camera-moves.tsx, loaded when the "#" picker or the Director panel's Movement tab shows them).+ // The slim map (which presets have a cover, and a clip, with their versions: about 8 KB gzipped) is for the pickers+ // and the preset header, each in its own chunk: the camera motion and Mix pickers (next/dynamic in composer.tsx),+ // Cinema Studio's moves (next/dynamic in camera-moves.tsx, loaded when the "#" picker or the Director panel's+ // Movement tab shows them), and the preset header (next/dynamic in studio-page.tsx, checked below).expect(importers(/from "[^"]*preset-covers\.generated"/)).toEqual(["lib/preset-covers.ts"]);// (A type is no code: the cover tile takes a cover without importing the map.)- expect(importers(/^import (?!type )[^;]*from "[^"]*preset-covers";/m)).toEqual(["components/cinema/move-list.tsx", "components/studio/preset-chips.tsx"]);+ expect(importers(/^import (?!type )[^;]*from "[^"]*preset-covers";/m)).toEqual([+ "components/cinema/move-list.tsx",+ "components/preset-header.tsx",+ "components/studio/preset-chips.tsx",+ ]);const composer = fs.readFileSync(path.join(root, "src", "components", "studio", "composer.tsx"), "utf8");expect(composer).toMatch(/dynamic\(\(\) => import\("\.\/preset-chips"\)/);expect(importers(/from "[^"]*\/move-list"/)).toEqual([]);@@ -146,11 +155,11 @@ describe("the preset covers manifest", () => {expect(header).toMatch(/dynamic\(\(\) => import\("@\/components\/preset-header"\)/);});- it("serves a versioned cover for a year, never revalidated, and one asked for without its version for a day", async () => {+ it("serves a versioned cover for a year in the browser and a day in the CDN, and one without its version for a day", async () => {const rules = (await nextConfig.headers!()).filter((r) => r.source === "/previews/:path*");const version = { type: "query", key: "v", value: "[0-9a-f]{8}" };expect(rules).toEqual([- { source: "/previews/:path*", has: [version], headers: [{ key: "Cache-Control", value: "public, max-age=31536000, immutable" }] },+ { source: "/previews/:path*", has: [version], headers: [{ key: "Cache-Control", value: "public, max-age=31536000, s-maxage=86400, immutable" }] },{ source: "/previews/:path*", missing: [version], headers: [{ key: "Cache-Control", value: "public, max-age=86400, stale-while-revalidate=604800" }] },]);// Next matches a has or missing value whole (^…$), so the two rules never both apply, and every version takes the first.diff --git a/tests/studio-examples.test.ts b/tests/studio-examples.test.tsindex 195d95f6..2ced4eb5 100644--- a/tests/studio-examples.test.ts+++ b/tests/studio-examples.test.ts@@ -17,7 +17,11 @@ vi.mock("next/cache", () => ({ cacheLife: () => {} }));*/const root = process.cwd();-const exists = (url: string) => (fs.statSync(path.join(root, "public", url), { throwIfNoEntry: false })?.size ?? 0) > 0;+/** A cover URL's file in public/ is there and not empty: the URL as the site gives it, ending in its version (?v=). */+const exists = (url: string) => {+ expect(url, url).toMatch(/^\/previews\/[^?]+\?v=[0-9a-f]{8}$/);+ return (fs.statSync(path.join(root, "public", url.split("?")[0]), { throwIfNoEntry: false })?.size ?? 0) > 0;+};const studios = Object.keys(STUDIO_EXAMPLES) as ExampleStudio[];describe("the studios' examples", () => {