added refference point

This commit is contained in:
2026-06-25 11:04:21 +03:00
parent cd82244dcd
commit b5258b4f82
23 changed files with 1922 additions and 3 deletions
+105
View File
@@ -157,6 +157,111 @@ def tracks_get(track_id: int):
return jsonify({"error": str(e)}), 404
@app.post("/api/reference-points/start")
def reference_points_start():
if not is_android_client(request.headers):
return jsonify({"error": "Android only"}), 403
body = request.get_json(force=True, silent=True) or {}
device_id = body.get("device_id")
if not device_id:
return jsonify({"error": "device_id required"}), 400
try:
return jsonify(
storage.start_reference_point_session(
str(device_id),
body.get("label"),
_float_or_none(body.get("lat")),
_float_or_none(body.get("lon")),
body.get("meta") if isinstance(body.get("meta"), dict) else None,
)
)
except ValueError as e:
return jsonify({"error": str(e)}), 400
@app.post("/api/reference-points/<int:session_id>/samples")
def reference_points_samples(session_id: int):
if not is_android_client(request.headers):
return jsonify({"error": "Android only"}), 403
body = request.get_json(force=True, silent=True) or {}
samples = body.get("samples") or []
try:
return jsonify(storage.add_reference_point_samples(session_id, samples))
except ValueError as e:
return jsonify({"error": str(e)}), 400
@app.post("/api/reference-points/<int:session_id>/finish")
def reference_points_finish(session_id: int):
if not is_android_client(request.headers):
return jsonify({"error": "Android only"}), 403
try:
return jsonify(storage.finish_reference_point_session(session_id))
except ValueError as e:
return jsonify({"error": str(e)}), 400
@app.get("/api/reference-points")
def reference_points_list():
device_id = request.args.get("device_id")
limit = int(request.args.get("limit", 50))
return jsonify(storage.list_reference_point_sessions(device_id, limit))
@app.get("/api/reference-points/<int:session_id>")
def reference_points_get(session_id: int):
try:
return jsonify(storage.get_reference_point_session(session_id))
except ValueError as e:
return jsonify({"error": str(e)}), 404
@app.get("/api/macro-presets")
def macro_presets_list():
include_disabled = str(request.args.get("include_disabled", "")).lower()
return jsonify(storage.list_macro_presets(include_disabled in ("1", "true", "yes")))
@app.post("/api/macro-presets")
def macro_presets_post():
body = request.get_json(force=True, silent=True) or {}
try:
return jsonify(_upsert_macro_preset(body))
except ValueError as e:
return jsonify({"error": str(e)}), 400
@app.patch("/api/macro-presets/<preset_id>")
def macro_presets_patch(preset_id: str):
body = request.get_json(force=True, silent=True) or {}
body["id"] = preset_id
try:
return jsonify(_upsert_macro_preset(body))
except ValueError as e:
return jsonify({"error": str(e)}), 400
@app.delete("/api/macro-presets/<preset_id>")
def macro_presets_delete(preset_id: str):
try:
return jsonify(storage.delete_macro_preset(preset_id))
except ValueError as e:
return jsonify({"error": str(e)}), 404
def _upsert_macro_preset(body):
return storage.upsert_macro_preset(
body.get("id"),
body.get("name"),
body.get("description"),
body.get("params") if isinstance(body.get("params"), dict) else None,
body.get("lines") if isinstance(body.get("lines"), list) else None,
body.get("scope"),
body.get("device_role"),
bool(body.get("enabled", True)),
)
@app.post("/api/chat")
def post_chat():
body = request.get_json(force=True, silent=True) or {}