fix: comfyui mount uses HOST_PROJECT_PATH + add CivitAI download support #10
Reference in New Issue
Block a user
Delete Branch "fix/comfy-mount-and-civitai"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
1. ComfyUI mount fix
Проблема
Когда dashboard вызывает
docker compose up -d comfyui, comfyui service использует volume mounts${COMFY_BASE_HOST:-./gpu/comfy}и${COMFY_RUN_HOST:-./comfyui/run}. Без явных env overrides compose резолвил к./gpu/comfyотносительно CWD dashboard контейнера (=/projectвнутри контейнера). Docker daemon хоста пытался смонтировать/project/gpu/comfy— но/projectсуществует только внутри dashboard контейнера, не на хосте.Результат: comfyui монтировался в несуществующие пути на хосте, все модели отсутствовали.
Fix
startService('comfyui')теперь явно передаёт те же env vars что иgpuctl start comfy, mirroringssh/scripts/comfy.sh:COMFY_BASE_HOST=$HOST_PROJECT_PATH/gpu/comfyCOMFY_RUN_HOST=$HOST_PROJECT_PATH/comfyui/runЭти передаются как extra env в
runCompose, который forwards их в compose subprocess. Compose резолвит volume mounts к реальному host path.2. CivitAI download support
Почему это нужно
CivitAI URLs особенные:
https://civitai.com/models/12345— это model PAGE (HTML), не файл. curl скачал бы HTML страницу вместо .gguf.https://civitai.com/api/download/models/12345— возвращает 302 redirect на signed Cloudflare URL.?token=XXX. Без него NSFW / gated модели падают с 401.civitai.red— зеркало, не принимает API requests так же.Fix
Settings storage
Новый
DashboardSettingsinterface сcivitaiToken: string. Persisted вgpu/dashboard/settings.json(отдельно от llama config — настройки скачивания не должны быть частью llama preset).URL transformation
prepareCivitaiUrl(rawUrl, token)— handle'ит все CivitAI URL shapes:https://civitai.com/models/12345(model page) → конвертирует вhttps://civitai.com/api/download/models/12345(preserves?modelVersionId=...query param)https://civitai.com/api/download/models/12345→ append?token=XXXесли нетhttps://civitai.red/models/12345→ normalize host на civitai.com (mirror не принимает API requests так же)Returns
{ url, note }где note объясняет что мы сделали.API routes (new)
/api/settings:GET— returns persisted settings (civitai token и т.д.)PUT— updates settings (body:{ civitaiToken: '...' })POST { action: 'preview-url', url: '...' }— returns что URL станет после transform, без запуска download. Используется frontend'ом для live URL preview пока юзер печатает.Frontend
POST /api/settings {action:'preview-url'}. Если URL будет трансформирован (например civitai.com/models/12345 → civitai.com/api/download/models/12345?token=...), preview card появляется под input'ом с transformed URL + note.originalUrl(зачёркнутый) →url(реально curl'ed), плюсurlNoteкак italic text. Юзер видит что произошло с его pasted URL.Verification
npm run build— OK, 26 routes (1 new/api/settingsroute)bash dashboard/validate-build.sh— все 8 COPY источников ✓, standalone ✓После мержа
Для ComfyUI:
docker inspect <comfyui-container> | grep Mounts— должно показать $HOST_PROJECT_PATH/gpu/comfy и $HOST_PROJECT_PATH/comfyui/runДля CivitAI:
Files changed
dashboard/src/lib/docker.ts— добавил DASHBOARD_SETTINGS_PATH export, startService() теперь передаёт COMFY_BASE_HOST / COMFY_RUN_HOST для comfyuidashboard/src/lib/downloads.ts— new DashboardSettings interface, loadSettings/saveSettings, prepareCivitaiUrl, startModelDownload integrates URL transformationdashboard/src/app/api/settings/route.ts— new (GET/PUT/POST preview)dashboard/src/app/page.tsx— settings state, civitai token UI, URL preview, DownloadJobRow показывает originalUrl + urlNote## 1. ComfyUI mount fix ### Problem When the dashboard called `docker compose up -d comfyui`, the comfyui service's volume mounts used ${COMFY_BASE_HOST:-./gpu/comfy} and ${COMFY_RUN_HOST:-./comfyui/run}. Without explicit env overrides, compose resolved these to './gpu/comfy' relative to the CWD of the dashboard container (= /project inside the container). Docker daemon on the host tried to mount /project/gpu/comfy — but /project only exists inside the dashboard container, not on the host. The result: comfyui mounted to non-existent paths on the host, all models missing. ### Fix `startService('comfyui')` now explicitly passes the same env vars that `gpuctl start comfy` does, mirroring `ssh/scripts/comfy.sh`: - COMFY_BASE_HOST=$HOST_PROJECT_PATH/gpu/comfy - COMFY_RUN_HOST=$HOST_PROJECT_PATH/comfyui/run These are passed as extra env to `runCompose`, which forwards them to the compose subprocess. Compose then resolves the volume mounts to the real host path. ## 2. CivitAI download support ### Why CivitAI URLs are special: - `https://civitai.com/models/12345` is a model PAGE (HTML), not the file. curl would download the HTML page instead of the .gguf. - The actual file is at `https://civitai.com/api/download/models/12345` which returns a 302 redirect to a signed Cloudflare URL. - Downloads require an API token: `?token=XXX`. Without it, NSFW / gated models fail with 401. - `civitai.red` is a mirror — it doesn't accept API requests the same way. ### Fix #### Settings storage New `DashboardSettings` interface with `civitaiToken: string`. Persisted to `gpu/dashboard/settings.json` (separate from the llama config — download settings shouldn't be part of a llama preset). - `loadSettings()` / `saveSettings()` in `dashboard/src/lib/downloads.ts` - Cache like the .env loader (read once per process lifetime) #### URL transformation `prepareCivitaiUrl(rawUrl, token)` — handles all CivitAI URL shapes: 1. `https://civitai.com/models/12345` (model page) → converts to `https://civitai.com/api/download/models/12345` (preserves any `?modelVersionId=...` query param) 2. `https://civitai.com/api/download/models/12345` → appends `?token=XXX` if missing 3. `https://civitai.red/models/12345` → normalizes host to civitai.com (mirror doesn't accept API requests the same way) 4. Non-CivitAI URLs (HuggingFace, GitHub releases, etc.) → passed through unchanged Returns `{ url, note }` where note explains what we did (e.g. 'converted model page → API download URL, added API token'). #### startModelDownload integration `startModelDownload()` now: 1. Loads settings (to get the token) 2. Calls `prepareCivitaiUrl()` on the input URL 3. Uses the transformed URL for curl 4. Records `originalUrl` and `urlNote` on the job object (shown in UI) #### API routes (new) `/api/settings`: - `GET` — returns the persisted settings (civitai token etc) - `PUT` — updates settings (body: `{ civitaiToken: '...' }`) - `POST { action: 'preview-url', url: '...' }` — returns what the URL would be transformed into, without starting a download. Used by the frontend for live URL preview as the user types. #### Frontend - **Settings UI** in the Models tab: 'CivitAI token' button (with badge showing 'set' / 'empty'). Click to expand a form with password input, Save / Clear buttons, and a link to https://civitai.com/user/account to get a token. - **URL preview**: as the user types in the download URL field, a debounced call to `POST /api/settings {action:'preview-url'}` runs. If the URL will be transformed (e.g. civitai.com/models/12345 → civitai.com/api/download/models/12345?token=...), a preview card appears below the input showing the transformed URL + note. - **DownloadJobRow**: shows `originalUrl` (struck through) → `url` (the actual URL curled), plus the `urlNote` as italic text. So the user can see what happened to their pasted URL. ## Verification - `npm run build` — OK, all 26 routes (1 new /api/settings route) - `bash dashboard/validate-build.sh` — all 8 COPY sources ✓, standalone ✓ ## After deploy ```sh git pull && sh build.sh docker compose up -d --force-recreate dashboard ``` For ComfyUI: 1. Click 'Start Comfy' (or Start button in System tab → comfyui row) 2. Check `docker inspect <comfyui-container> | grep Mounts` — should show $HOST_PROJECT_PATH/gpu/comfy and $HOST_PROJECT_PATH/comfyui/run For CivitAI: 1. Open Models tab → 'CivitAI token' button → paste your token from https://civitai.com/user/account → API Keys → Save 2. Paste any CivitAI URL (model page or API download URL) in the URL field 3. Watch the URL preview card show the transformed URL 4. Click Download — file fetches with token auth ## Files changed - dashboard/src/lib/docker.ts — added DASHBOARD_SETTINGS_PATH export, startService() now passes COMFY_BASE_HOST / COMFY_RUN_HOST for comfyui - dashboard/src/lib/downloads.ts — new DashboardSettings interface, loadSettings / saveSettings, prepareCivitaiUrl, startModelDownload integrates URL transformation - dashboard/src/app/api/settings/route.ts — new (GET/PUT/POST preview) - dashboard/src/app/page.tsx — settings state, civitai token UI, URL preview, DownloadJobRow shows originalUrl + urlNote