Merge pull request #12 from MrSleeps/feature/web-dashboard-docker

Add Docker service and Scene Search web dashboard
This commit is contained in:
Sleeps
2026-10-06 19:05:44 +01:00
committed by GitHub
13 changed files with 627 additions and 10 deletions
+9
View File
@@ -0,0 +1,9 @@
.git
.github
.venv
.env
data
jellyfin-plugin
tests
__pycache__
*.pyc
+8 -3
View File
@@ -25,6 +25,9 @@ CAPTION_ROUTER_CONTEXT_SECONDS=6
# Jellyfin ingestion
JELLYFIN_URL=http://127.0.0.1:8096
# Docker Compose uses this only from inside the scene-search container.
# Leave blank to use http://host.docker.internal:8096.
JELLYFIN_DOCKER_URL=
JELLYFIN_API_KEY=
# Preferred: comma-separated list of libraries to index by default.
JELLYFIN_LIBRARIES=
@@ -47,9 +50,11 @@ JELLYFIN_FORCE_SPECIALIST_TAG=scene-search:specialist
JELLYFIN_FORCE_GENERAL_TAG=scene-search:general
JELLYFIN_SKIP_TAG=scene-search:skip
# HTTP search API used by the Jellyfin plugin
# HTTP API / standalone web dashboard.
# Docker Compose overrides SCENE_API_HOST to 0.0.0.0 and publishes this port.
SCENE_API_HOST=127.0.0.1
SCENE_API_PORT=8097
# Optional but recommended. When set, /api/search and thumbnails require
# Authorization: Bearer <key> or X-Scene-Search-Key: <key>.
# Strongly recommended when Docker exposes the dashboard/API on the LAN.
# Protected API calls accept Authorization: Bearer <key> or X-Scene-Search-Key.
# The web dashboard stores the key only in the browser's local storage.
SCENE_API_KEY=
+23
View File
@@ -0,0 +1,23 @@
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt /app/requirements.txt
# Install a CUDA-enabled PyTorch wheel explicitly; the NVIDIA container runtime
# supplies access to the host driver/GPU.
RUN python -m pip install --upgrade pip \
&& python -m pip install "torch>=2.4" --index-url https://download.pytorch.org/whl/cu124 \
&& python -m pip install -r /app/requirements.txt
COPY scene_search /app/scene_search
CMD ["python", "-m", "scene_search.cli", "serve"]
+59 -6
View File
@@ -37,14 +37,52 @@ Long term:
- Docker / Docker Compose
- Ollama for optional stage-2 captions
## 1. Start Meilisearch
## 1. Run Scene Search with Docker
The normal deployment runs both Meilisearch and the Scene Search API/web app with Docker Compose. The Python CLI remains available for maintenance and debugging, but you do not need to keep `python -m scene_search.cli serve` running manually.
Create your environment file and set the Jellyfin/API credentials:
```bash
cp .env.example .env
# Change MEILI_MASTER_KEY in .env
docker compose up -d
nano .env
```
At minimum set `MEILI_MASTER_KEY`, `JELLYFIN_API_KEY`, `SCENE_API_KEY`, and your Ollama URL/model settings.
GPU access requires the NVIDIA Container Toolkit on the Docker host. Once Docker can expose the NVIDIA GPU to containers, build and start everything:
```bash
docker compose up -d --build
```
The existing `./data` directory is bind-mounted into the application container, so SQLite, thumbnails, editable prompts and the Hugging Face model cache persist across container rebuilds.
The Compose service reaches Jellyfin on the same host through `host.docker.internal:8096` by default. If your Jellyfin server uses another address, set:
```env
JELLYFIN_DOCKER_URL=http://your-jellyfin-host:8096
```
Meilisearch is addressed internally as `http://meilisearch:7700`; the existing host port `7869` remains available for its dashboard/API.
Check the containers:
```bash
docker compose ps
docker compose logs -f scene-search
```
The standalone Scene Search dashboard is then available at:
```text
http://<tardis-ip-or-hostname>:8097/
```
If `SCENE_API_KEY` is configured, enter it once in the dashboard. It is stored only in that browser's local storage.
> If an item has no Jellyfin Trickplay data and the indexer must use ffmpeg fallback, its Jellyfin media path must also be mounted into the container at the same path. Trickplay-backed items do not require the original media filesystem to be mounted.
## 2. Python environment
Create and activate a venv, install a CUDA-compatible PyTorch build if required, then:
@@ -322,7 +360,7 @@ SCENE_API_KEY=replace-with-a-random-secret
If Jellyfin and this project run on the same host, keeping the API bound to `127.0.0.1` is recommended.
Start the service:
With the recommended Docker deployment the service starts automatically with `docker compose up -d`. For development outside Docker you can still run:
```bash
python -m scene_search.cli serve
@@ -364,7 +402,22 @@ The API also exposes authenticated Jellyfin-management endpoints used by the plu
- `POST /api/jellyfin/index` — start one background indexing job for selected library ids.
- `GET /api/jellyfin/index/status` — report live library/item/frame/sync progress.
Only one plugin-triggered indexing job can run at a time. Search requests return a temporary 503 while that job owns the shared embedding model.
Only one indexing job can run at a time. Search requests return a temporary 503 while that job owns the shared embedding model.
The indexing status now includes an overall item-weighted percentage across all selected libraries. The final 1% is reserved for rebuilding Meilisearch, so the UI reaches 99% after media ingestion and 100% only when the serving index is ready.
### Standalone web dashboard
The API serves a lightweight management/search UI at `/`. It provides:
- service/Meilisearch health at a glance;
- Jellyfin library selection and indexed item/frame counts;
- normal or forced indexing;
- overall progress plus current library/item/frame progress;
- final indexed/unchanged/failed/removed totals;
- semantic scene search with cached frame thumbnails.
The page talks to the same authenticated API used by the Jellyfin plugin. The API key is never embedded into the HTML; when supplied in the page it is kept in that browser's local storage.
## Jellyfin 12 search plugin
@@ -398,7 +451,7 @@ Open **Dashboard → Plugins → Scene Search** and configure:
The plugin asks the Python service for the libraries visible to the configured Jellyfin API key and shows their current indexed item/frame counts. The selected library ids are saved in Jellyfin's plugin configuration, so normal operation does not require editing `.env`.
Use **Index selected libraries** to start a backend indexing job. The plugin shows the current library, item and frame progress and polls until the job completes. When ingestion finishes, the backend automatically rebuilds Meilisearch, so newly indexed vectors are searchable without a separate `sync-meili` command.
Use **Index selected libraries** to start a backend indexing job. The plugin shows an overall percentage/progress bar across all selected libraries as well as the current library, item and frame progress, and polls until the job completes. When ingestion finishes, the backend automatically rebuilds Meilisearch, so newly indexed vectors are searchable without a separate `sync-meili` command.
Plugin-triggered indexing reuses the API process's existing SigLIP instance and blocks semantic searches while the indexing job owns the model, avoiding a second GPU copy on the same machine.
+36
View File
@@ -9,3 +9,39 @@ services:
MEILI_MASTER_KEY: ${MEILI_MASTER_KEY:-change-me-now}
volumes:
- ./data/meili:/meili_data
scene-search:
build:
context: .
restart: unless-stopped
env_file:
- .env
environment:
SCENE_API_HOST: 0.0.0.0
DATA_DIR: /app/data
MEILI_URL: http://meilisearch:7700
JELLYFIN_URL: ${JELLYFIN_DOCKER_URL:-http://host.docker.internal:8096}
HF_HOME: /app/data/huggingface
ports:
- "${SCENE_API_PORT:-8097}:${SCENE_API_PORT:-8097}"
volumes:
- ./data:/app/data
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
- meilisearch
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
healthcheck:
test:
- CMD-SHELL
- "curl -fsS http://127.0.0.1:${SCENE_API_PORT:-8097}/api/health >/dev/null || exit 1"
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
@@ -60,6 +60,13 @@
</label>
</div>
<div style="margin-bottom:.5em;">
<div style="display:flex;justify-content:space-between;gap:1em;">
<strong id="overallProgressText">0%</strong>
<span id="overallProgressItems" class="fieldDescription">0 / 0 items</span>
</div>
<progress id="overallProgress" max="100" value="0" style="width:100%;height:1.1em;"></progress>
</div>
<div id="indexStatus" class="fieldDescription" style="margin-bottom:1.5em;"></div>
<button is="emby-button" type="submit" class="raised button-submit block">
@@ -108,11 +115,25 @@
function renderStatus(status) {
var container = page.querySelector('#indexStatus');
var progress = page.querySelector('#overallProgress');
var progressText = page.querySelector('#overallProgressText');
var progressItems = page.querySelector('#overallProgressItems');
if (!status) {
container.textContent = 'Index status unavailable.';
progress.value = 0;
progressText.textContent = '0%';
progressItems.textContent = '0 / 0 items';
return;
}
var percent = Number(status.overall_percent || (status.stage === 'complete' ? 100 : 0));
progress.value = percent;
progressText.textContent = percent.toFixed(1).replace('.0', '') + '%';
progressItems.textContent =
(status.overall_items_completed || 0) + ' / ' +
(status.overall_items_total || 0) + ' items';
if (status.running) {
var parts = ['Indexing'];
if (status.library) {
@@ -73,6 +73,15 @@ public sealed class SceneSearchIndexStatus
[JsonPropertyName("frames_total")]
public int? FramesTotal { get; set; }
[JsonPropertyName("overall_items_total")]
public int? OverallItemsTotal { get; set; }
[JsonPropertyName("overall_items_completed")]
public int? OverallItemsCompleted { get; set; }
[JsonPropertyName("overall_percent")]
public double? OverallPercent { get; set; }
[JsonPropertyName("documents_processed")]
public int? DocumentsProcessed { get; set; }
+7
View File
@@ -12,6 +12,8 @@ from .database import connect, init_db
from .index_jobs import IndexJobManager
from .search_service import SearchService
WEB_INDEX_PATH = Path(__file__).parent / "web" / "index.html"
app = FastAPI(
title="Jellyfin Scene Search API",
version="1.0.0",
@@ -64,6 +66,11 @@ def require_api_key(
raise HTTPException(status_code=401, detail="Invalid API key")
@app.get("/", include_in_schema=False)
def web_dashboard() -> FileResponse:
return FileResponse(WEB_INDEX_PATH, media_type="text/html")
@app.get("/api/health")
def health() -> dict:
return get_search_service().health()
+50
View File
@@ -88,6 +88,11 @@ class IndexJobManager:
client = build_jellyfin_client()
libraries = resolve_library_ids(client, library_ids)
library_item_totals = [
client.item_count(str(item.get("Id") or ""))
for item in libraries
]
overall_items_total = sum(library_item_totals)
with self._state_lock:
self._state = {
@@ -98,6 +103,10 @@ class IndexJobManager:
"error": None,
"library_total": len(libraries),
"library_ids": [str(item.get("Id") or "") for item in libraries],
"library_item_totals": library_item_totals,
"overall_items_total": overall_items_total,
"overall_items_completed": 0,
"overall_percent": 0.0,
}
self._thread = threading.Thread(
@@ -112,6 +121,47 @@ class IndexJobManager:
def _progress(self, update: dict) -> None:
with self._state_lock:
self._state.update(update)
self._update_overall_progress_locked()
def _update_overall_progress_locked(self) -> None:
stage = str(self._state.get("stage") or "")
total = int(self._state.get("overall_items_total") or 0)
totals = [
int(value)
for value in (self._state.get("library_item_totals") or [])
]
if stage == "complete":
self._state["overall_items_completed"] = total
self._state["overall_percent"] = 100.0
return
if stage in {"indexed", "syncing", "sync", "synced"}:
self._state["overall_items_completed"] = total
self._state["overall_percent"] = 99.0 if total else 99.0
return
library_number = int(self._state.get("library_number") or 1)
library_index = max(0, min(library_number - 1, len(totals)))
before_library = sum(totals[:library_index])
item_number = int(self._state.get("item_number") or 0)
completed_before_item = max(item_number - 1, 0)
completed = min(before_library + completed_before_item, total)
fractional_item = 0.0
frames_total = int(self._state.get("frames_total") or 0)
frames_processed = int(self._state.get("frames_processed") or 0)
if stage == "embedding" and frames_total > 0:
fractional_item = min(max(frames_processed / frames_total, 0.0), 1.0)
position = min(completed + fractional_item, float(total))
self._state["overall_items_completed"] = completed
self._state["overall_percent"] = (
round((position / total) * 99.0, 1)
if total > 0
else 0.0
)
def _run(self, libraries: list[dict], force: bool) -> None:
try:
+14
View File
@@ -122,6 +122,20 @@ class JellyfinClient:
return results[:limit] if limit is not None else results
def item_count(self, library_id: str) -> int:
data = self._get(
"/Items",
params={
"ParentId": library_id,
"Recursive": "true",
"IncludeItemTypes": "Movie,Episode,Video",
"EnableTotalRecordCount": "true",
"StartIndex": 0,
"Limit": 1,
},
).json()
return int(data.get("TotalRecordCount") or 0)
def item(self, item_id: str) -> dict[str, Any]:
data = self._get(
"/Items",
+313
View File
@@ -0,0 +1,313 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Scene Search</title>
<style>
:root { color-scheme: dark; font-family: Inter, system-ui, sans-serif; background:#0f1115; color:#f4f5f7; }
* { box-sizing:border-box; }
body { margin:0; background:#0f1115; }
main { max-width:1180px; margin:0 auto; padding:28px 18px 60px; }
h1,h2 { margin-top:0; }
.muted { color:#9ca3af; }
.grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(300px,1fr)); gap:16px; }
.card { background:#181b21; border:1px solid #2a2f39; border-radius:14px; padding:18px; margin-bottom:16px; }
input,button { font:inherit; }
input[type=text],input[type=password] { width:100%; padding:11px 12px; border-radius:9px; border:1px solid #3a414d; background:#101318; color:#fff; }
button { padding:10px 14px; border:0; border-radius:9px; cursor:pointer; background:#3b82f6; color:white; font-weight:650; }
button.secondary { background:#303642; }
button:disabled { opacity:.5; cursor:not-allowed; }
.row { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.between { justify-content:space-between; }
.library { display:flex; gap:10px; align-items:flex-start; padding:9px 0; border-bottom:1px solid #282d36; }
.library:last-child { border-bottom:0; }
.library small { display:block; color:#9ca3af; margin-top:3px; }
progress { width:100%; height:18px; accent-color:#3b82f6; }
.big { font-size:1.7rem; font-weight:750; }
.status { margin-top:9px; min-height:1.4em; }
.error { color:#fca5a5; }
.ok { color:#86efac; }
#results { display:grid; gap:12px; }
.result { display:grid; grid-template-columns:180px 1fr; gap:14px; background:#12151a; border:1px solid #282d36; border-radius:11px; overflow:hidden; }
.result img { width:180px; height:102px; object-fit:cover; background:#08090b; }
.result .body { padding:12px 12px 12px 0; }
.result h3 { margin:0 0 6px; }
code { background:#101318; padding:2px 5px; border-radius:5px; }
@media(max-width:640px){ .result{grid-template-columns:1fr}.result img{width:100%;height:auto}.result .body{padding:0 12px 12px} }
</style>
</head>
<body>
<main>
<div class="row between">
<div>
<h1>Scene Search</h1>
<div class="muted">Jellyfin semantic scene search and indexing dashboard</div>
</div>
<div id="health" class="muted">Checking service…</div>
</div>
<div class="card">
<div class="grid">
<div>
<label for="apiKey">API key</label>
<input id="apiKey" type="password" autocomplete="off" placeholder="SCENE_API_KEY (leave blank if disabled)">
</div>
<div style="align-self:end">
<div class="row">
<button id="saveKey" type="button">Save key locally</button>
<button id="clearKey" type="button" class="secondary">Clear</button>
</div>
<div class="muted" style="margin-top:6px">Stored only in this browser's local storage.</div>
</div>
</div>
</div>
<div class="grid">
<section class="card">
<div class="row between">
<h2>Libraries</h2>
<div class="row">
<button id="selectAll" type="button" class="secondary">Select all</button>
<button id="refreshLibraries" type="button" class="secondary">Refresh</button>
</div>
</div>
<div id="libraries" class="muted">Loading…</div>
<div class="row" style="margin-top:14px">
<button id="indexNow" type="button">Index selected</button>
<label><input id="forceIndex" type="checkbox"> Force rebuild</label>
</div>
</section>
<section class="card">
<h2>Index progress</h2>
<div class="row between">
<div id="overallText" class="big">0%</div>
<div id="overallItems" class="muted">0 / 0 items</div>
</div>
<progress id="overallProgress" max="100" value="0"></progress>
<div id="indexStatus" class="status muted">Idle</div>
<div id="indexDetail" class="muted"></div>
</section>
</div>
<section class="card">
<h2>Search</h2>
<div class="row">
<div style="flex:1; min-width:220px"><input id="searchQuery" type="text" placeholder="e.g. woman standing outside"></div>
<button id="searchButton" type="button">Search scenes</button>
</div>
<div id="searchStatus" class="status muted"></div>
<div id="results"></div>
</section>
</main>
<script>
(() => {
const $ = id => document.getElementById(id);
let statusTimer = null;
let thumbnailUrls = [];
$('apiKey').value = localStorage.getItem('sceneSearchApiKey') || '';
function headers(json=false) {
const h = {};
const key = $('apiKey').value.trim();
if (key) h.Authorization = 'Bearer ' + key;
if (json) h['Content-Type'] = 'application/json';
return h;
}
async function api(path, options={}) {
const response = await fetch(path, {...options, headers:{...headers(!!options.body), ...(options.headers||{})}});
if (!response.ok) {
let detail = '';
try { detail = (await response.json()).detail || ''; } catch (_) {}
throw new Error(detail || ('HTTP ' + response.status));
}
return response.status === 204 ? null : response.json();
}
async function refreshHealth() {
try {
const data = await fetch('/api/health').then(r => r.json());
$('health').textContent = 'Service ' + data.status + ' · ' + (data.frame_count || 0) + ' frames';
$('health').className = data.status === 'ok' ? 'ok' : 'muted';
} catch (e) {
$('health').textContent = 'Service unavailable';
$('health').className = 'error';
}
}
async function loadLibraries() {
$('libraries').textContent = 'Loading…';
try {
const data = await api('/api/jellyfin/libraries');
const libs = data.libraries || [];
if (!libs.length) {
$('libraries').textContent = 'No Jellyfin libraries returned.';
return;
}
$('libraries').innerHTML = libs.map(l => `
<label class="library">
<input type="checkbox" class="libraryCheck" value="${escapeHtml(l.id)}" ${l.indexed_items > 0 ? 'checked' : ''}>
<span><strong>${escapeHtml(l.name)}</strong><small>${l.indexed_items} indexed items · ${l.indexed_frames} frames</small></span>
</label>`).join('');
} catch (e) {
$('libraries').innerHTML = '<span class="error">' + escapeHtml(e.message) + '</span>';
}
}
function selectedLibraries() {
return Array.from(document.querySelectorAll('.libraryCheck:checked')).map(x => x.value);
}
function renderStatus(s) {
const percent = Number(s.overall_percent || (s.stage === 'complete' ? 100 : 0));
$('overallProgress').value = percent;
$('overallText').textContent = percent.toFixed(1).replace('.0','') + '%';
$('overallItems').textContent = (s.overall_items_completed || 0) + ' / ' + (s.overall_items_total || 0) + ' items';
if (s.running) {
$('indexStatus').className = 'status';
$('indexStatus').textContent = s.stage === 'sync' || s.stage === 'syncing'
? 'Rebuilding Meilisearch'
: 'Indexing ' + (s.library || '');
const bits = [];
if (s.library_number && s.library_total) bits.push('library ' + s.library_number + '/' + s.library_total);
if (s.item) bits.push(s.item);
if (s.item_number && s.item_total) bits.push('item ' + s.item_number + '/' + s.item_total);
if (s.frames_total) bits.push((s.frames_processed || 0) + '/' + s.frames_total + ' frames');
if (s.documents_processed && (s.stage === 'sync' || s.stage === 'syncing')) bits.push(s.documents_processed + ' documents');
$('indexDetail').textContent = bits.join(' · ');
$('indexNow').disabled = true;
} else if (s.stage === 'failed') {
$('indexStatus').className = 'status error';
$('indexStatus').textContent = 'Failed: ' + (s.error || 'unknown error');
$('indexDetail').textContent = '';
$('indexNow').disabled = false;
} else if (s.stage === 'complete') {
$('indexStatus').className = 'status ok';
$('indexStatus').textContent = 'Complete';
$('indexDetail').textContent =
(s.indexed || 0) + ' indexed · ' + (s.skipped || 0) + ' unchanged · ' +
(s.failed || 0) + ' failed · ' + (s.pruned || 0) + ' removed';
$('indexNow').disabled = false;
} else {
$('indexStatus').className = 'status muted';
$('indexStatus').textContent = 'Idle';
$('indexDetail').textContent = '';
$('indexNow').disabled = false;
}
}
async function refreshStatus() {
try {
const s = await api('/api/jellyfin/index/status');
renderStatus(s);
if (!s.running && statusTimer) {
clearInterval(statusTimer);
statusTimer = null;
loadLibraries();
refreshHealth();
}
return s;
} catch (e) {
$('indexStatus').className = 'status error';
$('indexStatus').textContent = e.message;
return null;
}
}
async function startIndex() {
const ids = selectedLibraries();
if (!ids.length) {
$('indexStatus').className = 'status error';
$('indexStatus').textContent = 'Select at least one library.';
return;
}
try {
const s = await api('/api/jellyfin/index', {
method:'POST',
body:JSON.stringify({library_ids:ids, force:$('forceIndex').checked})
});
renderStatus(s);
if (!statusTimer) statusTimer = setInterval(refreshStatus, 2000);
} catch (e) {
$('indexStatus').className = 'status error';
$('indexStatus').textContent = e.message;
}
}
function formatTs(ms) {
const seconds = Math.floor((ms || 0) / 1000);
const h = Math.floor(seconds / 3600);
const m = Math.floor((seconds % 3600) / 60);
const s = seconds % 60;
return [h,m,s].map(x => String(x).padStart(2,'0')).join(':');
}
async function loadThumbnail(frameId, img) {
try {
const response = await fetch('/api/frames/' + encodeURIComponent(frameId) + '/thumbnail', {headers:headers()});
if (!response.ok) return;
const blob = await response.blob();
const url = URL.createObjectURL(blob);
thumbnailUrls.push(url);
img.src = url;
} catch (_) {}
}
async function search() {
const q = $('searchQuery').value.trim();
if (!q) return;
thumbnailUrls.forEach(URL.revokeObjectURL);
thumbnailUrls = [];
$('results').innerHTML = '';
$('searchStatus').textContent = 'Searching…';
try {
const data = await api('/api/search?q=' + encodeURIComponent(q) + '&scene_limit=20&item_limit=10');
const scenes = data.scenes || [];
$('searchStatus').textContent = scenes.length + ' scene match' + (scenes.length === 1 ? '' : 'es');
for (const scene of scenes) {
const el = document.createElement('article');
el.className = 'result';
el.innerHTML = '<img alt=""><div class="body"><h3>' + escapeHtml(scene.title || 'Untitled') +
' <span class="muted">@ ' + formatTs(scene.timestamp_ms) + '</span></h3><div>' +
escapeHtml(scene.caption || 'No caption yet') + '</div><div class="muted" style="margin-top:6px">score ' +
(scene.ranking_score == null ? '—' : Number(scene.ranking_score).toFixed(3)) + '</div></div>';
$('results').appendChild(el);
if (scene.frame_id) loadThumbnail(scene.frame_id, el.querySelector('img'));
}
} catch (e) {
$('searchStatus').className = 'status error';
$('searchStatus').textContent = e.message;
}
}
function escapeHtml(value) {
return String(value == null ? '' : value).replace(/[&<>"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
}
$('saveKey').onclick = () => {
localStorage.setItem('sceneSearchApiKey', $('apiKey').value.trim());
loadLibraries(); refreshStatus();
};
$('clearKey').onclick = () => {
localStorage.removeItem('sceneSearchApiKey'); $('apiKey').value = '';
loadLibraries(); refreshStatus();
};
$('refreshLibraries').onclick = loadLibraries;
$('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true);
$('indexNow').onclick = startIndex;
$('searchButton').onclick = search;
$('searchQuery').addEventListener('keydown', e => { if (e.key === 'Enter') search(); });
refreshHealth();
loadLibraries();
refreshStatus().then(s => {
if (s && s.running && !statusTimer) statusTimer = setInterval(refreshStatus, 2000);
});
})();
</script>
</body>
</html>
+6 -1
View File
@@ -6,7 +6,12 @@ from unittest.mock import patch
from fastapi import HTTPException
from scene_search.api import require_api_key
from scene_search.api import WEB_INDEX_PATH, require_api_key
class WebDashboardTests(unittest.TestCase):
def test_dashboard_asset_is_bundled(self) -> None:
self.assertTrue(WEB_INDEX_PATH.is_file())
class ApiAuthTests(unittest.TestCase):
+72
View File
@@ -0,0 +1,72 @@
from __future__ import annotations
import unittest
from types import SimpleNamespace
from scene_search.index_jobs import IndexJobManager
class OverallIndexProgressTests(unittest.TestCase):
def make_manager(self) -> IndexJobManager:
return IndexJobManager(SimpleNamespace()) # type: ignore[arg-type]
def test_progress_accounts_for_different_library_sizes(self) -> None:
manager = self.make_manager()
manager._state = {
"running": True,
"stage": "starting",
"library_item_totals": [2, 4],
"overall_items_total": 6,
"overall_items_completed": 0,
"overall_percent": 0.0,
}
manager._progress(
{
"stage": "embedding",
"library_number": 2,
"library_total": 2,
"item_number": 3,
"item_total": 4,
"frames_processed": 5,
"frames_total": 10,
}
)
status = manager.status()
self.assertEqual(status["overall_items_completed"], 4)
self.assertAlmostEqual(status["overall_percent"], 74.2, places=1)
def test_sync_reserves_final_percent(self) -> None:
manager = self.make_manager()
manager._state = {
"running": True,
"stage": "indexed",
"library_item_totals": [10],
"overall_items_total": 10,
}
manager._progress({"stage": "syncing"})
status = manager.status()
self.assertEqual(status["overall_items_completed"], 10)
self.assertEqual(status["overall_percent"], 99.0)
def test_complete_is_one_hundred_percent(self) -> None:
manager = self.make_manager()
manager._state = {
"running": True,
"stage": "sync",
"library_item_totals": [3, 2],
"overall_items_total": 5,
}
manager._progress({"stage": "complete", "running": False})
status = manager.status()
self.assertEqual(status["overall_items_completed"], 5)
self.assertEqual(status["overall_percent"], 100.0)
if __name__ == "__main__":
unittest.main()