adacam-api/adacam_api/routes/landmarks.py

28 lines
819 B
Python

"""Landmark detection endpoints."""
from flask import Blueprint, jsonify, request
from .. import db, forwarder
from ..auth import require_auth
bp = Blueprint("landmarks", __name__, url_prefix="/api/1/landmarks")
@bp.route("/last/<int:n>", methods=["GET"])
def get_last(n):
"""Get last N detections (unauthenticated)."""
n = min(n, 1000) # Cap at 1000
landmarks = db.get_last_landmarks(n)
return jsonify(landmarks)
@bp.route("", methods=["POST"])
@require_auth
def ingest():
"""Ingest a new detection from camera pipeline (authenticated)."""
data = request.get_json()
if not data or "class_label" not in data:
return jsonify({"error": "Missing class_label"}), 400
db.insert_landmark(data)
forwarder.forward_detection(data)
return jsonify({"status": "ok"})