feat(server): modularize backend and admin console

This commit is contained in:
2026-07-14 01:38:41 +00:00
parent 9a6ac1e4ed
commit 95dd32c75a
261 changed files with 39289 additions and 2156 deletions
+36
View File
@@ -0,0 +1,36 @@
import db
def list_devices(app_id: str = "") -> list[dict]:
conn = db.get_conn()
if app_id:
rows = conn.execute("SELECT * FROM devices WHERE app_id=? ORDER BY last_seen_at DESC", (app_id,)).fetchall()
else:
rows = conn.execute("SELECT * FROM devices ORDER BY last_seen_at DESC LIMIT 500").fetchall()
conn.close()
return [
{
"device_id": row["device_id"],
"app_id": row["app_id"],
"installation_id": row["installation_id"],
"disabled": bool(row["disabled"]),
"disabled_reason": row["disabled_reason"],
"credential_seq": row["credential_seq"],
"first_seen_at": row["first_seen_at"],
"last_seen_at": row["last_seen_at"],
"last_ip": row["last_ip"],
}
for row in rows
]
def set_device_disabled(device_id: str, disabled: bool, reason: str) -> int:
conn = db.get_conn()
cur = conn.execute(
"UPDATE devices SET disabled=?,disabled_reason=? WHERE device_id=?",
(int(disabled), reason if disabled else "", device_id),
)
conn.commit()
updated = cur.rowcount
conn.close()
return updated