CRITICAL: - frames.py: FRAMES_DIR corrected to /tmp/adacam/pics - frames.py: graceful handling when capture not started IMPORTANT: - wigle.py: added GET /api/1/wigle/config endpoint for Varroa - app.py: added GET /api/1/debug/redis-keys endpoint for GPS troubleshooting - install.sh: removed python validation that runs from wrong directory
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Recording frame endpoints."""
|
|
import os
|
|
import glob
|
|
from flask import Blueprint, jsonify
|
|
|
|
bp = Blueprint("frames", __name__, url_prefix="/api/1/recording")
|
|
|
|
FRAMES_DIR = "/tmp/adacam/pics"
|
|
|
|
|
|
@bp.route("/frames/latest", methods=["GET"])
|
|
def latest_frame():
|
|
"""Get path to most recent frame file."""
|
|
# Handle case where capture hasn't started yet
|
|
if not os.path.exists(FRAMES_DIR):
|
|
return jsonify({'frames': [], 'message': 'capture not started'}), 200
|
|
|
|
if not os.path.isdir(FRAMES_DIR):
|
|
return jsonify({"error": "Frames directory invalid"}), 500
|
|
|
|
files = glob.glob(os.path.join(FRAMES_DIR, "*"))
|
|
if not files:
|
|
return jsonify({'frames': [], 'message': 'no frames captured yet'}), 200
|
|
|
|
latest = max(files, key=os.path.getmtime)
|
|
return jsonify({"path": latest})
|
|
|
|
|
|
@bp.route("/frames", methods=["GET"])
|
|
def list_frames():
|
|
"""List all available frames."""
|
|
if not os.path.exists(FRAMES_DIR):
|
|
return jsonify({'frames': [], 'message': 'capture not started'})
|
|
|
|
files = glob.glob(os.path.join(FRAMES_DIR, "*"))
|
|
files.sort(key=os.path.getmtime, reverse=True)
|
|
return jsonify({
|
|
'frames': files[:100], # limit to 100 most recent
|
|
'total': len(files)
|
|
})
|