Improve machines page: online status, formatted time, delete unbound placeholders.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -493,6 +493,24 @@ def delete_account(conn: sqlite3.Connection, account_id: int) -> None:
|
||||
conn.execute("DELETE FROM accounts WHERE id=?", (account_id,))
|
||||
|
||||
|
||||
def delete_machine(conn: sqlite3.Connection, machine_id: int) -> None:
|
||||
"""删除机器。在线中的不允许删;相关激活/成交仅解除 machine 引用。"""
|
||||
m = conn.execute("SELECT * FROM machines WHERE id=?", (machine_id,)).fetchone()
|
||||
if not m:
|
||||
raise ValueError("机器不存在")
|
||||
last = m["last_seen_at"]
|
||||
online = False
|
||||
try:
|
||||
online = bool(last and (now() - float(last)) <= ONLINE_SECONDS)
|
||||
except (TypeError, ValueError):
|
||||
online = False
|
||||
if online:
|
||||
raise ValueError("机器当前在线,请先关闭客户端后再删")
|
||||
conn.execute("UPDATE activations SET machine_id=NULL WHERE machine_id=?", (machine_id,))
|
||||
conn.execute("UPDATE trades SET machine_id=NULL WHERE machine_id=?", (machine_id,))
|
||||
conn.execute("DELETE FROM machines WHERE id=?", (machine_id,))
|
||||
|
||||
|
||||
def create_user(
|
||||
conn: sqlite3.Connection,
|
||||
username: str,
|
||||
|
||||
Reference in New Issue
Block a user