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
Sharing: share pages render per request, captions don't repeat the prompt, clearer expiry
Claude0d1791aaee2d
diff --git a/src/app/s/[token]/page.tsx b/src/app/s/[token]/page.tsxindex e21d791d..9b5479f9 100644--- a/src/app/s/[token]/page.tsx+++ b/src/app/s/[token]/page.tsx@@ -1,6 +1,7 @@import type { Metadata } from "next";import { cookies } from "next/headers";import { notFound } from "next/navigation";+import { connection } from "next/server";import { cache, Suspense } from "react";import { SharePage, ShareSkeleton } from "@/components/share/share-page";import { authEnabled, SESSION_COOKIE, validSession } from "@/server/auth";@@ -22,6 +23,8 @@ const PRIVATE: Metadata = {export async function generateMetadata({ params }: PageProps<"/s/[token]">): Promise<Metadata> {const { token } = await params;+ // A link opens per request (it may expire or be revoked any minute): never prerendered.+ await connection();const s = load(token);if (!s) return { ...PRIVATE, title: { absolute: "Link unavailable · Fuobe" } };return {@@ -34,6 +37,7 @@ export async function generateMetadata({ params }: PageProps<"/s/[token]">): Proasync function Content({ params }: { params: PageProps<"/s/[token]">["params"] }) {const { token } = await params;+ await connection();const s = load(token);if (!s) notFound();// Views count visitors, not the owner checking their own link.diff --git a/src/components/share/publish-wizard.tsx b/src/components/share/publish-wizard.tsxindex 1186e5e1..a3d98b59 100644--- a/src/components/share/publish-wizard.tsx+++ b/src/components/share/publish-wizard.tsx@@ -48,7 +48,8 @@ export function PublishWizard({ items, onClose, onPublished }: { items: Generaticonst actions = useShareActions();const at = STEPS.indexOf(step);const blocker = !title.trim() ? "Give the page a title" : !order.length ? "Keep at least one result" : null;- const coverOf = cover && order.some((g) => g.id === cover.generationId) ? cover : null;+ // Without a pick, the first piece (as the Cover step shows it), whatever it is.+ const coverOf = cover && order.some((g) => g.id === cover.generationId) ? cover : order[0] ? { generationId: order[0].id, index: firstShown(order[0]) } : null;const publish = async () => {setBusy(true);diff --git a/src/components/share/share-dialog.tsx b/src/components/share/share-dialog.tsxindex 4b7555b2..24831852 100644--- a/src/components/share/share-dialog.tsx+++ b/src/components/share/share-dialog.tsx@@ -111,12 +111,12 @@ export function PromptsSwitch({ value, onChange }: { value: boolean; onChange: ();}-/** Never / 1 day / 7 days / 30 days, as a segmented radio row. */+/** Always / 1 day / 7 days / 30 days, as a segmented radio row. */export function ExpiryPicker({ value, onChange }: { value: number | null; onChange: (days: number | null) => void }) {return (<div className="grid gap-1.5"><p id="share-expiry" className="text-sm leading-none font-medium">- Link stops working+ Link works for</p><div role="radiogroup" aria-labelledby="share-expiry" onKeyDown={radioKeys} className="flex flex-wrap gap-1 rounded-xl bg-muted p-1">{EXPIRY_CHOICES.map((c) => {@@ -134,7 +134,7 @@ export function ExpiryPicker({ value, onChange }: { value: number | null; onChanon ? "bg-background font-medium shadow-sm" : "text-muted-foreground hover:text-foreground",)}>- {c.days === null ? "Never" : `After ${c.label}`}+ {c.days === null ? "Always" : c.label}</button>);})}diff --git a/src/components/share/shared-links.tsx b/src/components/share/shared-links.tsxindex c20fc507..cb012ecb 100644--- a/src/components/share/shared-links.tsx+++ b/src/components/share/shared-links.tsx@@ -125,7 +125,7 @@ function Row({ s, token, now }: { s: ShareListItem; token?: string; now: numberreturn (<li className={cn("flex min-w-0 items-center gap-3 rounded-xl border bg-card p-2.5", dead && "opacity-75")}><div className="grid size-14 shrink-0 place-items-center overflow-hidden rounded-lg bg-muted">- {s.thumb ? <MediaThumb output={{ url: s.thumb.url, kind: s.thumb.kind }} className="size-full" /> : s.kind === "publish" ? <Globe className="size-5 text-muted-foreground" /> : <Link2 className="size-5 text-muted-foreground" />}+ {s.thumb ? <MediaThumb output={{ url: s.thumb.url, kind: s.thumb.kind, ...(s.thumb.poster && { meta: { poster: s.thumb.poster } }) }} className="size-full" /> : s.kind === "publish" ? <Globe className="size-5 text-muted-foreground" /> : <Link2 className="size-5 text-muted-foreground" />}</div><div className="min-w-0 flex-1"><p className="truncate text-[14px] font-medium">{s.title}</p>diff --git a/src/lib/share.ts b/src/lib/share.tsindex fdf6f57b..f66fd79c 100644--- a/src/lib/share.ts+++ b/src/lib/share.ts@@ -60,7 +60,7 @@ export interface ShareInfo {export interface ShareListItem extends ShareInfo {count: number;/** The cover as the owner's own file URL (/api/files/…), for the list. */- thumb: { url: string; kind: MediaKind } | null;+ thumb: { url: string; kind: MediaKind; poster?: string } | null;/** The result, folder or project was deleted: the link answers 404. */gone: boolean;}diff --git a/src/server/shares.ts b/src/server/shares.tsindex c8edbd4b..06a152af 100644--- a/src/server/shares.ts+++ b/src/server/shares.ts@@ -147,16 +147,18 @@ export function buildPublicShare(row: ShareRow, token: string): { page: PublicShconst items: PublicItem[] = [];for (const [n, g] of sc.list.entries()) {const key = String(n + 1);- const title = itemTitle(g, share.showPrompts);+ const prompt = share.showPrompts ? promptOf(g) : undefined;+ const named = itemTitle(g, share.showPrompts);+ // The prompt shows under the title, so a title that is only the prompt again says what was made instead.+ const title = prompt && prompt.startsWith(named) ? itemTitle(g, false) : named;// A 3D result shows its turntable (a video output) with the model as a download.const shown = g.kind === "model3d" ? g.outputs.map((_, i) => i) : shownOutputs(g);- const list = shown.map((i) => ({ i, m: media(g.outputs[i], i, title) })).filter((x): x is { i: number; m: PublicMedia } => !!x.m);+ const list = shown.map((i) => ({ i, m: media(g.outputs[i], i, named) })).filter((x): x is { i: number; m: PublicMedia } => !!x.m);if (!list.length) continue;if (share.cover?.generationId === g.id) {cover = (list.find((x) => x.i === share.cover!.index) ?? list[0]).m;coverKey = key;}- const prompt = share.showPrompts ? promptOf(g) : undefined;items.push({key,title,@@ -196,7 +198,10 @@ export function buildPublicShare(row: ShareRow, token: string): { page: PublicSh};}-/** Whether a share may serve this stored file: only one its page shows. */+/**+ * Whether a share may serve this stored file: only one its page shows now. Worked out per request+ * (no cache), so a result taken to the Trash or out of a folder stops opening at once.+ */export function shareServesFile(row: ShareRow, token: string, rel: string): boolean {return buildPublicShare(row, token)?.files.has(rel) ?? false;}@@ -295,12 +300,23 @@ export function listShares(): ShareListItem[] {return rows.map((r) => {const sc = scope(r);const info = toShareInfo(r);- const coverGen = (info.cover && sc?.list.find((g) => g.id === info.cover!.generationId)) || sc?.list.find((g) => g.outputs.some((o) => (o.kind === "image" || o.kind === "video") && storedPath(o.url)));- const out = coverGen?.outputs[coverGen.id === info.cover?.generationId ? info.cover.index : coverGen.outputs.findIndex((o) => (o.kind === "image" || o.kind === "video") && storedPath(o.url))];- return { ...info, count: sc?.list.length ?? 0, thumb: out && storedPath(out.url) ? { url: out.url, kind: out.kind } : null, gone: !sc };+ return { ...info, count: sc?.list.length ?? 0, thumb: sc ? thumbOf(sc.list, info.cover) : null, gone: !sc };});}+/** The list's thumbnail: the cover, else the first picture, else the first clip (with its poster). */+function thumbOf(list: Generation[], cover: ShareInfo["cover"]): ShareListItem["thumb"] {+ const stored = (o: OutputFile | undefined, kinds: string[]) => !!o && kinds.includes(o.kind) && !!storedPath(o.url);+ const covered = cover && list.find((g) => g.id === cover.generationId)?.outputs[cover.index];+ const out =+ (stored(covered ?? undefined, ["image", "video"]) ? covered : undefined) ??+ list.flatMap((g) => g.outputs).find((o) => stored(o, ["image"])) ??+ list.flatMap((g) => g.outputs).find((o) => stored(o, ["video"]));+ if (!out) return null;+ const poster = ["poster", "thumbnail"].map((k) => out.meta?.[k]).find((v): v is string => typeof v === "string" && !!storedPath(v));+ return { url: out.url, kind: out.kind, ...(poster && { poster }) };+}+/** Change a link (its words, prompts on or off, a new expiry from now), or give it a new token. */export function updateShare(id: string, patch: SharePatch, now = Date.now()): { share: ShareInfo; token?: string; path?: string } | null {const r = rowOf(id);diff --git a/tests/share-links.test.ts b/tests/share-links.test.tsindex eb6e3404..7029fbf0 100644--- a/tests/share-links.test.ts+++ b/tests/share-links.test.ts@@ -267,6 +267,9 @@ describe("prompts", () => {const shown = shares.createShare({ kind: "result", targetId: g.id, showPrompts: true });const page2 = shares.buildPublicShare(access.findShare(shown.token)!, shown.token)!.page;expect(page2.items[0].prompt).toBe("a secret prompt about violet tigers");+ // The caption doesn't say the prompt twice: the title names what was made, the prompt sits under it.+ expect(page2.items[0].title).not.toMatch(/violet tigers/);+ expect(page2.items[0].media[0].download).toMatch(/^a-secret-prompt-about-violet-tigers/);const html2 = renderToStaticMarkup(createElement(SharePage, { share: page2 }));expect(html2).toMatch(/violet tigers/);expect(html2).toMatch(/Recreate in your Fuobe/);