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
Split soundtrack: a refused upload goes back to the empty tool; the price check names a missing model
Adarshda765932b444
diff --git a/src/components/audio-tools/split-tool.tsx b/src/components/audio-tools/split-tool.tsxindex c585f7b4..2ae26fe1 100644--- a/src/components/audio-tools/split-tool.tsx+++ b/src/components/audio-tools/split-tool.tsx@@ -117,7 +117,26 @@ const tick = () => new Promise<void>((r) => setTimeout(r, 0));// ---------------------------------------------------------------------------// Input-function AddMedia({ onPick }: { onPick: (s: Source) => void }) {+/**+ * Upload a file as the soundtrack: `put` shows it at once with its local preview, then `update` gives it its address,+ * or takes it away when the upload is refused (a guest, an account without its GPU, a file of another kind) or fails,+ * so the tool never stays on "Uploading…". Its answer counts only while it's still this upload: a soundtrack removed or+ * replaced meanwhile stays as it is.+ */+export function uploadSource(f: File, kind: "audio" | "video", put: (s: Source) => void, update: (next: (cur: Source | null) => Source | null) => void): Promise<void> {+ const id = nanoid(8);+ return fileToSlot(+ f,+ (v) => {+ const s: Source | null = v && { ...v, id, kind: v.kind === "video" ? "video" : "audio", name: f.name };+ if (s?.uploading) put(s);+ else update((cur) => (cur?.id === id ? s : cur));+ },+ kind,+ );+}++function AddMedia({ onPick, onUpdate }: { onPick: (s: Source) => void; onUpdate: (next: (cur: Source | null) => Source | null) => void }) {const input = useRef<HTMLInputElement>(null);const [over, setOver] = useState(false);const [picking, setPicking] = useState(false);@@ -125,7 +144,7 @@ function AddMedia({ onPick }: { onPick: (s: Source) => void }) {if (!f) return;const kind = kindOfFile(f);if (kind !== "audio" && kind !== "video") return void toast("Audio or video only — drop a sound file or a clip here");- void fileToSlot(f, (v) => v && onPick({ ...v, kind: v.kind === "video" ? "video" : "audio", name: f.name }), kind);+ void uploadSource(f, kind, onPick, onUpdate);};return (<div@@ -721,7 +740,7 @@ export function SplitSoundtrackTool({ tabs }: { tabs?: React.ReactNode }) {)}<div className={cn("mx-auto max-w-[860px] space-y-3", source ? "pt-4" : "mt-8")}>{!source ? (- <AddMedia onPick={take} />+ <AddMedia onPick={take} onUpdate={setSource} />) : (<SourcePanelsource={source}diff --git a/src/server/audio-tools.ts b/src/server/audio-tools.tsindex 62533d03..585526ac 100644--- a/src/server/audio-tools.ts+++ b/src/server/audio-tools.ts@@ -166,9 +166,10 @@ export async function previewAudioTool(body: AudioToolRequest): Promise<AudioToo: visitor? [account ? lastGpuDevice(account) : undefined, undefined]: await Promise.all([comfyDevice().catch(() => undefined), comfyDbsModels().catch(() => undefined)]);- if (body.quality && installed && !installed.includes(DBS_MODELS[body.quality])) throw new AudioToolError(missingDbs(DBS_MODELS[body.quality], installed));const pick = hostPick(device, installed);const quality = body.quality ?? pick;+ // Picked or the host's pick: a host with neither model on disk can't run its pick either.+ if (installed && !installed.includes(DBS_MODELS[quality])) throw new AudioToolError(missingDbs(DBS_MODELS[quality], installed));const { duration: seconds, channels } = p.split ?? {};Object.assign(out, { hostPick: pick, ...(device && { device }), ...(installed && { installed: installed.map((m) => (m === DBS_MODELS.best ? "best" : "fast")) }), ...(p.headerChannels && { channels: p.headerChannels }) });if (seconds) out.estimate = splitTime({ seconds, quality, mode: dbsChannelsFor(body.stereo ? "each channel" : "mono", channels), channels, device });diff --git a/tests/e2e/split-soundtrack.mjs b/tests/e2e/split-soundtrack.mjsindex b754970b..fef7d490 100644--- a/tests/e2e/split-soundtrack.mjs+++ b/tests/e2e/split-soundtrack.mjs@@ -4,8 +4,10 @@// ComfyUI-DBS and its weights (a CPU split of the 6 s clip takes about half a minute).// Checks, at 1440 px and 390 px in light and dark: the empty tool, the cloud engine's "runs on your GPU" note, the open// engine's options (model preselected for the host, stereo stems) and "Free" with a time estimate, no sideways scroll;-// then one run per source kind: the four stem tiles, the live mixer playing, a preset, Export mix landing in the Library,-// and, for a video, "Put back on the video" giving a video. Screenshots go to outDir.+// a refused upload (a guest's, an account's without its GPU, a file of another kind) and one removed while it uploads+// bring back the empty tool, never "Uploading…" for good; then one run per source kind: the four stem tiles, the live+// mixer playing, a preset, Export mix landing in the Library, and, for a video, "Put back on the video" giving a video.+// Screenshots go to outDir.import { spawnSync } from "node:child_process";import fs from "node:fs";import path from "node:path";@@ -80,6 +82,55 @@ try {}}+ // ---- A refused upload (a guest's 401, an account's Connect your GPU, a file the server reads as another kind) and one+ // removed while it uploads: the empty tool comes back, never "Uploading…" for good; then a file is taken as usual.+ for (const [dname, device] of [+ ["1440", DESKTOP],+ ["390", PHONE],+ ]) {+ const ctx = await setup(browser, device, "light", "open");+ // Connect your GPU's card looks for a ComfyUI on this computer (127.0.0.1:8188…): it reaches nothing but the app.+ await ctx.route((u) => u.origin !== new URL(app).origin && /^https?:$/.test(u.protocol), (r) => r.abort());+ const page = await ctx.newPage();+ let refusal = null;+ await page.route("**/api/uploads", async (r) => {+ if (r.request().method() !== "POST" || !refusal) return r.continue();+ const [status, headers, body, delay = 0] = refusal;+ if (delay) await new Promise((res) => setTimeout(res, delay));+ return r.fulfill({ status, contentType: "application/json", headers, body: JSON.stringify(body) }).catch(() => {});+ });+ await openRoute(page, `${app}/audio/split`);+ const empty = page.getByText("Add a soundtrack to split");+ for (const [why, answer] of [+ ["a guest's refused upload", [401, { "x-fuobe-guest": "1" }, { error: "Create a free account to run this." }]],+ ["an account's upload without its GPU", [403, { "x-fuobe-connect-gpu": "1" }, { error: "Connect your GPU to run this.", code: "connect-gpu" }]],+ ["a file the server reads as a picture", [201, {}, { id: "x", url: "/api/files/uploads/x.png", kind: "image" }]],+ ]) {+ refusal = answer;+ await page.locator('input[type="file"]').setInputFiles(wav);+ await empty.waitFor({ timeout: 10_000 }).catch(() => {});+ await page.waitForTimeout(500);+ const uploading = await page.getByText("Uploading…").count();+ check((await empty.isVisible()) && uploading === 0, `${dname}: after ${why} the empty tool is back (Uploading… ×${uploading})`);+ await page.keyboard.press("Escape");+ await page.waitForTimeout(300);+ }+ if (dname === "390") await page.screenshot({ path: path.join(out, `split-refused-${dname}.png`), fullPage: true });+ // Removed while it uploads: its answer, when it comes, doesn't bring it back.+ refusal = [201, {}, { id: "y", url: "/api/files/uploads/y.wav", kind: "audio" }, 2500];+ await page.locator('input[type="file"]').setInputFiles(wav);+ await page.getByRole("status").filter({ hasText: "Uploading…" }).waitFor({ timeout: 10_000 });+ await page.getByRole("button", { name: "Remove the soundtrack" }).click();+ await page.waitForTimeout(3500);+ check(await empty.isVisible(), `${dname}: a soundtrack removed while it uploads stays removed`);+ refusal = null;+ await page.locator('input[type="file"]').setInputFiles(wav);+ await page.getByText(/Free · runs on your ComfyUI|Demo · free/).waitFor({ timeout: 30_000 });+ check(true, `${dname}: a file is taken as usual afterwards`);+ await page.screenshot({ path: path.join(out, `split-after-refusal-${dname}.png`), fullPage: true });+ await ctx.close();+ }+// ---- A run per source kind: stems, mixer, export; a video goes back on the video.for (const [kind, file, device, dname] of [["audio", wav, DESKTOP, "1440"],diff --git a/tests/split-soundtrack.test.ts b/tests/split-soundtrack.test.tsindex b21ef8d4..eafd4a22 100644--- a/tests/split-soundtrack.test.ts+++ b/tests/split-soundtrack.test.ts@@ -1,7 +1,9 @@import fs from "node:fs";+import http from "node:http";+import type { AddressInfo } from "node:net";import os from "node:os";import path from "node:path";-import { afterAll, beforeAll, describe, expect, it } from "vitest";+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";import {backgroundLowered,CLOUD_ONLY_PROBLEM,@@ -59,12 +61,17 @@ process.env.FUOBE_DATA_DIR = dir;// Nothing listens: the open model runs on the demo provider.process.env.COMFYUI_URL = "http://127.0.0.1:9";+const toasts = vi.hoisted(() => ({ error: [] as string[] }));+vi.mock("sonner", () => ({ toast: Object.assign(() => {}, { error: (m: string) => void toasts.error.push(m) }) }));+const { setSetting } = await import("@/server/settings");const { getAsset, saveFile, scratchDir, storedMedia } = await import("@/server/storage");const gens = await import("@/server/generations");const route = await import("@/app/api/audio-tools/route");const exportRoute = await import("@/app/api/audio-tools/export/route");const { PART_MAX } = await import("@/server/mix-export");+const { uploadSource } = await import("@/components/audio-tools/split-tool");+const { CONNECT_GPU_HEADER, CONNECT_GPU_MESSAGE, GUEST_HEADER, GUEST_RUN_MESSAGE } = await import("@/lib/guest-access");beforeAll(() => setSetting("demoMode", "auto"));afterAll(() => fs.rmSync(dir, { recursive: true, force: true }));@@ -617,3 +624,110 @@ describe("POST /api/audio-tools/export (a mix sent in parts)", () => {expect(over.pulled()).toBeLessThanOrEqual(PART_MAX + 2 * 1024 ** 2);});});++describe("a price check on a ComfyUI without the DBS model it would use", () => {+ it("refuses the host's pick in words, as it refuses a picked model, before anything runs", async () => {+ // A CPU ComfyUI with ComfyUI-DBS loaded: GET /models/dbs lists the files on disk.+ let files: string[] = [];+ const server = http.createServer((req, res) => {+ const at = (req.url ?? "").split("?")[0];+ const body = at === "/system_stats" ? { system: { comfyui_version: "0.41.0" }, devices: [{ name: "cpu", type: "cpu" }] } : at === "/models/dbs" ? files : null;+ res.writeHead(body ? 200 : 404, { "Content-Type": "application/json" });+ res.end(JSON.stringify(body));+ });+ await new Promise<void>((r) => server.listen(0, "127.0.0.1", () => r()));+ const url = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;+ setSetting("comfyUrl", url);+ globalThis.__fuobeComfyReach = { ok: true, at: Date.now(), url, seen: Date.now() };+ globalThis.__fuobeComfyDevice = globalThis.__fuobeComfyDbs = undefined;+ try {+ const media = upload(5, 2, "pick.wav");+ const price = (asked: Record<string, unknown>) => post({ tool: "split", engine: "open", media, kind: "audio", ...asked }, true);+ // Neither model on disk: no quality picked is refused as Fast picked is (the CPU's pick), not priced as if it ran.+ for (const asked of [{}, { quality: "fast" }]) {+ const res = await price(asked);+ expect(res.status).toBe(422);+ expect((await res.json()).error).toBe(missingDbs("DBS-BSRNN-DnR", []));+ }+ // DBS-TIGER alone: the host's pick is it, priced; Fast picked is refused and names Best.+ files = ["DBS-TIGER-DnR/config.json", "DBS-TIGER-DnR/model.safetensors"];+ globalThis.__fuobeComfyDbs = undefined;+ expect(await (await price({})).json()).toMatchObject({ demo: false, hostPick: "best", installed: ["best"], device: "cpu" });+ expect((await (await price({ quality: "fast" })).json()).error).toBe(missingDbs("DBS-BSRNN-DnR", ["DBS-TIGER-DnR"]));+ } finally {+ setSetting("comfyUrl", "");+ globalThis.__fuobeComfyReach = undefined;+ globalThis.__fuobeComfyDevice = globalThis.__fuobeComfyDbs = undefined;+ await new Promise<void>((r) => server.close(() => r()));+ }+ });+});++describe("the soundtrack while it uploads (the page's source)", () => {+ type Shown = { id?: string; ref: string; preview: string; kind: "audio" | "video"; name?: string; uploading?: boolean } | null;+ const answer = (status: number, body: Record<string, unknown>, headers: Record<string, string> = {}) =>+ new Response(JSON.stringify(body), { status, headers: { "Content-Type": "application/json", ...headers } });+ const film = (name = "Film.wav") => new File([new Uint8Array(64)], name, { type: "audio/wav" });+ let server: () => Response | Promise<Response> = () => answer(500, {});+ beforeEach(() => {+ toasts.error.length = 0;+ vi.stubGlobal("fetch", async () => server());+ });+ afterEach(() => vi.unstubAllGlobals());++ /** The page's source as React keeps it: the upload puts it up, then changes what is there by its answer. */+ function page() {+ let source: Shown = null;+ const seen: Shown[] = [];+ const put = (s: NonNullable<Shown>) => void seen.push((source = s));+ const update = (next: (cur: Shown) => Shown) => void seen.push((source = next(source)));+ return { seen, now: () => source, remove: () => void (source = null), upload: (f = film()) => uploadSource(f, "audio", put, update) };+ }++ it("a guest's refused upload goes back to the empty tool, not Uploading… for good", async () => {+ server = () => answer(401, { error: GUEST_RUN_MESSAGE }, { [GUEST_HEADER]: "1" });+ const p = page();+ await p.upload();+ expect(p.seen.map((s) => s && { uploading: s.uploading, name: s.name })).toEqual([{ uploading: true, name: "Film.wav" }, null]);+ expect(p.now()).toBeNull();+ });++ it("so does an account's without its GPU, and a file the server reads as another kind (with why)", async () => {+ server = () => answer(403, { error: CONNECT_GPU_MESSAGE, code: "connect-gpu" }, { [CONNECT_GPU_HEADER]: "1" });+ const p = page();+ await p.upload();+ expect(p.seen.map((s) => s?.uploading ?? null)).toEqual([true, null]);+ server = () => answer(201, { id: "a1", url: "/api/files/uploads/a1.png", kind: "image" });+ toasts.error.length = 0;+ await p.upload(film("cover.wav"));+ expect(p.now()).toBeNull();+ expect(toasts.error).toEqual(["Audio only — drop a sound file here"]);+ });++ it("a finished upload gives the soundtrack its address and keeps the file's name", async () => {+ server = () => answer(201, { id: "a2", url: "/api/files/uploads/a2.wav", kind: "audio" });+ const p = page();+ await p.upload();+ expect(p.now()).toMatchObject({ ref: "/api/files/uploads/a2.wav", preview: "/api/files/uploads/a2.wav", kind: "audio", name: "Film.wav", id: p.seen[0]?.id });+ expect(p.now()?.uploading).toBeUndefined();+ });++ it("a soundtrack removed or replaced while it uploads stays as it is when the answer comes", async () => {+ let reply: (r: Response) => void = () => {};+ server = () => new Promise<Response>((r) => (reply = r));+ const p = page();+ const removed = p.upload();+ p.remove();+ reply(answer(201, { id: "a3", url: "/api/files/uploads/a3.wav", kind: "audio" }));+ await removed;+ expect(p.now()).toBeNull();+ // Replaced: the newer file stays, whatever the older one's answer.+ const older = p.upload(film("Older.wav"));+ const refuse = reply;+ server = () => answer(201, { id: "a4", url: "/api/files/uploads/a4.wav", kind: "audio" });+ await p.upload(film("Newer.wav"));+ refuse(answer(401, { error: GUEST_RUN_MESSAGE }, { [GUEST_HEADER]: "1" }));+ await older;+ expect(p.now()).toMatchObject({ ref: "/api/files/uploads/a4.wav", name: "Newer.wav" });+ });+});