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
Character Swap Studio: an account's project page opens for that account
Adarsh50a155dfede8
diff --git a/src/app/(studio)/character-swap/[id]/page.tsx b/src/app/(studio)/character-swap/[id]/page.tsxindex f9ccd361..a8d70a78 100644--- a/src/app/(studio)/character-swap/[id]/page.tsx+++ b/src/app/(studio)/character-swap/[id]/page.tsx@@ -1,15 +1,16 @@import type { Metadata } from "next";+import { headers } from "next/headers";import { notFound } from "next/navigation";import { Suspense } from "react";import { SwapWorkbench } from "@/components/swap-studio/workbench";-import { projectPageOpens } from "@/server/swap-studio-account";+import { recordFor } from "@/server/records";export const metadata: Metadata = { title: "Character Swap" };/** A project's page: the owner's projects, or a signed-in account's own (its projects only). */async function Project({ params }: { params: PageProps<"/character-swap/[id]">["params"] }) {const { id } = await params;- if (!(await projectPageOpens(id))) notFound();+ if (!recordFor({ kind: "swap-project", ids: [id] }, await headers())) notFound();return <SwapWorkbench id={id} />;}diff --git a/src/server/records.ts b/src/server/records.tsindex 8ffbca44..e6aa3874 100644--- a/src/server/records.ts+++ b/src/server/records.ts@@ -35,7 +35,7 @@ export function recordExists(ref: RecordRef): boolean {}/** Record pages a tool keeps per account (public sign-up): the project kind it keeps them as (account-projects.ts). */-const ACCOUNT_KINDS: Partial<Record<RecordRef["kind"], string>> = { shorts: "shorts", cinema: "cinema" };+const ACCOUNT_KINDS: Partial<Record<RecordRef["kind"], string>> = { shorts: "shorts", cinema: "cinema", "swap-project": "swap" };/*** For a signed-in account: whether the record a page names is one of its own, on a page a tool keeps per account (null:diff --git a/src/server/swap-studio-account.ts b/src/server/swap-studio-account.tsindex a022a881..1f644cae 100644--- a/src/server/swap-studio-account.ts+++ b/src/server/swap-studio-account.ts@@ -1,14 +1,12 @@import "server-only";-import { headers } from "next/headers";import type { z } from "zod";import { GUEST_HEADER, GUEST_LIBRARY_MESSAGE } from "@/lib/guest-access";import { projectRefsProblem, projectSavesLimited } from "./account-projects";import { bodyTooBig, guestRun, refusalResponse, runAccountTool, toolViewer } from "./account-tool-run";-import { requestViewer, type Account } from "./auth";+import type { Account } from "./auth";import { AccountRunError, asAccount } from "./generations";-import { recordExists } from "./records";import { body, handle } from "./shorts-schemas";-import { accountHasProject, planSwapJob, startSwapJob, StudioError } from "./swap-studio";+import { planSwapJob, startSwapJob, StudioError } from "./swap-studio";/*** Character Swap Studio for each kind of viewer (public sign-up), for its routes:@@ -119,12 +117,3 @@ export function asViewer(request: Request, fn: (account: Account | null) => Respreturn handle(() => asAccount(account.id, () => fn(account)), request);}-/**- * Whether the page of this project opens for whoever asks: an account opens only its own projects; the owner and a- * guest the owner's (a guest's page then says to sign up).- */-export async function projectPageOpens(id: string): Promise<boolean> {- const viewer = requestViewer(new Request("http://fuobe.local/", { headers: await headers() }));- if (viewer.kind === "account") return accountHasProject(viewer.account.id, id);- return recordExists({ kind: "swap-project", ids: [id] });-}diff --git a/src/server/swap-studio.ts b/src/server/swap-studio.tsindex 5ace3d48..74543fe0 100644--- a/src/server/swap-studio.ts+++ b/src/server/swap-studio.ts@@ -172,8 +172,6 @@ function mustProject(id: string): SwapProject {return p;}-/** Whether this account has a Character Swap project with this id (its page opens only its own). */-export const accountHasProject = (accountId: string, id: string): boolean => !!getAccountProject(accountId, ACCOUNT_KIND, id);/** Change a project in one synchronous read-modify-write (no await inside: nothing else runs between). */function mutate(id: string, fn: (p: SwapProject) => SwapProject): SwapProject {diff --git a/tests/account-swap-studio.test.ts b/tests/account-swap-studio.test.tsindex e2c8cb3d..6d70e463 100644--- a/tests/account-swap-studio.test.ts+++ b/tests/account-swap-studio.test.ts@@ -61,9 +61,9 @@ const { saveFile } = await import("@/server/storage");const { runAsTenant } = await import("@/server/tenant");const { ACCOUNT_LIMITS } = await import("@/server/account-files");const { accountProjectsWith, getAccountProject } = await import("@/server/account-projects");-const { accountHasProject, ensureSwapStudioRunner } = await import("@/server/swap-studio");+const { ensureSwapStudioRunner } = await import("@/server/swap-studio");const { ACCOUNT_CLIP_BYTES } = await import("@/lib/clip-limit");-const { recordExists } = await import("@/server/records");+const { accountRecordExists, recordExists } = await import("@/server/records");const CLIP = fs.readFileSync(path.join(__dirname, "fixtures/shorts-12s.mp4"));@@ -253,9 +253,14 @@ describe("an account's projects are its own", () => {// Kept with the account, never in the owner's table.expect(getAccountProject(a, "swap", mine)).not.toBeNull();expect(recordExists({ kind: "swap-project", ids: [mine] })).toBe(false);- expect(accountHasProject(a, mine)).toBe(true);- expect(accountHasProject(b, mine)).toBe(false);- expect(accountHasProject(a, owners)).toBe(false);+ // Its page opens for it alone (the proxy answers anyone else a 404 before the page streams).+ const page = { kind: "swap-project" as const, ids: [mine] };+ expect(accountRecordExists(page, a)).toBe(true);+ expect(accountRecordExists(page, b)).toBe(false);+ expect(accountRecordExists({ kind: "swap-project", ids: [owners] }, a)).toBe(false);+ expect(passed(viaProxy(`/character-swap/${mine}`, "GET", "a"))).toBe(true);+ expect(viaProxy(`/character-swap/${mine}`, "GET", "b").status).toBe(404);+ expect(viaProxy(`/character-swap/${owners}`, "GET", "a").status).toBe(404);// Its list has it (and never the owner's); B's and the owner's lists don't.expect((await list("a")).map((x) => x.id)).toEqual([mine]);expect(await list("b")).toEqual([]);