fix: comfyui mount uses HOST_PROJECT_PATH + add CivitAI download support #10

Merged
mikan merged 1 commits from fix/comfy-mount-and-civitai into master 2026-10-24 01:55:42 +00:00
Collaborator

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, mirroring ssh/scripts/comfy.sh:

  • COMFY_BASE_HOST=$HOST_PROJECT_PATH/gpu/comfy
  • COMFY_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.
  • Скачивание требует API token: ?token=XXX. Без него NSFW / gated модели падают с 401.
  • civitai.red — зеркало, не принимает API requests так же.

Fix

Settings storage

Новый DashboardSettings interface с civitaiToken: string. Persisted в gpu/dashboard/settings.json (отдельно от llama config — настройки скачивания не должны быть частью llama preset).

URL transformation

prepareCivitaiUrl(rawUrl, token) — handle'ит все CivitAI URL shapes:

  1. https://civitai.com/models/12345 (model page) → конвертирует в https://civitai.com/api/download/models/12345 (preserves ?modelVersionId=... query param)
  2. https://civitai.com/api/download/models/12345 → append ?token=XXX если нет
  3. https://civitai.red/models/12345 → normalize host на civitai.com (mirror не принимает API requests так же)
  4. Non-CivitAI URLs (HuggingFace, GitHub releases, и т.д.) → passed through unchanged

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

  • Settings UI в Models tab: кнопка 'CivitAI token' (с badge 'set' / 'empty'). Клик → форма с password input, Save / Clear, и ссылка на https://civitai.com/user/account для получения token'а.
  • URL preview: пока юзер печатает в URL поле, debounced call к POST /api/settings {action:'preview-url'}. Если URL будет трансформирован (например civitai.com/models/12345 → civitai.com/api/download/models/12345?token=...), preview card появляется под input'ом с transformed URL + note.
  • DownloadJobRow: показывает originalUrl (зачёркнутый) → url (реально curl'ed), плюс urlNote как italic text. Юзер видит что произошло с его pasted URL.

Verification

  • npm run build — OK, 26 routes (1 new /api/settings route)
  • bash dashboard/validate-build.sh — все 8 COPY источников ✓, standalone ✓

После мержа

git pull && sh build.sh
docker compose up -d --force-recreate dashboard

Для ComfyUI:

  1. Нажми 'Start Comfy' (или Start button в System tab → comfyui row)
  2. Проверь docker inspect <comfyui-container> | grep Mounts — должно показать $HOST_PROJECT_PATH/gpu/comfy и $HOST_PROJECT_PATH/comfyui/run

Для CivitAI:

  1. Открой Models tab → 'CivitAI token' кнопка → вставь token с https://civitai.com/user/account → API Keys → Save
  2. Вставь любой CivitAI URL (model page или API download URL) в URL поле
  3. Смотри как URL preview card показывает transformed URL
  4. Нажми Download — файл скачается с token auth

Files changed

  • dashboard/src/lib/docker.ts — добавил DASHBOARD_SETTINGS_PATH export, startService() теперь передаёт COMFY_BASE_HOST / COMFY_RUN_HOST для 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 показывает originalUrl + urlNote
## 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`, mirroring `ssh/scripts/comfy.sh`: - `COMFY_BASE_HOST=$HOST_PROJECT_PATH/gpu/comfy` - `COMFY_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. - Скачивание требует API token: `?token=XXX`. Без него NSFW / gated модели падают с 401. - `civitai.red` — зеркало, не принимает API requests так же. ### Fix #### Settings storage Новый `DashboardSettings` interface с `civitaiToken: string`. Persisted в `gpu/dashboard/settings.json` (отдельно от llama config — настройки скачивания не должны быть частью llama preset). #### URL transformation `prepareCivitaiUrl(rawUrl, token)` — handle'ит все CivitAI URL shapes: 1. `https://civitai.com/models/12345` (model page) → конвертирует в `https://civitai.com/api/download/models/12345` (preserves `?modelVersionId=...` query param) 2. `https://civitai.com/api/download/models/12345` → append `?token=XXX` если нет 3. `https://civitai.red/models/12345` → normalize host на civitai.com (mirror не принимает API requests так же) 4. Non-CivitAI URLs (HuggingFace, GitHub releases, и т.д.) → passed through unchanged 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 - **Settings UI** в Models tab: кнопка 'CivitAI token' (с badge 'set' / 'empty'). Клик → форма с password input, Save / Clear, и ссылка на https://civitai.com/user/account для получения token'а. - **URL preview**: пока юзер печатает в URL поле, debounced call к `POST /api/settings {action:'preview-url'}`. Если URL будет трансформирован (например civitai.com/models/12345 → civitai.com/api/download/models/12345?token=...), preview card появляется под input'ом с transformed URL + note. - **DownloadJobRow**: показывает `originalUrl` (зачёркнутый) → `url` (реально curl'ed), плюс `urlNote` как italic text. Юзер видит что произошло с его pasted URL. ## Verification - `npm run build` — OK, 26 routes (1 new `/api/settings` route) - `bash dashboard/validate-build.sh` — все 8 COPY источников ✓, standalone ✓ ## После мержа ```sh git pull && sh build.sh docker compose up -d --force-recreate dashboard ``` ### Для ComfyUI: 1. Нажми 'Start Comfy' (или Start button в System tab → comfyui row) 2. Проверь `docker inspect <comfyui-container> | grep Mounts` — должно показать $HOST_PROJECT_PATH/gpu/comfy и $HOST_PROJECT_PATH/comfyui/run ### Для CivitAI: 1. Открой Models tab → 'CivitAI token' кнопка → вставь token с https://civitai.com/user/account → API Keys → Save 2. Вставь любой CivitAI URL (model page или API download URL) в URL поле 3. Смотри как URL preview card показывает transformed URL 4. Нажми Download — файл скачается с token auth ## Files changed - `dashboard/src/lib/docker.ts` — добавил DASHBOARD_SETTINGS_PATH export, startService() теперь передаёт COMFY_BASE_HOST / COMFY_RUN_HOST для 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 показывает originalUrl + urlNote
super-z-bot added 1 commit 2026-10-24 01:54:07 +00:00
## 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
mikan merged commit b0e03cdb99 into master 2026-10-24 01:55:42 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mikan/GPU-Node#10