Merge pull request #10 from jasonMPM/v7
Update app.py
This commit was merged in pull request #10.
This commit is contained in:
36
app.py
36
app.py
@@ -158,7 +158,11 @@ def receive_webhook():
|
||||
# Data block per UniFi Access docs: payload["data"]["actor"], ["event"], etc.
|
||||
data = payload.get("data") or {}
|
||||
actor_obj = data.get("actor") or {}
|
||||
actor = actor_obj.get("id") or payload.get("actor_id", "")
|
||||
actor = (
|
||||
actor_obj.get("id")
|
||||
or actor_obj.get("identity_id")
|
||||
or payload.get("actor_id", "")
|
||||
)
|
||||
|
||||
if "access.door.unlock" not in str(event):
|
||||
# Ignore other notification types
|
||||
@@ -256,6 +260,36 @@ def reset_day():
|
||||
return jsonify({"status": "ok", "deleted": cur.rowcount, "date": date})
|
||||
|
||||
|
||||
@app.route("/api/debug-user-cache")
|
||||
def debug_user_cache():
|
||||
"""Temporary helper to see what the Access API returns for a webhook actor."""
|
||||
actor_id = request.args.get("actor_id", "").strip()
|
||||
if not actor_id:
|
||||
return jsonify({"error": "missing actor_id"}), 400
|
||||
|
||||
try:
|
||||
r = requests.get(
|
||||
f"{UNIFI_BASE}/users/search",
|
||||
headers={"Authorization": f"Bearer {UNIFI_TOKEN}"},
|
||||
params={"userid": actor_id},
|
||||
verify=False,
|
||||
timeout=10,
|
||||
)
|
||||
try:
|
||||
data = r.json()
|
||||
except Exception:
|
||||
data = {"raw": r.text[:500]}
|
||||
return jsonify(
|
||||
{
|
||||
"status_code": r.status_code,
|
||||
"actor_id_param": actor_id,
|
||||
"response": data,
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
# Initialise DB and kick off background scheduler at import time
|
||||
with app.app_context():
|
||||
init_db()
|
||||
|
||||
Reference in New Issue
Block a user