Add caption controls to web dashboard

This commit is contained in:
Sleeps
2026-10-07 11:44:06 +01:00
parent 6290dd0779
commit 7a3dc9cfec
+106 -2
View File
@@ -89,6 +89,21 @@
<div id="indexStatus" class="status muted">Idle</div>
<div id="indexDetail" class="muted"></div>
</section>
<section class="card">
<h2>Captioning</h2>
<div class="row between">
<div id="captionText" class="big">0%</div>
<div id="captionFrames" class="muted">0 / 0 frames</div>
</div>
<progress id="captionProgress" max="100" value="0"></progress>
<div id="captionStatus" class="status muted">Idle</div>
<div id="captionDetail" class="muted"></div>
<div class="row" style="margin-top:14px">
<button id="captionNow" type="button">Start / resume captioning</button>
<label><input id="forceCaption" type="checkbox"> Force recaption</label>
</div>
</section>
</div>
<section class="card">
@@ -105,6 +120,7 @@
(() => {
const $ = id => document.getElementById(id);
let statusTimer = null;
let captionTimer = null;
let thumbnailUrls = [];
$('apiKey').value = localStorage.getItem('sceneSearchApiKey') || '';
@@ -238,6 +254,90 @@
}
}
function renderCaptionStatus(s) {
const percent = Number(s.percent || (s.stage === 'complete' ? 100 : 0));
$('captionProgress').value = percent;
$('captionText').textContent = percent.toFixed(1).replace('.0','') + '%';
$('captionFrames').textContent = (s.frames_completed || 0) + ' / ' + (s.frames_total || 0) + ' frames';
if (s.running) {
$('captionNow').disabled = true;
$('captionStatus').className = 'status';
if (s.stage === 'routing') {
$('captionStatus').textContent = 'Routing frames to caption models';
$('captionDetail').textContent = (s.frames_selected || s.frames_total || 0) + ' frames selected';
} else if (s.stage === 'syncing' || s.stage === 'sync') {
$('captionStatus').textContent = 'Rebuilding search index: ' + (s.documents_processed || 0);
$('captionDetail').textContent =
(s.frames_completed || 0) + ' captions saved, ' + (s.failed || 0) + ' failed';
} else {
$('captionStatus').textContent = 'Captioning: ' +
(s.title || 'current frame') +
(s.timestamp_ms != null ? ' at ' + formatTs(s.timestamp_ms) : '');
$('captionDetail').textContent =
(s.model || '') +
(s.route ? ', ' + s.route : '') +
', ' + (s.failed || 0) + ' failed';
}
} else if (s.stage === 'failed') {
$('captionNow').disabled = false;
$('captionStatus').className = 'status error';
$('captionStatus').textContent = 'Failed: ' + (s.error || 'unknown error');
$('captionDetail').textContent = '';
} else if (s.stage === 'complete') {
$('captionNow').disabled = false;
$('captionStatus').className = 'status ok';
$('captionStatus').textContent =
'Complete: ' + (s.frames_completed || 0) + ' saved, ' + (s.failed || 0) + ' failed';
$('captionDetail').textContent =
(s.retained || 0) + ' existing captions retained';
} else {
$('captionNow').disabled = false;
$('captionStatus').className = 'status muted';
$('captionStatus').textContent = 'Idle';
$('captionDetail').textContent = '';
}
}
async function refreshCaptionStatus() {
try {
const s = await api('/api/caption/status');
renderCaptionStatus(s);
if (s.running) {
if (!captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
} else if (captionTimer) {
clearInterval(captionTimer);
captionTimer = null;
refreshHealth();
}
return s;
} catch (e) {
$('captionStatus').className = 'status error';
$('captionStatus').textContent = e.message;
return null;
}
}
async function startCaption() {
const ids = selectedLibraries();
if (!ids.length) {
$('captionStatus').className = 'status error';
$('captionStatus').textContent = 'Select at least one library.';
return;
}
try {
const s = await api('/api/caption', {
method:'POST',
body:JSON.stringify({library_ids:ids, force:$('forceCaption').checked})
});
renderCaptionStatus(s);
if (s.running && !captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
} catch (e) {
$('captionStatus').className = 'status error';
$('captionStatus').textContent = e.message;
}
}
function formatTs(ms) {
const seconds = Math.floor((ms || 0) / 1000);
const h = Math.floor(seconds / 3600);
@@ -290,15 +390,16 @@
$('saveKey').onclick = () => {
localStorage.setItem('sceneSearchApiKey', $('apiKey').value.trim());
loadLibraries(); refreshStatus();
loadLibraries(); refreshStatus(); refreshCaptionStatus();
};
$('clearKey').onclick = () => {
localStorage.removeItem('sceneSearchApiKey'); $('apiKey').value = '';
loadLibraries(); refreshStatus();
loadLibraries(); refreshStatus(); refreshCaptionStatus();
};
$('refreshLibraries').onclick = loadLibraries;
$('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true);
$('indexNow').onclick = startIndex;
$('captionNow').onclick = startCaption;
$('searchButton').onclick = search;
$('searchQuery').addEventListener('keydown', e => { if (e.key === 'Enter') search(); });
@@ -307,6 +408,9 @@
refreshStatus().then(s => {
if (s && s.running && !statusTimer) statusTimer = setInterval(refreshStatus, 2000);
});
refreshCaptionStatus().then(s => {
if (s && s.running && !captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
});
})();
</script>
</body>