feat(dashboard): download .gguf models from URL with live progress #9

Merged
mikan merged 1 commits from feature/llama-model-download into master 2026-10-24 01:40:19 +00:00
Collaborator

Что

Добавил секцию '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 -L -f -S --progress-bar -o <dest>.part <url>
    

    curl следует редиректам (HuggingFace, Cloudflare R2), падает на HTTP 4xx/5xx, пишет в .part файл для atomic rename на success.

  • subscribeToJob(id, cb) — pub/sub для progress updates

  • cancelDownload(id) — SIGTERM к curl, удаляет .part файл

  • listJobs() / getJob(id) — read access

  • publicJob(job) — стрипает internal fields перед возвратом

Progress tracking:

  • Парсит curl --progress-bar stderr для percent (формат #### 54.3%)
  • Периодически stats .part файл для actual bytes downloaded (надёжнее чем парсинг curl)
  • Делает HEAD request через 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 job
  • GET /api/models/download/status — все jobs (active + recent)
  • GET /api/models/download/[id]/stream — SSE push of progress events:
    event: progress
    data: {id, status, percent, bytesDownloaded, bytesTotal, ...}
    
    Плюс end event когда job достиг terminal state.
  • POST /api/models/download/[id]/cancel — SIGTERM'ит curl, удаляет .part

Dockerfile

Добавил curl в apk add — нужен для самого скачивания. wget уже был (используется в health checks).

Frontend

ModelsTab additions

  • URL input + Download button — Enter для submit
  • 'Active downloads' list с progress bar'ами, bytes downloaded / total, speed (например 1.5 MB/s), elapsed time, Cancel button
  • 'Recent' list (последние 5 finished) — показывает final size + duration

DownloadJobRow component

Reusable row для active и finished jobs. Два режима:

  • Full (default): badge + filename + progress bar + stats + source URL link
  • Compact: меньше, просто 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> для cleanup

On mount, fetches existing download jobs (на случай page refresh mid-download). Для каждого active job открывает EventSource subscription. На end event закрывает SSE и refresh'ит models list (файл появился на диске).

Handlers

  • handleDownload() — POST /api/models/download, затем start SSE
  • handleCancelDownload(id) — POST /api/models/download/[id]/cancel, закрывает SSE, refresh jobs
  • refreshDownloadJobs() — GET /api/models/download/status, manages SSE subscriptions

Verification

  • npm run build — OK, 25 routes (4 new download routes)
  • bash dashboard/validate-build.sh — все 8 COPY источников ✓, standalone ✓

После мержа

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

Открой 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 add
  • dashboard/src/app/page.tsx — ModelsTab gets Download section, DownloadJobRow component, DownloadJob type, SSE-based handlers
## Что Добавил секцию '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 -L -f -S --progress-bar -o <dest>.part <url> ``` curl следует редиректам (HuggingFace, Cloudflare R2), падает на HTTP 4xx/5xx, пишет в `.part` файл для atomic rename на success. - `subscribeToJob(id, cb)` — pub/sub для progress updates - `cancelDownload(id)` — SIGTERM к curl, удаляет `.part` файл - `listJobs()` / `getJob(id)` — read access - `publicJob(job)` — стрипает internal fields перед возвратом Progress tracking: - Парсит curl `--progress-bar` stderr для percent (формат `#### 54.3%`) - Периодически stats `.part` файл для actual bytes downloaded (надёжнее чем парсинг curl) - Делает HEAD request через `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 job - `GET /api/models/download/status` — все jobs (active + recent) - `GET /api/models/download/[id]/stream` — SSE push of progress events: ``` event: progress data: {id, status, percent, bytesDownloaded, bytesTotal, ...} ``` Плюс `end` event когда job достиг terminal state. - `POST /api/models/download/[id]/cancel` — SIGTERM'ит curl, удаляет `.part` ### Dockerfile Добавил `curl` в apk add — нужен для самого скачивания. `wget` уже был (используется в health checks). ## Frontend ### ModelsTab additions - URL input + Download button — Enter для submit - 'Active downloads' list с progress bar'ами, bytes downloaded / total, speed (например `1.5 MB/s`), elapsed time, Cancel button - 'Recent' list (последние 5 finished) — показывает final size + duration ### DownloadJobRow component Reusable row для active и finished jobs. Два режима: - Full (default): badge + filename + progress bar + stats + source URL link - Compact: меньше, просто 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> для cleanup On mount, fetches existing download jobs (на случай page refresh mid-download). Для каждого active job открывает EventSource subscription. На `end` event закрывает SSE и refresh'ит models list (файл появился на диске). ### Handlers - `handleDownload()` — POST /api/models/download, затем start SSE - `handleCancelDownload(id)` — POST /api/models/download/[id]/cancel, закрывает SSE, refresh jobs - `refreshDownloadJobs()` — GET /api/models/download/status, manages SSE subscriptions ## Verification - `npm run build` — OK, 25 routes (4 new download routes) - `bash dashboard/validate-build.sh` — все 8 COPY источников ✓, standalone ✓ ## После мержа ```sh git pull && sh build.sh docker compose up -d --force-recreate dashboard ``` Открой 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 add - `dashboard/src/app/page.tsx` — ModelsTab gets Download section, DownloadJobRow component, DownloadJob type, SSE-based handlers
super-z-bot added 1 commit 2026-10-24 01:34:37 +00:00
## 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
mikan merged commit e02b0e57a3 into master 2026-10-24 01:40:19 +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#9