feat: add HLTB status page and refresh installs incrementally
CI / test (push) Successful in 2m57s

This commit is contained in:
strsv committed 2026-11-06 23:14:54 +03:00
1 parent d92c7a1964
commit 31f94997d5
13 files changed
+255 -9

No files matched your search

+54
View File
@@ -894,6 +894,8 @@ class Handler(BaseHTTPRequestHandler):
self._games(qs)
elif path == "/api/export":
self._export(qs)
elif path == "/api/hltb/status":
self._hltb_status(qs)
elif path == "/api/moods":
self._moods()
elif path == "/api/descriptions":
@@ -1039,6 +1041,58 @@ class Handler(BaseHTTPRequestHandler):
finally:
con.close()
def _hltb_status(self, qs):
def q(name, default=None):
return qs.get(name, [default])[0]
where = ["LOWER(g.type) = 'game'", "g.hltb_checked_at IS NOT NULL"]
params = []
status = q("status")
if status == "match":
where.append("g.hltb_match = 1")
elif status == "miss":
where.append("COALESCE(g.hltb_match, 0) = 0")
if q("q"):
where.append("g.name LIKE ? COLLATE NOCASE")
params.append(f"%{q('q')}%")
try:
limit = max(1, min(500, int(q("limit", "100") or 100)))
offset = max(0, int(q("offset", "0") or 0))
except (TypeError, ValueError):
self._error(400, "invalid pagination")
return
base = f"FROM games g WHERE {' AND '.join(where)}"
con = connect()
try:
total = con.execute(f"SELECT COUNT(*) c {base}", params).fetchone()["c"]
checked = con.execute(
"""SELECT COUNT(*) FROM games WHERE LOWER(type)='game'
AND hltb_checked_at IS NOT NULL""").fetchone()[0]
matched = con.execute(
"""SELECT COUNT(*) FROM games WHERE LOWER(type)='game'
AND hltb_match = 1""").fetchone()[0]
rows = con.execute(
f"""SELECT g.appid, g.name, g.hltb_match, g.hltb_main, g.hltb_extra,
g.hltb_complete, g.hltb_id, g.hltb_checked_at, g.hltb_updated_at
{base} ORDER BY g.hltb_checked_at DESC, g.name
LIMIT ? OFFSET ?""", [*params, limit, offset]).fetchall()
items = [{
"appid": row["appid"],
"name": row["name"],
"status": "match" if row["hltb_match"] else "miss",
"main": row["hltb_main"],
"extra": row["hltb_extra"],
"complete": row["hltb_complete"],
"hltb_id": row["hltb_id"],
"checked_at": row["hltb_checked_at"],
"updated_at": row["hltb_updated_at"],
} for row in rows]
self._json({"total": total, "checked": checked, "matched": matched,
"limit": limit, "offset": offset, "items": items})
finally:
con.close()
def _export(self, qs):
fmt = (qs.get("format", ["csv"])[0] or "csv").lower()
if fmt not in ("csv", "json"):