Ship a health-management BMI home for review, keep the nomad hub as hub, and let admin switch platforms.tt.homeVariant live with track/ntfy; fix tt config fetch to api.nomadro.cn/api/config. Co-authored-by: Cursor <cursoragent@cursor.com>
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Verify realtime homeVariant PUT + config_change track."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
BASE = "https://admin.nomadro.cn"
|
|
|
|
|
|
def req(method: str, path: str, token: str | None = None, body: dict | None = None):
|
|
data = None if body is None else json.dumps(body).encode()
|
|
headers = {"Content-Type": "application/json"}
|
|
if token:
|
|
headers["Authorization"] = f"Bearer {token}"
|
|
r = urllib.request.Request(BASE + path, data=data, headers=headers, method=method)
|
|
with urllib.request.urlopen(r, timeout=25) as resp:
|
|
return json.loads(resp.read().decode())
|
|
|
|
|
|
def main() -> int:
|
|
login = req("POST", "/api/admin/login", body={"username": "admin", "password": "Xiao4669805"})
|
|
token = login.get("token") or login.get("access_token")
|
|
if not token:
|
|
print("login fail", login)
|
|
return 1
|
|
before = req("GET", "/api/admin/douyin/config", token=token)
|
|
hv = (before.get("config") or {}).get("homeVariant") or "bmi"
|
|
print("before", hv)
|
|
target = "bmi" if hv == "hub" else "hub"
|
|
put = req("PUT", "/api/admin/douyin/config", token=token, body={"homeVariant": target})
|
|
after = (put.get("config") or {}).get("homeVariant")
|
|
print("after", after, "ok", put.get("ok"))
|
|
# restore
|
|
req("PUT", "/api/admin/douyin/config", token=token, body={"homeVariant": hv})
|
|
print("restored", hv)
|
|
|
|
events = req("GET", "/api/admin/track-events?limit=5&name=config_change", token=token)
|
|
rows = events.get("events") or events.get("items") or events
|
|
if isinstance(rows, dict):
|
|
rows = rows.get("events") or []
|
|
print("recent config_change count sample", len(rows) if isinstance(rows, list) else type(rows))
|
|
if isinstance(rows, list) and rows:
|
|
e0 = rows[0]
|
|
print("latest", e0.get("name"), e0.get("label"), e0.get("client"))
|
|
return 0 if after == target else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|