diff --git a/recounting_dashboard.py b/recounting_dashboard.py index a8f7633..a70b2d1 100644 --- a/recounting_dashboard.py +++ b/recounting_dashboard.py @@ -171,12 +171,33 @@ def start_recount(): return jsonify({ "success": True, - "stream_url": f"{RECOUNT_API_URL}/api/live-video", + "stream_url": "/api/proxy-stream", "file": Path(mp4_path).name, "path": mp4_path, }) +@app.route("/api/proxy-stream") +def api_proxy_stream(): + try: + resp = _http_session.get(f"{RECOUNT_API_URL}/api/live-video", stream=True, timeout=5) + if resp.status_code != 200: + return Response("stream unavailable", status=502) + + def generate(): + for chunk in resp.iter_content(chunk_size=8192): + if chunk: + yield chunk + resp.close() + + return Response( + generate(), + mimetype=resp.headers.get("Content-Type", "multipart/x-mixed-replace; boundary=frame"), + ) + except Exception: + return Response("stream unavailable", status=502) + + @app.route("/api/stop-recount", methods=["POST"]) def stop_recount(): global _current_file @@ -198,7 +219,7 @@ def api_state(): if current_file: result["file"] = current_file result["file_name"] = Path(current_file).name - result["stream_url"] = f"{RECOUNT_API_URL}/api/live-video" + result["stream_url"] = "/api/proxy-stream" batch_num, date_str = _parse_filename(Path(current_file).name) if batch_num is not None: result["batch_number"] = batch_num