Add Pi-side upload client for Phase 9 remote server
- app_sql.py: add UPLOADED column + migration on tracking table, add settings and dashcam_uploads tables, add helpers for unsent-row queries, marking rows uploaded, and dashcam upload dedupe tracking. - app_upload.py: new background upload client. Periodically batches unsent tracking rows to POST /api/v1/tracking/batch and uploads new dashcam files (sha256-verified) to POST /api/v1/dashcam/upload, with exponential backoff on failure. Exposes get_status() and a dashcam-upload enable/disable toggle backed by the settings table. - app.py: start the upload client thread at startup, add GET /api/upload/status and POST /api/upload/dashcam_toggle routes. - dash.html/dash.js: add a "Remote server upload" card with upload status and a toggle switch to pause dashcam video uploads while trip/GPS log uploads keep running (per user request - useful on a slow/metered connection). - db/upload_creds.env: new gitignore-exempted template (mirrors db/creds.env) for YARIS_SERVER_URL/YARIS_DEVICE_NAME/YARIS_API_KEY. - requirements.txt: add requests. Tested against the real deployed unraid server: tracking batch upload + dedupe, dashcam upload + dedupe, and toggle-off correctly pausing dashcam uploads while tracking uploads continue. Also verified the full Flask app imports/runs cleanly and the new API routes + dash.html toggle render correctly in a headless browser. Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -63,3 +63,54 @@ 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_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);
|
||||
|
||||
Reference in New Issue
Block a user