fix: comfyui mount uses HOST_PROJECT_PATH + add CivitAI download support #10
Merged
mikan
merged 1 commits from 2026-10-24 01:55:42 +00:00
fix/comfy-mount-and-civitai into master
1 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
12fb97314b |
fix: comfyui mount uses HOST_PROJECT_PATH + add CivitAI download support
## 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
|