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.

Audio: old Speech links on /audio still open Speech

Adarshf38736bef210
diff --git a/src/lib/hubs.ts b/src/lib/hubs.ts
index 60a31e05..1a057ab3 100644
--- a/src/lib/hubs.ts
+++ b/src/lib/hubs.ts
@@ -60,6 +60,14 @@ export const HUB_MODES: Record<HubKind, HubMode[]> = {
],
};
+/**
+ * A hub whose own URL opened another mode before, and the link params only that mode reads: /audio opened on Speech
+ * until Clean up voice came first, so an old `/audio?voice=…`, `?prompt=…` or `?model=…` link opens Speech (src/proxy.ts).
+ */
+export const FORMER_HOME: Partial<Record<HubKind, { mode: string; params: readonly string[] }>> = {
+ audio: { mode: "speech", params: ["voice", "prompt", "model", "preset", "example", "lyrics"] },
+};
+
/** The URL of one mode: the hub itself for the first one, else /<hub>/<mode>. */
export function modeHref(kind: HubKind, mode: string, query?: Record<string, string>): string {
const path = HUB_MODES[kind][0].id === mode ? `/${kind}` : `/${kind}/${mode}`;
diff --git a/src/proxy.ts b/src/proxy.ts
index d7793d41..3d847039 100644
--- a/src/proxy.ts
+++ b/src/proxy.ts
@@ -1,6 +1,6 @@
import { NextResponse, type NextRequest } from "next/server";
import { APPS } from "@/lib/catalog/apps";
-import { modeHref, type HubKind } from "@/lib/hubs";
+import { FORMER_HOME, modeHref, type HubKind } from "@/lib/hubs";
import { hiddenStarterPage, recordForPath, unknownHubMode, unknownStarterPage } from "@/lib/record-pages";
import { countsAsView, SHARE_VIEW_HEADER, shareRoute } from "@/lib/share";
import {
@@ -328,14 +328,22 @@ function openShare(request: NextRequest, token: string, file: boolean): NextResp
/**
* An old `/audio?mode=music` link (any case: ?mode=Music too): that mode's own page, without the mode in its query.
- * An unknown mode lands on the hub's 404 (unknownHubMode).
+ * An unknown mode lands on the hub's 404 (unknownHubMode). An old link to the mode the hub opened on before, known by
+ * the params only that mode reads (`/audio?voice=…` is Speech's, FORMER_HOME), opens that mode with its whole query.
*/
function hubModeLink(request: NextRequest): URL | null {
const kind = /^\/(audio|video-tools|upscale)\/?$/.exec(request.nextUrl.pathname)?.[1] as HubKind | undefined;
- const mode = kind && request.nextUrl.searchParams.get("mode")?.trim().toLowerCase();
+ const sp = request.nextUrl.searchParams;
+ const former = kind ? FORMER_HOME[kind] : undefined;
+ if (kind && former && !sp.has("mode") && former.params.some((k) => sp.has(k))) {
+ const url = new URL(modeHref(kind, former.mode), request.url);
+ url.search = request.nextUrl.search;
+ return url;
+ }
+ const mode = kind && sp.get("mode")?.trim().toLowerCase();
if (!kind || !mode || !/^[a-z0-9-]+$/.test(mode)) return null;
const url = new URL(modeHref(kind, mode), request.url);
- for (const [k, v] of request.nextUrl.searchParams) if (k !== "mode") url.searchParams.append(k, v);
+ for (const [k, v] of sp) if (k !== "mode") url.searchParams.append(k, v);
return url;
}
diff --git a/tests/e2e/audio-first.mjs b/tests/e2e/audio-first.mjs
index 5714c1e0..0852bbab 100644
--- a/tests/e2e/audio-first.mjs
+++ b/tests/e2e/audio-first.mjs
@@ -7,7 +7,7 @@
// covers or clips).
// 2. The other tabs still open their own pages (Speech at /audio/speech, Music), and Clean up voice brings /audio back.
// 3. Old links: /audio/clean is the same tool with its tab selected; /audio?mode=speech and ?mode=music land on their
-// pages; /audio/speech?voice=… keeps the voice for the composer.
+// pages; links made for Speech when it was /audio (/audio?voice=…, ?prompt=…, ?model=…) open Speech, query kept.
// 4. The Studios menu (desktop launcher, phone sheet's Sound chip) lists Clean up voice right after the Audio studio,
// and search for "audio" shows Audio, then Clean up voice.
import fs from "node:fs";
@@ -101,6 +101,18 @@ for (const [label, device] of [
}
await openRoute(p, `${app}/audio/speech`);
check(await p.getByRole("heading", { name: "Give it a voice" }).first().isVisible(), `${label}: /audio/speech is the Speech composer`);
+ // Links made for Speech when it was /audio (a voice sample, words, a model from search) still open Speech.
+ for (const q of ["?voice=%2Fapi%2Ffiles%2Fuploads%2Fa.wav", "?prompt=Hello%20there", "?model=elevenlabs-v4"]) {
+ await openRoute(p, `${app}/audio${q}`);
+ const speech = await p.getByRole("heading", { name: "Give it a voice" }).first().isVisible();
+ // The same query (the composer may write it back as "Hello+there").
+ const kept = new URL(p.url()).searchParams.toString() === new URLSearchParams(q).toString();
+ check(new URL(p.url()).pathname === "/audio/speech" && kept && speech, `${label}: an old /audio${q} link opens Speech`, path_(p));
+ if (q.startsWith("?prompt=")) {
+ const words = await p.locator("textarea").first().inputValue().catch(() => "");
+ check(words.includes("Hello there"), `${label}: its words are in the composer`, words.slice(0, 40));
+ }
+ }
// 4. The menus and search.
if (label === "1440") {
diff --git a/tests/security-lows.test.ts b/tests/security-lows.test.ts
index c193ea7f..5d6781d8 100644
--- a/tests/security-lows.test.ts
+++ b/tests/security-lows.test.ts
@@ -224,6 +224,15 @@ describe("L-2: an unknown record or link answers 404 behind an HTTPS reverse pro
expect(mode.status).toBe(307);
expect(new URL(mode.headers.get("location")!, "https://fuobe.example").pathname).toBe("/audio/music");
expect(new URL(mode.headers.get("location")!, "https://fuobe.example").search).toBe("?x=1");
+ // /audio opens on Clean up voice: an old link to Speech there (its voice, words or model) opens Speech, query kept.
+ for (const q of ["?voice=%2Fapi%2Ffiles%2Fa.wav", "?prompt=Hello", "?model=elevenlabs-v4&x=1"]) {
+ const old = at(`https://fuobe.example/audio${q}`);
+ expect(old.status, q).toBe(307);
+ const to = new URL(old.headers.get("location")!, "https://fuobe.example");
+ expect(to.pathname + to.search, q).toBe(`/audio/speech${q}`);
+ }
+ // Clean up voice's own hand-off (?audio=, ?video=) stays on /audio.
+ expect(at("https://fuobe.example/audio?audio=%2Fapi%2Ffiles%2Fa.wav").headers.get("location")).toBeNull();
// A plain-HTTP install keeps the rewrite to the app's own 404 pages.
expect(proxy(new NextRequest("http://localhost:3000/apps/does-not-exist")).headers.get("x-middleware-rewrite")).toMatch(/_fuobe-not-found$/);
});