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
Library: an account's boards and projects keep only that account's files
Adarshe78b1dbf9368
diff --git a/src/server/generations.ts b/src/server/generations.tsindex d9441f9f..cb541e98 100644--- a/src/server/generations.ts+++ b/src/server/generations.ts@@ -382,6 +382,12 @@ export interface AssetRef {/** SQL that names the row, and the key that tells rows apart (default `id`; a Cinema take and its project are one project). */name?: string;key?: string;+ /**+ * The column naming the account a row belongs to (an account's own board or project). Such a row keeps only that+ * account's own files: what a board names is checked when the file is read, not when the board is saved, and a+ * project's free text is never checked, so a row naming the owner's or another account's file must never keep it.+ */+ account?: string;}/**@@ -434,9 +440,9 @@ export const ASSET_REFS: AssetRef[] = [// An account's own boards and projects (public sign-up): a board's pages (its nodes' pictures and clips), and a// project's data (a Shorts session or preset, a Cinema project, a Character Swap project…) and its list line (a// short's final video, a swap's character picture). `key` is set so an owner's dry run never deletes these rows- // (skill-runs.ts STUDIO_TABLES).- { table: "account_canvases", cols: ["pages_json"], what: "account canvas", key: "id", name: "name" },- { table: "account_projects", cols: ["data_json", "summary_json"], what: "account project", key: "id", name: "name" },+ // (skill-runs.ts STUDIO_TABLES). `account` lets a row keep only its own account's files.+ { table: "account_canvases", cols: ["pages_json"], what: "account canvas", key: "id", name: "name", account: "account_id" },+ { table: "account_projects", cols: ["data_json", "summary_json"], what: "account project", key: "id", name: "name", account: "account_id" },];/**@@ -505,8 +511,10 @@ export const ASSET_FREE: Record<string, string> = {export function assetRefSql(r: AssetRef): string {const where = r.cols.map((c) => `instr(COALESCE(${c}, ''), @id) > 0`).join(" OR ");const except = r.except ? ` AND ${r.except} != @g` : "";+ // A row of the file's own account only (the owner's files have no account, so no account's row keeps them).+ const own = r.account ? ` AND ${r.account} = (SELECT account_id FROM assets WHERE id = @id)` : "";const trashed = r.table === "generations" ? ", EXISTS (SELECT 1 FROM generation_trash t WHERE t.generation_id = generations.id) AS trashed" : "";- return `SELECT ${r.key ?? "id"} AS k, ${r.name ?? "NULL"} AS n${trashed} FROM ${r.table} WHERE (${where})${except} LIMIT @max`;+ return `SELECT ${r.key ?? "id"} AS k, ${r.name ?? "NULL"} AS n${trashed} FROM ${r.table} WHERE (${where})${except}${own} LIMIT @max`;}/**diff --git a/tests/library.test.ts b/tests/library.test.tsindex e219068b..0186cd85 100644--- a/tests/library.test.ts+++ b/tests/library.test.ts@@ -755,6 +755,7 @@ describe("ASSET_REFS", () => {const short = made("account short final");const character = made("account swap character");const board = made("account board picture");+ for (const f of [short, character, board]) db().prepare("UPDATE assets SET account_id = 'acct-keep' WHERE id = ?").run(f.asset.id);// A Shorts session names its final video in its data and its list line; a swap project's list line names its character.const session = projects.createAccountProject("acct-keep", "shorts", { name: "Launch short", data: { stitches: [{ final: short.asset.url }] }, summary: { final: short.asset.url } });const swap = projects.createAccountProject("acct-keep", "swap", { name: "Swap", data: { clips: [] }, summary: { character: character.asset.url } });@@ -778,6 +779,26 @@ describe("ASSET_REFS", () => {for (const f of [short, character, board]) expect(gens.assetUses(f.asset.id)).toEqual([]);});+ it("never lets an account's board or project keep the owner's or another account's file", async () => {+ // The owner's upload, named by a stranger's board (a board takes any /api/files/ link; the file route checks it on read).+ const upload = saveFile({ data: Buffer.concat([PNG, Buffer.from("owner upload")]), contentType: "image/png", source: "upload" });+ // Another account's result, named in a stranger's project free text (a Cinema brief) and on its board.+ const theirs = made("another account's result");+ db().prepare("UPDATE assets SET account_id = 'acct-other' WHERE id = ?").run(theirs.asset.id);+ const page = (url: string) => ({ id: "p1", name: "Page 1", graph: { nodes: [{ id: "n1", type: "image", position: { x: 0, y: 0 }, data: { url } }], edges: [] } });+ canvases.createAccountCanvas("acct-stranger", { name: "anything I like", pages: [page(upload.url), page(theirs.asset.url)] as never });+ projects.createAccountProject("acct-stranger", "cinema", { name: "Brief", data: { brief: { body: `see ${upload.id} and ${theirs.asset.id}` } }, summary: { cover: theirs.asset.url } });+ expect(gens.assetUses(upload.id)).toEqual([]);+ expect(gens.assetUses(theirs.asset.id, { exceptGeneration: theirs.g.id })).toEqual([]);+ // Uploads → Delete works for the owner, and Delete forever removes the other account's file.+ const r = await assetIdRoutes.DELETE(new Request("http://x", { method: "DELETE" }), { params: Promise.resolve({ id: upload.id }) } as never);+ expect(r.status).toBe(204);+ await lib.deleteForever([theirs.g.id]);+ expect(fs.existsSync(fileOf(theirs.asset.url))).toBe(false);+ projects.deleteAccountProjects("acct-stranger");+ canvases.deleteAccountCanvases("acct-stranger");+ });+it("covers every column that can hold a file, and every entry's query runs", () => {// account_projects is made the first time it's used.projects.listAccountProjects("nobody", "shorts");