"""CMS API + browsing UI for the compression miner. Reads the SQLite DB (populated by ingest.py), the calibration log, the CQ tables' source, and the two sample libraries. Runs as its own process, independent of the compression service and the miner -- see run_server.sh. """ from __future__ import annotations import re from pathlib import Path import calibration import cq_health import db import library import preview from auth import require_auth from fastapi import Depends, FastAPI, HTTPException, Request from fastapi.responses import FileResponse, HTMLResponse, StreamingResponse REFERENCE_LIBRARY_PATH = Path("/root/vidaio-real-content-library") COMPRESSED_LIBRARY_PATH = Path("/root/vidaio-compressed-sample-library") _RANGE_RE = re.compile(r"bytes=(\d*)-(\d*)") app = FastAPI(title="Vidaio Miner CMS") Auth = Depends(require_auth) def _find_sample(library_path: Path, task_id: str) -> Path | None: matches = list(library_path.glob(f"{task_id}_*.mp4")) return matches[0] if matches else None _STREAM_CHUNK = 1024 * 1024 def _stream_video(path: Path, request: Request) -> StreamingResponse: """Plain FileResponse ignores the Range header and always returns 200 with the entire file -- for a 200MB+ 4K reference clip, that means the browser has to download the whole thing before it can play anything, which looks exactly like the "spinning, never plays" symptom this was built to fix. Real 206 Partial Content support so the