Skip to content

armgit / fuobe

Public Imported from GitHub
0

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.

Library: files an account's own projects and boards name stay in use

Adarsh7b614cc1871b
diff --git a/src/server/generations.ts b/src/server/generations.ts
index bce7648f..d9441f9f 100644
--- a/src/server/generations.ts
+++ b/src/server/generations.ts
@@ -431,6 +431,12 @@ export const ASSET_REFS: AssetRef[] = [
{ table: "swap_projects", cols: ["data_json"], what: "Character Swap project", name: "name" },
// A user skill's bundled text files: its recipe.json names the files a run starts from (an example, a fixed logo).
{ table: "skills", cols: ["files_json"], what: "skill", key: "name", name: "title" },
+ // 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" },
];
/**
@@ -492,6 +498,7 @@ export const ASSET_FREE: Record<string, string> = {
"relay_workers.hours_json": "a worker's hours: a time zone and windows",
"relay_workers.allow_json": "the lanes the owner lets a worker run, with their delays",
"relay_pairings.facts_json": "what a paired ComfyUI said about itself: its name, GPU and version",
+ "account_canvases.summary_json": "an account board's list line: node and page counts, and its outline (node types, places and short labels)",
};
/** The query that finds the rows of one ASSET_REFS table naming a file (@id), except the purged generation's own (@g). */
diff --git a/tests/library.test.ts b/tests/library.test.ts
index af331f31..e219068b 100644
--- a/tests/library.test.ts
+++ b/tests/library.test.ts
@@ -26,6 +26,8 @@ const generationRoutes = await import("@/app/api/generations/route");
const generationIdRoutes = await import("@/app/api/generations/[id]/route");
const assetIdRoutes = await import("@/app/api/assets/[id]/route");
const { db } = await import("@/server/db");
+const projects = await import("@/server/account-projects");
+const canvases = await import("@/server/account-canvas");
const { childFolders, folderTree } = await import("@/lib/library");
beforeAll(() => setSetting("demoMode", "auto"));
@@ -749,7 +751,36 @@ describe("ASSET_REFS", () => {
expect(gens.assetUses(example.asset.id)).toEqual([]);
});
+ it("keeps files an account's own project or board names when their results are deleted for good", async () => {
+ const short = made("account short final");
+ const character = made("account swap character");
+ const board = made("account board picture");
+ // 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 } });
+ const canvas = canvases.createAccountCanvas("acct-keep", {
+ name: "Board",
+ pages: [{ id: "p1", name: "Page 1", graph: { nodes: [{ id: "n1", type: "image", position: { x: 0, y: 0 }, data: { url: board.asset.url } }], edges: [] } }] as never,
+ });
+ expect(gens.assetUses(short.asset.id, { exceptGeneration: short.g.id })).toEqual([{ what: "account project", key: session.id, name: "Launch short" }]);
+ expect(gens.assetUses(character.asset.id, { exceptGeneration: character.g.id })).toEqual([{ what: "account project", key: swap.id, name: "Swap" }]);
+ expect(gens.assetUses(board.asset.id, { exceptGeneration: board.g.id })).toEqual([{ what: "account canvas", key: canvas.id, name: "Board" }]);
+ lib.trashGenerations([short.g.id, character.g.id, board.g.id]);
+ expect(await lib.emptyTrash()).toBeGreaterThanOrEqual(3);
+ for (const f of [short, character, board]) expect(fs.existsSync(fileOf(f.asset.url))).toBe(true);
+ // Uploads → Delete says where it's used, and keeps it.
+ const r = await assetIdRoutes.DELETE(new Request("http://x", { method: "DELETE" }), { params: Promise.resolve({ id: short.asset.id }) } as never);
+ expect(r.status).toBe(409);
+ expect((await r.json()).usedBy).toBe("the account project “Launch short”");
+ // Without the project or board, nothing keeps them.
+ projects.deleteAccountProjects("acct-keep");
+ canvases.deleteAccountCanvases("acct-keep");
+ for (const f of [short, character, board]) expect(gens.assetUses(f.asset.id)).toEqual([]);
+ });
+
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");
const tables = (db().prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'").all() as { name: string }[]).map((t) => t.name);
const columns = new Map(tables.map((t) => [t, (db().prepare(`PRAGMA table_info(${t})`).all() as { name: string }[]).map((c) => c.name)]));
const covered = new Set(gens.ASSET_REFS.flatMap((r) => r.cols.map((c) => `${r.table}.${c}`)));