Files
yaris-obd/static/js/dash.js
T
Mathieu MoranandCopilot f17c5c8681 Phase 12: remove phone-relay dashcam upload feature
Removes the phone-relay feature entirely per the Phase 11 finding
that it hit a fundamental phone-OS limitation (a browser page can't
route WiFi and cellular traffic simultaneously, no code fix possible)
- see PLAN.md for the full test writeup.

- app.py: dropped /api/dash/pending, /api/dash/file/<path>,
  /api/dash/relay/config, /api/dash/relay/heartbeat,
  /api/dash/relay/stop, /api/dash/relay/mark_uploaded routes and
  their now-unused imports (os, send_file, abort, safe_join).
- modules/app_upload.py: dropped list_pending_dashcam_files(),
  relay_heartbeat()/relay_stop()/is_relay_active(),
  RELAY_LEASE_SECONDS/_relay_lease_until, and the relay-lease check
  inside _upload_dashcam_files()/get_status(). Kept the chunked
  upload protocol, dashcam_hash_cache/_hash_dashcam_file() (still
  used by the Pi's own background uploader), and DASHCAM_CHUNK_SIZE -
  none of that was relay-specific.
- templates/dash.html: removed the 'Relay via phone' card.
- static/js/dash.js: removed all relay JS (relayOneFile,
  fetchChunkWithRetry, uploadChunkWithRetry, heartbeat timers,
  pending-file list rendering).
- server/app.py: removed the CORS after_request hook, added solely
  for the phone's cross-origin browser calls (the Pi's own Python
  requests-based client was never subject to CORS).
- readme.md: dropped the phone-relay feature bullet, updated the
  project-status blurb to explain the removal + point at the planned
  native Android app as the real fix for that use case.
- PLAN.md: marked Phase 12 done with a verification writeup.

Verified: py_compile on all touched Python files, node --check on
dash.js, grepped all touched files for any leftover relay/RELAY
reference (none), and smoke-tested by importing app.py + hitting it
with Flask's test client - app starts cleanly, every relay route is
gone from url_map, and both / and /dash still render HTTP 200 with
zero 'relay' occurrences in /dash's HTML.

Co-authored-by: Copilot <[email protected]>
2026-08-09 17:12:30 -04:00

124 lines
4.6 KiB
JavaScript

// Dashcam page: scan for a USB dashcam, then trigger importing its videos.
// Uses plain fetch() (not socket.io / yaris.js) since this is a one-shot
// request/response flow, not a live data stream, and yaris.js assumes DOM
// elements (#map, #speedGraph) that don't exist on this page.
const deviceStatus = document.getElementById('dash-device-status');
const importStatus = document.getElementById('dash-import-status');
const scanBtn = document.getElementById('dash-scan-btn');
const importBtn = document.getElementById('dash-import-btn');
function describeDevice(device) {
const label = device.label ? ` "${device.label}"` : '';
return `${device.path}${label} (${device.size}, ${device.fstype || 'unknown fs'})`;
}
function scanForDashcam() {
deviceStatus.textContent = 'Scanning...';
importBtn.disabled = true;
fetch('/api/dash/devices')
.then(response => response.json())
.then(data => {
const devices = data.devices || [];
if (devices.length === 0) {
deviceStatus.textContent = 'No USB dashcam/storage device detected. Plug it in and scan again.';
return;
}
deviceStatus.textContent = 'Detected: ' + devices.map(describeDevice).join(', ');
importBtn.disabled = false;
})
.catch(err => {
deviceStatus.textContent = 'Error while scanning: ' + err;
});
}
function importDashcam() {
importStatus.textContent = 'Importing... this can take a while for large videos.';
importBtn.disabled = true;
fetch('/api/dash/import', { method: 'POST' })
.then(response => response.json())
.then(summary => {
if (summary.status !== 'ok') {
importStatus.textContent = summary.message || ('Import failed: ' + summary.status);
return;
}
let text = `Found ${summary.found} video(s), copied ${summary.copied}, skipped ${summary.skipped} (already imported).`;
if (summary.errors && summary.errors.length > 0) {
text += ` Errors: ${summary.errors.join('; ')}`;
}
importStatus.textContent = text;
})
.catch(err => {
importStatus.textContent = 'Error while importing: ' + err;
})
.finally(() => {
importBtn.disabled = false;
});
}
scanBtn.addEventListener('click', scanForDashcam);
importBtn.addEventListener('click', importDashcam);
// Auto-scan once when the page loads.
scanForDashcam();
// --- Remote server upload status/toggle ---
const uploadStatusEl = document.getElementById('upload-status');
const dashcamToggle = document.getElementById('dashcam-upload-toggle');
function describeUploadStatus(status) {
if (!status.configured) {
return 'Remote server not configured on this device (see db/upload_creds.env).';
}
let text = `Pending trip-log rows to upload: ${status.pending_tracking_rows}.`;
if (status.last_success_at) {
text += ` Last successful upload: ${status.last_success_at}`;
if (status.last_network_path) {
text += ` (via ${status.last_network_path === 'cellular' ? 'cellular fallback' : 'WiFi/Ethernet'})`;
}
text += '.';
}
if (status.cellular_fallback_configured) {
text += ' Cellular (SIM868) fallback is enabled for trip logs if WiFi/Ethernet is unreachable.';
}
if (status.last_error) {
text += ` Last error: ${status.last_error}.`;
}
return text;
}
function refreshUploadStatus() {
fetch('/api/upload/status')
.then(response => response.json())
.then(status => {
uploadStatusEl.textContent = describeUploadStatus(status);
dashcamToggle.checked = status.dashcam_upload_enabled;
dashcamToggle.disabled = !status.configured;
})
.catch(err => {
uploadStatusEl.textContent = 'Error while checking upload status: ' + err;
});
}
dashcamToggle.addEventListener('change', () => {
fetch('/api/upload/dashcam_toggle', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled: dashcamToggle.checked }),
})
.then(response => response.json())
.then(status => {
uploadStatusEl.textContent = describeUploadStatus(status);
dashcamToggle.checked = status.dashcam_upload_enabled;
})
.catch(err => {
uploadStatusEl.textContent = 'Error while updating toggle: ' + err;
});
});
refreshUploadStatus();
setInterval(refreshUploadStatus, 15000);