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
This commit is contained in:
78
dashboard/src/app/api/settings/route.ts
Normal file
78
dashboard/src/app/api/settings/route.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import {
|
||||
loadSettings,
|
||||
saveSettings,
|
||||
prepareCivitaiUrl,
|
||||
type DashboardSettings,
|
||||
} from "@/lib/downloads";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const runtime = "nodejs";
|
||||
|
||||
/**
|
||||
* GET /api/settings
|
||||
*
|
||||
* Returns the persisted dashboard settings (civitai token etc).
|
||||
*
|
||||
* NOTE: The civitai token is returned in plain text. The dashboard has no
|
||||
* auth and is intended for use within a trusted tailnet only (Tailscale
|
||||
* serve on port 8090). If you expose this externally, add auth first.
|
||||
*/
|
||||
export async function GET() {
|
||||
const settings = await loadSettings();
|
||||
return NextResponse.json({ settings });
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /api/settings
|
||||
*
|
||||
* Body: Partial<DashboardSettings> — only the fields you want to change.
|
||||
*
|
||||
* Common usage:
|
||||
* PUT { civitaiToken: "abc123..." }
|
||||
*/
|
||||
export async function PUT(req: NextRequest) {
|
||||
const body = (await req.json()) as Partial<DashboardSettings>;
|
||||
const current = await loadSettings();
|
||||
const next: DashboardSettings = {
|
||||
civitaiToken: body.civitaiToken ?? current.civitaiToken,
|
||||
};
|
||||
await saveSettings(next);
|
||||
return NextResponse.json({ settings: next });
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/settings
|
||||
*
|
||||
* Body: { action: "preview-url", url: "<civitai URL>" }
|
||||
*
|
||||
* Returns what we'd transform the URL into (without actually starting a
|
||||
* download). Useful for the frontend to show the user "this URL will become
|
||||
* this" before clicking Download.
|
||||
*/
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = (await req.json()) as {
|
||||
action: "preview-url";
|
||||
url?: string;
|
||||
};
|
||||
|
||||
if (body.action === "preview-url") {
|
||||
if (!body.url) {
|
||||
return NextResponse.json(
|
||||
{ ok: false, error: "url required" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
const settings = await loadSettings();
|
||||
const result = prepareCivitaiUrl(body.url, settings.civitaiToken || "");
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
original: body.url,
|
||||
transformed: result.url,
|
||||
note: result.note,
|
||||
isCivitai: result.note.length > 0 || result.url !== body.url,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({ error: "unknown action" }, { status: 400 });
|
||||
}
|
||||
Reference in New Issue
Block a user