feat: hide games by series or tag
CI / test (push) Successful in 6m46s

This commit is contained in:
strsv committed 2026-11-06 20:58:25 +03:00
1 parent 419bd12dec
commit 710a9026df
12 files changed
+229 -11

No files matched your search

+77
View File
@@ -458,6 +458,29 @@ def serialize(r, tags, genres, details):
}
def scope_appids(con, scope, appid=None, tag=None):
"""Return appids for a series (by name) or a Steam tag."""
if scope == "series":
row = con.execute("SELECT appid, name FROM games WHERE appid = ? AND LOWER(type) = 'game'",
(appid,)).fetchone()
if not row:
return None
key = reco.series_key(row["name"])
return [r["appid"] for r in con.execute(
"SELECT appid, name FROM games WHERE LOWER(type) = 'game'")
if reco.series_key(r["name"]) == key]
if scope == "tag":
if not tag:
return None
return [r["appid"] for r in con.execute(
"""SELECT DISTINCT g.appid
FROM games g
JOIN game_tags gt ON gt.appid = g.appid
JOIN tag_names tn ON tn.tag_id = gt.tag_id
WHERE LOWER(g.type) = 'game' AND tn.name = ? COLLATE NOCASE""", (tag,))]
return None
def game_filters(qs):
"""Shared WHERE/ORDER construction for the library and export."""
def q(name, default=None):
@@ -618,6 +641,8 @@ class Handler(BaseHTTPRequestHandler):
self._update_personal_bulk(self._body())
elif path == "/api/personal/restore":
self._restore_personal(self._body())
elif path == "/api/personal/hide-scope":
self._hide_scope(self._body())
elif path.startswith("/api/personal/"):
appid = int(path.rsplit("/", 1)[1])
self._update_personal(appid, self._body())
@@ -1208,6 +1233,58 @@ class Handler(BaseHTTPRequestHandler):
finally:
con.close()
def _hide_scope(self, body):
scope = body.get("scope")
if scope not in ("series", "tag"):
self._error(400, "unknown scope")
return
appid = tag = None
try:
if body.get("appid") is not None:
appid = int(body["appid"])
except (TypeError, ValueError):
self._error(400, "invalid appid")
return
if scope == "series" and appid is None:
self._error(400, "invalid appid")
return
if scope == "tag":
tag = (body.get("tag") or "").strip()
if not tag:
self._error(400, "empty tag")
return
con = connect()
try:
ids = scope_appids(con, scope, appid=appid, tag=tag)
if ids is None:
self._error(404, "unknown appid")
return
if not ids:
self._error(404, "no games")
return
placeholders = ",".join("?" * len(ids))
rows = con.execute(
f"""SELECT appid, COALESCE(status, 'backlog') status,
COALESCE(favorite, 0) favorite
FROM personal WHERE appid IN ({placeholders})""", ids).fetchall()
previous_map = {r["appid"]: {"appid": r["appid"], "status": r["status"],
"favorite": r["favorite"]} for r in rows}
previous = [previous_map.get(appid_value,
{"appid": appid_value, "status": "backlog",
"favorite": 0}) for appid_value in ids]
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
con.executemany(
"INSERT OR IGNORE INTO personal (appid, status, updated_at) "
"VALUES (?, 'backlog', ?)", [(value, now) for value in ids])
con.execute(
f"UPDATE personal SET status = 'ignore', updated_at = ? "
f"WHERE appid IN ({placeholders})", [now, *ids])
con.commit()
self._json({"updated": len(ids), "appids": ids, "previous": previous})
finally:
con.close()
def _restore_personal(self, body):
items = []
for item in body.get("items") or []: