feat: add waveform download and storage.
This commit is contained in:
@@ -244,6 +244,46 @@
|
||||
let eventList = []; // populated from /device/events after connect
|
||||
let currentEventIndex = 0;
|
||||
|
||||
// ── DB mode: opened via ?db_id=<uuid>&api_base=<url> from History tab ────────
|
||||
const _urlParams = new URLSearchParams(window.location.search);
|
||||
const _dbId = _urlParams.get('db_id');
|
||||
const _dbApiBase = (_urlParams.get('api_base') || '').replace(/\/$/, '');
|
||||
|
||||
async function _loadFromDb() {
|
||||
const apiBase = _dbApiBase || document.getElementById('api-base').value.replace(/\/$/, '');
|
||||
setStatus('Loading waveform from database…', 'loading');
|
||||
document.getElementById('unit-bar').style.display = 'none';
|
||||
// Hide live-device controls — not relevant in DB mode
|
||||
document.querySelector('header .conn-group').style.display = 'none';
|
||||
|
||||
const url = `${apiBase}/db/events/${encodeURIComponent(_dbId)}/waveform`;
|
||||
let data;
|
||||
try {
|
||||
const resp = await fetch(url);
|
||||
if (!resp.ok) {
|
||||
const err = await resp.json().catch(() => ({ detail: resp.statusText }));
|
||||
throw new Error(err.detail || resp.statusText);
|
||||
}
|
||||
data = await resp.json();
|
||||
} catch (e) {
|
||||
setStatus(`Error: ${e.message}`, 'error');
|
||||
return;
|
||||
}
|
||||
lastData = data;
|
||||
renderWaveform(data);
|
||||
}
|
||||
|
||||
// Auto-load when opened with db_id param
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
if (_dbId) {
|
||||
// Pre-fill api-base if provided
|
||||
if (_dbApiBase) {
|
||||
document.getElementById('api-base').value = _dbApiBase;
|
||||
}
|
||||
_loadFromDb();
|
||||
}
|
||||
});
|
||||
|
||||
function setStatus(msg, cls = '') {
|
||||
const bar = document.getElementById('status-bar');
|
||||
bar.textContent = msg;
|
||||
@@ -404,8 +444,11 @@
|
||||
bar.innerHTML = '';
|
||||
bar.className = 'ok';
|
||||
const ts = data.timestamp;
|
||||
if (ts) {
|
||||
bar.textContent = `Event #${data.index} — ${ts.display} `;
|
||||
const tsDisplay = ts
|
||||
? (typeof ts === 'string' ? ts : (ts.display ?? JSON.stringify(ts)))
|
||||
: null;
|
||||
if (tsDisplay) {
|
||||
bar.textContent = `Event #${data.index} — ${tsDisplay} `;
|
||||
} else {
|
||||
bar.textContent = `Event #${data.index} `;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user