Spaces:
Runtime error
Runtime error
Download src/app/api/capabilities/route.ts from RalphThings/yue2-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/RalphThings/yue2-studio/resolve/main/src/app/api/capabilities/route.ts
- Command line
-
hf download hf://spaces/RalphThings/yue2-studio/src/app/api/capabilities/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/RalphThings/yue2-studio/resolve/main/src/app/api/capabilities/route.ts
2.3 kB
| import { readFile } from "node:fs/promises"; | |
| import { NextResponse } from "next/server"; | |
| import { | |
| COMFY_URL, | |
| DEFAULT_CHECKPOINT, | |
| DEFAULT_ENCODER, | |
| IS_MOCK, | |
| fetchObjectInfo, | |
| } from "@/lib/comfy/client"; | |
| import type { ComfyCapabilities } from "@/lib/types"; | |
| export const runtime = "nodejs"; | |
| export const dynamic = "force-dynamic"; | |
| /** | |
| * When ComfyUI runs beside this app (the Space), its console is the only place | |
| * a startup failure is written. Reading the tail back means a broken engine | |
| * says why on the page instead of just showing an unreachable badge. | |
| */ | |
| async function engineLogTail(): Promise<string | null> { | |
| const path = process.env.ENGINE_LOG; | |
| if (!path) return null; | |
| try { | |
| const text = await readFile(path, "utf8"); | |
| const lines = text | |
| .split("\n") | |
| .map((line) => line.trimEnd()) | |
| .filter(Boolean); | |
| if (!lines.length) return null; | |
| return lines.slice(-12).join("\n"); | |
| } catch { | |
| return null; | |
| } | |
| } | |
| function buildStamp(): string | null { | |
| return process.env.BUILD_STAMP ?? null; | |
| } | |
| export async function GET() { | |
| if (IS_MOCK) { | |
| const payload: ComfyCapabilities = { | |
| connected: true, | |
| url: "mock", | |
| mock: true, | |
| checkpoints: [DEFAULT_CHECKPOINT], | |
| audioEncoders: [DEFAULT_ENCODER], | |
| loras: [], | |
| missingNodes: [], | |
| error: null, | |
| engineLog: null, | |
| buildStamp: buildStamp(), | |
| }; | |
| return NextResponse.json(payload); | |
| } | |
| try { | |
| const info = await fetchObjectInfo(); | |
| const payload: ComfyCapabilities = { | |
| connected: true, | |
| url: COMFY_URL, | |
| mock: false, | |
| checkpoints: info.checkpoints, | |
| audioEncoders: info.audioEncoders, | |
| loras: info.loras, | |
| missingNodes: info.missingNodes, | |
| error: null, | |
| engineLog: null, | |
| buildStamp: buildStamp(), | |
| }; | |
| return NextResponse.json(payload); | |
| } catch (error) { | |
| const payload: ComfyCapabilities = { | |
| connected: false, | |
| url: COMFY_URL, | |
| mock: false, | |
| checkpoints: [], | |
| audioEncoders: [], | |
| loras: [], | |
| missingNodes: [], | |
| error: error instanceof Error ? error.message : "ComfyUI is not reachable", | |
| engineLog: await engineLogTail(), | |
| buildStamp: buildStamp(), | |
| }; | |
| return NextResponse.json(payload, { status: 200 }); | |
| } | |
| } | |