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.

Workers: download the worker as a zip, and fix the e2e label selector

Adarsh129fbf0ea3d7
diff --git a/src/app/api/admin/workers/download/route.ts b/src/app/api/admin/workers/download/route.ts
new file mode 100644
index 00000000..33fd0d36
--- /dev/null
+++ b/src/app/api/admin/workers/download/route.ts
@@ -0,0 +1,60 @@
+import { connection } from "next/server";
+import { isOwnerRequest, sessionCookieOf } from "@/server/auth";
+import fs from "node:fs";
+import path from "node:path";
+
+/**
+ * Download the worker program as a zip, so its version always matches the server's (docs/gpu-workers.md).
+ * The zip contains bin/ with the fuobe.mjs entry point, bin/lib/commands.mjs, bin/lib/worker/ and the
+ * package.json that names the dependencies (`better-sqlite3` is not needed on the worker; the runner
+ * is bundled). Owner only.
+ */
+export async function GET(request: Request) {
+ await connection();
+ if (!isOwnerRequest(request, sessionCookieOf(request)))
+ return Response.json({ error: "Only the studio's owner manages workers" }, { status: 403 });
+
+ // Dynamic import so the zip helper is loaded only for this route.
+ const { zipFiles } = await import("../../../../../../bin/lib/zip.mjs");
+
+ const root = process.cwd();
+ const files: { name: string; data: Buffer }[] = [];
+
+ const add = (rel: string) => {
+ const abs = path.join(root, rel);
+ if (fs.existsSync(abs)) files.push({ name: rel, data: fs.readFileSync(abs) });
+ };
+
+ // The worker's entry point and its commands dispatcher.
+ add("bin/fuobe.mjs");
+ add("bin/lib/commands.mjs");
+
+ // bin/lib/worker/ — the worker shell and the transpiled runner.
+ const workerDir = path.join(root, "bin/lib/worker");
+ if (fs.existsSync(workerDir)) {
+ const walk = (dir: string, prefix: string) => {
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
+ const rel = `${prefix}/${entry.name}`;
+ if (entry.isDirectory()) walk(path.join(dir, entry.name), rel);
+ else files.push({ name: rel, data: fs.readFileSync(path.join(dir, entry.name)) });
+ }
+ };
+ walk(workerDir, "bin/lib/worker");
+ }
+
+ // A minimal package.json for the worker (no dev deps, no Next.js).
+ files.push({
+ name: "package.json",
+ data: Buffer.from(JSON.stringify({ name: "fuobe-worker", private: true, type: "module" }, null, 2)),
+ });
+
+ const buf = zipFiles(files);
+ return new Response(buf, {
+ headers: {
+ "Content-Type": "application/zip",
+ "Content-Disposition": 'attachment; filename="fuobe-worker.zip"',
+ "Content-Length": String(buf.length),
+ "Cache-Control": "no-store",
+ },
+ });
+}
diff --git a/tests/e2e/computer-mode.mjs b/tests/e2e/computer-mode.mjs
index 7c95af1e..28bf25a0 100644
--- a/tests/e2e/computer-mode.mjs
+++ b/tests/e2e/computer-mode.mjs
@@ -160,7 +160,7 @@ try {
await dialog.getByRole("button", { name: "Find my ComfyUI" }).click();
await dialog.getByText("Found ComfyUI. One step to use it here:").waitFor({ timeout: 20_000 });
check("ComfyUI that this page can't use yet: one step, Fuobe Connect from ComfyUI-Manager", await dialog.getByText("Install Fuobe Connect in ComfyUI-Manager").isVisible());
- check("the step names the Manager's search term and a git address to copy", (await dialog.getByLabel("the search term").first().textContent()) === "Fuobe Connect" && /git clone https:\/\//.test((await dialog.getByLabel("the git command").textContent()) ?? ""));
+ check("the step names the Manager's search term and a git address to copy", (await dialog.getByLabel("the search term").first().textContent()) === "Fuobe Connect" && /git clone https:\/\//.test((await dialog.getByLabel("the git command", { exact: true }).textContent()) ?? ""));
check("the start setting and the guard are not shown until Advanced is opened", !(await dialog.getByRole("button", { name: "Download start file" }).isVisible()) && !(await dialog.getByText("--enable-cors-header").first().isVisible()));
await page.screenshot({ path: path.join(shots, "2-needs-setting.png") });
await dialog.getByRole("button", { name: /Advanced: a start setting instead/ }).click();