Improve machines page: online status, formatted time, delete unbound placeholders.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-17 20:59:52 +08:00
parent 679b55f1db
commit ba74a9cce8
3 changed files with 78 additions and 26 deletions
+16 -15
View File
@@ -321,22 +321,12 @@ def register_routes(app: Flask) -> None:
@app.get("/machines")
@login_required
def machines_page():
# 机器列表:管理员全看;普通用户只看与自己账户激活相关的机器
u = current_user()
with database.get_db() as conn:
if u["role"] == "admin":
items = database.list_machines(conn)
else:
cur = conn.execute(
"""
SELECT DISTINCT m.* FROM machines m
JOIN activations act ON act.machine_id = m.id
WHERE act.account_id=?
ORDER BY m.id DESC
""",
(u.get("account_id"),),
)
items = [database.row_to_dict(r) for r in cur.fetchall()]
items = database.list_machines_for_user(conn, u)
for m in items:
m["last_seen_fmt"] = _fmt_ts(m.get("last_seen_at"))
m["bound"] = bool(m.get("device_fingerprint"))
return render_template("machines.html", items=items, is_admin=(u["role"] == "admin"))
@app.post("/machines")
@@ -349,7 +339,7 @@ def register_routes(app: Flask) -> None:
VALUES(?,?,?,?,?)""",
(name, "", (request.form.get("note") or "").strip(), 1, database.now()),
)
flash("机器已添加", "ok")
flash("机器已添加(预登记,激活后绑定指纹)", "ok")
return redirect(url_for("machines_page"))
@app.post("/machines/<int:mid>/note")
@@ -365,6 +355,17 @@ def register_routes(app: Flask) -> None:
flash("机器标注已保存", "ok")
return redirect(url_for("machines_page"))
@app.post("/machines/<int:mid>/delete")
@admin_required
def machines_delete(mid: int):
try:
with database.get_db() as conn:
database.delete_machine(conn, mid)
flash("机器已删除", "ok")
except ValueError as exc:
flash(str(exc), "error")
return redirect(url_for("machines_page"))
# ---------- 下载 / 激活(管理员与用户都可发码;用户仅自己账户)----------
@app.get("/download")
@login_required