feat: add bulk actions for selected games
CI / test (push) Successful in 19s

This commit is contained in:
strsv committed 2026-11-06 08:51:31 +03:00
1 parent 17e5805b2e
commit c811107776
11 files changed
+253 -12

No files matched your search

+49
View File
@@ -510,6 +510,8 @@ class Handler(BaseHTTPRequestHandler):
ids = self._missing_ids(body.get("limit", 200), bool(body.get("retry_missing")))
DETAILS.enqueue_many(ids)
self._json({"queued": len(ids)})
elif path == "/api/personal/bulk":
self._update_personal_bulk(self._body())
elif path.startswith("/api/personal/"):
appid = int(path.rsplit("/", 1)[1])
self._update_personal(appid, self._body())
@@ -958,6 +960,53 @@ class Handler(BaseHTTPRequestHandler):
finally:
con.close()
def _update_personal_bulk(self, body):
appids = []
for value in body.get("appids") or []:
try:
appid = int(value)
except (TypeError, ValueError):
continue
if appid not in appids:
appids.append(appid)
if not appids:
self._error(400, "no appids")
return
sets, vals = [], []
if body.get("status") in STATUSES:
sets.append("status=?")
vals.append(body["status"])
if "favorite" in body:
sets.append("favorite=?")
vals.append(1 if body["favorite"] else 0)
if not sets:
self._error(400, "nothing to update")
return
con = connect()
try:
placeholders = ",".join("?" * len(appids))
existing = [r["appid"] for r in con.execute(
f"SELECT appid FROM games WHERE appid IN ({placeholders})", appids)]
if not existing:
self._error(404, "unknown appids")
return
now = datetime.now(timezone.utc).isoformat(timespec="seconds")
con.executemany(
"INSERT OR IGNORE INTO personal (appid, status, updated_at) VALUES (?, 'backlog', ?)",
[(appid, now) for appid in existing])
sets.append("updated_at=?")
vals.append(now)
con.execute(
f"UPDATE personal SET {', '.join(sets)} "
f"WHERE appid IN ({','.join('?' * len(existing))})",
[*vals, *existing])
con.commit()
self._json({"updated": len(existing)})
finally:
con.close()
def _update_personal(self, appid, body):
con = connect()
try: