new version

This commit is contained in:
2026-04-20 09:00:42 +02:00
parent a2358ed0c3
commit c7ff9f162c
7 changed files with 291 additions and 28 deletions

View File

@@ -16,15 +16,22 @@ def init_db():
conn = _conn()
conn.executescript('''
CREATE TABLE IF NOT EXISTS players (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
online INTEGER NOT NULL DEFAULT 0,
last_seen TEXT,
updating INTEGER NOT NULL DEFAULT 0,
registered INTEGER NOT NULL DEFAULT 0,
workspace_name TEXT,
player_type TEXT,
updated_at TEXT NOT NULL
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
online INTEGER NOT NULL DEFAULT 0,
last_seen TEXT,
updating INTEGER NOT NULL DEFAULT 0,
registered INTEGER NOT NULL DEFAULT 0,
workspace_name TEXT,
player_type TEXT,
updated_at TEXT NOT NULL,
last_pushed TEXT,
last_ip_address TEXT,
status_last_updated TEXT,
screen_resolution TEXT,
hardware_version TEXT,
hostname TEXT,
eth0_ip TEXT
);
CREATE TABLE IF NOT EXISTS logs (
@@ -37,6 +44,21 @@ def init_db():
CREATE INDEX IF NOT EXISTS idx_logs_ts ON logs(timestamp DESC);
''')
# Migrate existing databases that predate the new columns
new_cols = [
('last_pushed', 'TEXT'),
('last_ip_address', 'TEXT'),
('status_last_updated', 'TEXT'),
('screen_resolution', 'TEXT'),
('hardware_version', 'TEXT'),
('hostname', 'TEXT'),
('eth0_ip', 'TEXT'),
]
for col, typ in new_cols:
try:
conn.execute(f'ALTER TABLE players ADD COLUMN {col} {typ}')
except Exception:
pass # column already exists
conn.commit()
conn.close()
@@ -44,21 +66,33 @@ def init_db():
def upsert_player(p):
state = p.get('state', {})
workspace = p.get('workspace', {})
ps = p.get('player_status') or {}
res = ps.get('screen_resolution')
eth0 = (ps.get('public_ip') or {}).get('eth0') or {}
now = datetime.now(timezone.utc).isoformat()
conn = _conn()
conn.execute('''
INSERT INTO players (id, name, online, last_seen, updating, registered,
workspace_name, player_type, updated_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
workspace_name, player_type, updated_at,
last_pushed, last_ip_address, status_last_updated,
screen_resolution, hardware_version, hostname, eth0_ip)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET
name = excluded.name,
online = excluded.online,
last_seen = excluded.last_seen,
updating = excluded.updating,
registered = excluded.registered,
workspace_name = excluded.workspace_name,
player_type = excluded.player_type,
updated_at = excluded.updated_at
name = excluded.name,
online = excluded.online,
last_seen = excluded.last_seen,
updating = excluded.updating,
registered = excluded.registered,
workspace_name = excluded.workspace_name,
player_type = excluded.player_type,
updated_at = excluded.updated_at,
last_pushed = excluded.last_pushed,
last_ip_address = excluded.last_ip_address,
status_last_updated = excluded.status_last_updated,
screen_resolution = excluded.screen_resolution,
hardware_version = excluded.hardware_version,
hostname = excluded.hostname,
eth0_ip = excluded.eth0_ip
''', (
p['id'],
p['name'],
@@ -69,6 +103,13 @@ def upsert_player(p):
workspace.get('name'),
p.get('player_type'),
now,
p.get('last_pushed'),
p.get('last_ip_address'),
ps.get('status_last_updated'),
f"{res[0]}x{res[1]}" if isinstance(res, list) and len(res) == 2 else None,
ps.get('hardware_version'),
ps.get('hostname'),
eth0.get('ip_v4'),
))
conn.commit()
conn.close()