feat(dashboard): download .gguf models from URL with live progress #9
Reference in New Issue
Block a user
Delete Branch "feature/llama-model-download"
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?
Что
Добавил секцию 'Download from URL' в Models tab. Вставляешь URL .gguf файла (HuggingFace, GitHub releases, любой прямой URL) — дашборд скачивает в
gpu/llama_models/с live progress, speed, ETA, и cancel кнопкой.Backend
dashboard/src/lib/downloads.ts(new)In-memory download tracker (single Node process, no DB needed).
startModelDownload(url, filenameOverride?)— валидирует URL (http/https only), санитайзит filename (.gguf only, no path traversal), spawn'ит curl:curl следует редиректам (HuggingFace, Cloudflare R2), падает на HTTP 4xx/5xx, пишет в
.partфайл для atomic rename на success.subscribeToJob(id, cb)— pub/sub для progress updatescancelDownload(id)— SIGTERM к curl, удаляет.partфайлlistJobs()/getJob(id)— read accesspublicJob(job)— стрипает internal fields перед возвратомProgress tracking:
--progress-barstderr для percent (формат#### 54.3%).partфайл для actual bytes downloaded (надёжнее чем парсинг curl)curl -Iдля Content-Length (total bytes)History: хранит последние 50 finished jobs (avoid memory bloat).
API routes (all under /api/models/download/)
POST /api/models/download— body:{url, filename?}, returns jobGET /api/models/download/status— все jobs (active + recent)GET /api/models/download/[id]/stream— SSE push of progress events:endevent когда job достиг terminal state.POST /api/models/download/[id]/cancel— SIGTERM'ит curl, удаляет.partDockerfile
Добавил
curlв apk add — нужен для самого скачивания.wgetуже был (используется в health checks).Frontend
ModelsTab additions
1.5 MB/s), elapsed time, Cancel buttonDownloadJobRow component
Reusable row для active и finished jobs. Два режима:
Main component state
downloadJobs: DownloadJob[]— full job listdownloadUrl: string— URL input statedownloadsActiveRef— guards SSE subscription lifecycledownloadSSERef— Map<jobId, EventSource> для cleanupOn mount, fetches existing download jobs (на случай page refresh mid-download). Для каждого active job открывает EventSource subscription. На
endevent закрывает SSE и refresh'ит models list (файл появился на диске).Handlers
handleDownload()— POST /api/models/download, затем start SSEhandleCancelDownload(id)— POST /api/models/download/[id]/cancel, закрывает SSE, refresh jobsrefreshDownloadJobs()— GET /api/models/download/status, manages SSE subscriptionsVerification
npm run build— OK, 25 routes (4 new download routes)bash dashboard/validate-build.sh— все 8 COPY источников ✓, standalone ✓После мержа
Открой Models tab, вставь URL типа
https://huggingface.co/bartowski/Qwen2.5-7B-Instruct-Q8_0.gguf(или любой прямой .gguf линк), нажми Download. Смотри progress live, отменить если надо.Файл автоматически появится в models list когда скачается.
Files changed
dashboard/src/lib/downloads.ts— new (download tracker + curl wrapper)dashboard/src/app/api/models/download/route.ts— new (POST start)dashboard/src/app/api/models/download/status/route.ts— new (GET list)dashboard/src/app/api/models/download/[id]/stream/route.ts— new (SSE)dashboard/src/app/api/models/download/[id]/cancel/route.ts— new (POST cancel)dashboard/Dockerfile— added curl to apk adddashboard/src/app/page.tsx— ModelsTab gets Download section, DownloadJobRow component, DownloadJob type, SSE-based handlers## What Adds a 'Download from URL' section to the Models tab. Paste a HuggingFace URL (or any direct .gguf URL) and the dashboard fetches it into gpu/llama_models/ with live progress, speed, ETA, and cancel support. ## Backend ### `dashboard/src/lib/downloads.ts` (new) In-memory download tracker. Single Node process, so no DB needed. - `startModelDownload(url, filenameOverride?)` — validates URL (http/https only), sanitizes filename (.gguf only, no path traversal), spawns curl: curl -L -f -S --progress-bar -o <dest>.part <url> curl follows redirects (HuggingFace, Cloudflare R2), fails on HTTP 4xx/5xx, writes to <dest>.part for atomic rename on success. - `subscribeToJob(id, cb)` — pub/sub for progress updates - `cancelDownload(id)` — sends SIGTERM to curl, deletes .part file - `listJobs()` / `getJob(id)` — read access - `publicJob(job)` — strips internal fields (_child, _subscribers) before returning to API caller Progress tracking: - Parses curl --progress-bar stderr for percent (looks like '#### 54.3%') - Periodically stats the .part file for actual bytes downloaded (more reliable than parsing curl output) - Does HEAD request via curl -I to get Content-Length for total bytes History: keeps last 50 finished jobs to avoid memory bloat. ### API routes (all under /api/models/download/) - `POST /api/models/download` — body: {url, filename?}, returns job - `GET /api/models/download/status` — returns all jobs (active + recent) - `GET /api/models/download/[id]/stream` — SSE push of progress events: event: progress data: {id, status, percent, bytesDownloaded, bytesTotal, ...} Plus 'end' event when job reaches terminal state. - `POST /api/models/download/[id]/cancel` — SIGTERMs curl, deletes .part ### Dockerfile Added `curl` to the apk add list — needed for the actual download. `wget` was already present (kept for compatibility with the rest of the codebase that uses it for health checks). ## Frontend ### ModelsTab additions - URL input + Download button — Enter to submit - 'Active downloads' list with progress bars, bytes downloaded / total, speed (e.g. '1.5 MB/s'), elapsed time, Cancel button - 'Recent' list (last 5 finished) — shows final size + duration ### DownloadJobRow component Reusable row for both active and finished jobs. Two modes: - Full (default): badge + filename + progress bar + stats + source URL link - Compact: smaller, just badge + filename + final size/duration ### Main component state - `downloadJobs: DownloadJob[]` — full job list - `downloadUrl: string` — URL input state - `downloadsActiveRef` — guards SSE subscription lifecycle - `downloadSSERef` — Map<jobId, EventSource> for cleanup On mount, fetches existing download jobs (in case page was refreshed mid-download). For each active job, opens an EventSource subscription. On 'end' event, closes the SSE and refreshes the models list (file should now be on disk). ### Handlers - `handleDownload()` — POST /api/models/download, then start SSE - `handleCancelDownload(id)` — POST /api/models/download/[id]/cancel, closes SSE, refreshes job list - `refreshDownloadJobs()` — GET /api/models/download/status, manages SSE subscriptions based on which jobs are active ## Verification - `npm run build` — OK, 25 routes (4 new download routes) - `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 ``` Open Models tab, paste a URL like 'https://huggingface.co/bartowski/Qwen2.5-7B-Instruct-Q8_0.gguf' (or any direct .gguf link), click Download. Watch progress live, cancel if needed. File appears in the models list automatically when download completes. ## Files changed - dashboard/src/lib/downloads.ts — new (download tracker + curl wrapper) - dashboard/src/app/api/models/download/route.ts — new (POST start) - dashboard/src/app/api/models/download/status/route.ts — new (GET list) - dashboard/src/app/api/models/download/[id]/stream/route.ts — new (SSE) - dashboard/src/app/api/models/download/[id]/cancel/route.ts — new (POST cancel) - dashboard/Dockerfile — added curl to apk add - dashboard/src/app/page.tsx — ModelsTab gets Download section, DownloadJobRow component, DownloadJob type, SSE-based handlers