"""Recording frame endpoints.""" import os import glob from flask import Blueprint, jsonify bp = Blueprint("frames", __name__, url_prefix="/api/1/recording") FRAMES_DIR = "/tmp/recording/pics" @bp.route("/frames/latest", methods=["GET"]) def latest_frame(): """Get path to most recent frame file.""" if not os.path.isdir(FRAMES_DIR): return jsonify({"error": "No frames directory"}), 404 files = glob.glob(os.path.join(FRAMES_DIR, "*")) if not files: return jsonify({"error": "No frames available"}), 404 latest = max(files, key=os.path.getmtime) return jsonify({"path": latest})