fix(dashboard): restore GET /api/models + fs fallbacks for comfy models/types
## Three bugs found from /api/debug output User reported: 'in UI ни комфи (причем и типы и модели) ни ллама модели не видны' — even though /api/debug shows the directories exist with files in them. ### Bug 1: GET /api/models was deleted In PR #5 I added `DELETE /api/models?name=...` but accidentally removed the existing `GET /api/models` handler when I rewrote the file with the Write tool. The frontend was getting 405 Method Not Allowed, but `refreshModels()` silently swallowed the error (try/catch with no logging). Fix: restore the GET handler alongside DELETE. ### Bug 2: refreshComfyModels() was never called The initial useEffect only called refreshConfig, refreshModels, refreshComfyTypes, and an interval for refreshComfyQueue. refreshComfyModels was defined as a useCallback but never invoked on mount — so the Comfy models table was always empty until the user clicked Refresh manually. Fix: add refreshComfyModels() to the initial useEffect. ### Bug 3: /api/comfy/types and /api/comfy/models fail when model-worker is offline Both endpoints proxied to `docker exec model-worker python3 /app/worker.py` — which fails (returns empty / error) when the model-worker container isn't running (e.g. during sleep mode, or right after a reboot before wake). The /api/debug endpoint showed that the directories exist on disk via fs.readdir — so we have the data, just weren't using it. Fix: add fs-based fallbacks in dashboard/src/lib/docker.ts: - `listComfyTypesFromFs()` — reads subdirectories of /project/gpu/comfy/models directly. Same as what `worker.py types` does, but no docker exec required. - `listComfyModelsFromFs(type?)` — walks each subdirectory and lists files. Same as what `worker.py list --json` does, but no docker exec. - `listComfyModels()` and `getComfyTypes()` now try the worker first, then fall back to fs. If both succeed, the worker's output wins (it filters out metadata files like .txt). - New export `COMFY_MODELS_DIR` — the internal mount path, used by both the fallback functions and /api/debug. ### Bonus: error visibility All `refresh*()` callbacks in page.tsx now `console.error` on failure instead of silently swallowing. The next time something breaks, you'll see it in the browser DevTools console. ## Verification - `npm run build` — OK, all 19 routes (including restored GET /api/models) - `bash dashboard/validate-build.sh` — all 8 COPY sources ✓, standalone ✓ - /api/debug still works (uses the same fs approach) ## Files changed - dashboard/src/app/api/models/route.ts — restored GET handler - dashboard/src/app/page.tsx — added refreshComfyModels() to initial useEffect, console.error on refresh failures - dashboard/src/lib/docker.ts — added COMFY_MODELS_DIR export, fs-based fallbacks for comfy types/models, try-worker-first-then-fs flow
This commit is contained in:
@@ -4,6 +4,17 @@ import { deleteModel, listModels } from "@/lib/docker";
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
/**
|
||||
* GET /api/models
|
||||
*
|
||||
* Lists all .gguf files in gpu/llama_models/. Returns:
|
||||
* { models: [{ name, sizeBytes, sizeHuman, modifiedAt }] }
|
||||
*/
|
||||
export async function GET() {
|
||||
const models = await listModels();
|
||||
return NextResponse.json({ models });
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /api/models?name=foo.gguf
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user