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]>
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
import os
|
||||
|
||||
from flask import Flask, render_template, make_response, json, jsonify, request, send_file, abort
|
||||
from werkzeug.utils import safe_join
|
||||
from flask import Flask, render_template, make_response, json, jsonify, request
|
||||
from modules import app_gps, app_events, app_car, app_account, app_gps,app_obd, app_sql, app_dash, app_upload
|
||||
import time
|
||||
from gevent.pywsgi import WSGIServer
|
||||
@@ -53,60 +50,6 @@ def upload_dashcam_toggle():
|
||||
app_upload.set_dashcam_upload_enabled(bool(body["enabled"]))
|
||||
return jsonify(app_upload.get_status())
|
||||
|
||||
# --- Phone-relay: lets a phone on the Pi's own network list, download, and
|
||||
# directly re-upload dashcam files to the remote server itself (bypassing
|
||||
# the Pi's own often-congested WiFi radio for the internet-bound leg). See
|
||||
# static/js/dash.js for the client side of this. ---
|
||||
|
||||
@app.route('/api/dash/pending')
|
||||
def dash_pending():
|
||||
return jsonify({"files": app_upload.list_pending_dashcam_files()})
|
||||
|
||||
@app.route('/api/dash/file/<path:relpath>')
|
||||
def dash_file(relpath):
|
||||
abs_path = safe_join(app_dash.DEFAULT_DESTINATION, relpath)
|
||||
if abs_path is None or not os.path.isfile(abs_path):
|
||||
abort(404)
|
||||
# conditional=True (Flask's default) makes this support Range requests,
|
||||
# so the phone can fetch/re-upload one chunk at a time instead of ever
|
||||
# holding the whole (300+MB) file in the browser's memory at once.
|
||||
return send_file(abs_path, mimetype='application/octet-stream', conditional=True)
|
||||
|
||||
@app.route('/api/dash/relay/config')
|
||||
def dash_relay_config():
|
||||
# Hands the phone the same device credentials the Pi's own upload client
|
||||
# uses, so its browser JS can call the remote server's existing chunked
|
||||
# upload endpoints directly. Same trust boundary as the rest of this
|
||||
# unauthenticated local UI - anyone on the Pi's hotspot/LAN is already
|
||||
# implicitly trusted.
|
||||
return jsonify({
|
||||
"server_url": app_upload.SERVER_URL,
|
||||
"device_name": app_upload.DEVICE_NAME,
|
||||
"api_key": app_upload.API_KEY,
|
||||
"chunk_size": app_upload.DASHCAM_CHUNK_SIZE,
|
||||
"configured": app_upload.is_configured(),
|
||||
})
|
||||
|
||||
@app.route('/api/dash/relay/heartbeat', methods=['POST'])
|
||||
def dash_relay_heartbeat():
|
||||
app_upload.relay_heartbeat()
|
||||
return jsonify(app_upload.get_status())
|
||||
|
||||
@app.route('/api/dash/relay/stop', methods=['POST'])
|
||||
def dash_relay_stop():
|
||||
app_upload.relay_stop()
|
||||
return jsonify(app_upload.get_status())
|
||||
|
||||
@app.route('/api/dash/relay/mark_uploaded', methods=['POST'])
|
||||
def dash_relay_mark_uploaded():
|
||||
body = request.get_json(silent=True) or {}
|
||||
relative_path = (body.get("relative_path") or "").strip()
|
||||
sha256 = (body.get("sha256") or "").strip().lower()
|
||||
if not relative_path or not sha256:
|
||||
return jsonify(error="expected JSON body {'relative_path', 'sha256'}"), 400
|
||||
app_sql.mark_dashcam_file_uploaded(relative_path, sha256)
|
||||
return jsonify(status="ok")
|
||||
|
||||
# not sure if im gonna use this
|
||||
@app.route('/api/obd_speed/')
|
||||
def data():
|
||||
|
||||
Reference in New Issue
Block a user