feat: distinguish owned and shared games
CI / test (push) Successful in 40s

Add game_ownership (schema v10) and tools/check_ownership.py, compare the local library with GetOwnedGames, expose owned/shared counts and filters, and show a shared-game badge on cards.
This commit is contained in:
strsv committed 2026-11-07 01:40:47 +03:00
1 parent 528fcb7474
commit 2ed00b7912
18 files changed
+255 -10

No files matched your search

+21 -3
View File
@@ -555,6 +555,7 @@ def serialize(r, tags, genres, details):
"complete": r["hltb_complete"] if "hltb_complete" in r.keys() else None,
} if "hltb_main" in r.keys() and r["hltb_main"] else None,
"installed": bool(r["installed"]),
"owned": r["owned"] if "owned" in r.keys() else None,
"status": r["status"],
"rating": r["rating"],
"favorite": bool(r["favorite"]),
@@ -617,6 +618,11 @@ def game_filters(qs):
where.append(f"""EXISTS (SELECT 1 FROM game_tags gt JOIN tag_names tn ON tn.tag_id=gt.tag_id
WHERE gt.appid=g.appid AND tn.name IN ({placeholders}))""")
params.extend(tags)
ownership = q("ownership")
if ownership == "owned":
where.append("o.owned = 1")
elif ownership == "shared":
where.append("o.owned = 0")
if q("status"):
where.append("COALESCE(pe.status,'backlog') = ?")
params.append(q("status"))
@@ -1121,6 +1127,11 @@ class Handler(BaseHTTPRequestHandler):
hltb_matched = con.execute(
"""SELECT COUNT(*) FROM games WHERE LOWER(type)='game'
AND hltb_match = 1""").fetchone()[0]
ownership = con.execute(
"""SELECT COALESCE(SUM(CASE WHEN o.owned=1 THEN 1 ELSE 0 END), 0) AS owned,
COALESCE(SUM(CASE WHEN o.owned=0 THEN 1 ELSE 0 END), 0) AS shared
FROM game_ownership o JOIN games g ON g.appid=o.appid
WHERE LOWER(g.type)='game'""").fetchone()
self._json({
"total": total, "installed": installed, "played": played,
"hours": round(minutes / 60), "cached": cached, "missing": missing,
@@ -1129,6 +1140,7 @@ class Handler(BaseHTTPRequestHandler):
"genres": genres, "tags": tags, "statuses": statuses,
"signals": signals, "hltb_checked": hltb_checked,
"hltb_matched": hltb_matched,
"owned": ownership["owned"], "shared": ownership["shared"],
"steam_api": bool(steam_api.has_key() and steam_api.steam_id(con)),
})
finally:
@@ -1144,6 +1156,7 @@ class Handler(BaseHTTPRequestHandler):
LEFT JOIN game_install i ON i.appid=g.appid
LEFT JOIN personal pe ON pe.appid=g.appid
LEFT JOIN game_details d ON d.appid=g.appid
LEFT JOIN game_ownership o ON o.appid=g.appid
WHERE {' AND '.join(where)}"""
con = connect()
try:
@@ -1153,7 +1166,7 @@ class Handler(BaseHTTPRequestHandler):
g.estimated_hours, g.hltb_main, g.hltb_extra, g.hltb_complete,
COALESCE(p.minutes,0) minutes, COALESCE(i.installed,0) installed,
COALESCE(pe.status,'backlog') status, pe.rating,
COALESCE(pe.favorite,0) favorite, pe.notes
COALESCE(pe.favorite,0) favorite, pe.notes, o.owned
{base} ORDER BY {order} LIMIT ? OFFSET ?""",
[*params, per_page, (page - 1) * per_page]).fetchall()
ids = [r["appid"] for r in rows]
@@ -1231,6 +1244,7 @@ class Handler(BaseHTTPRequestHandler):
LEFT JOIN game_install i ON i.appid=g.appid
LEFT JOIN personal pe ON pe.appid=g.appid
LEFT JOIN game_details d ON d.appid=g.appid
LEFT JOIN game_ownership o ON o.appid=g.appid
WHERE {' AND '.join(where)}"""
con = connect()
try:
@@ -1239,7 +1253,7 @@ class Handler(BaseHTTPRequestHandler):
g.estimated_hours, COALESCE(p.minutes,0) minutes, p.last_played,
COALESCE(i.installed,0) installed, i.size_bytes,
COALESCE(pe.status,'backlog') status, pe.rating,
COALESCE(pe.favorite,0) favorite
COALESCE(pe.favorite,0) favorite, o.owned
{base} ORDER BY {order}""", params).fetchall()
ids = [row["appid"] for row in rows]
tags = game_tags_map(con, ids)
@@ -1263,6 +1277,7 @@ class Handler(BaseHTTPRequestHandler):
"rating": row["rating"],
"favorite": bool(row["favorite"]),
"installed": bool(row["installed"]),
"owned": row["owned"],
"size_gb": round((row["size_bytes"] or 0) / (1024 ** 3), 2),
"last_played": row["last_played"],
"genres": genres.get(row["appid"], []),
@@ -1305,11 +1320,13 @@ class Handler(BaseHTTPRequestHandler):
COALESCE(p.minutes,0) minutes, p.last_played,
COALESCE(i.installed,0) installed, i.size_bytes,
COALESCE(pe.status,'backlog') status, pe.rating,
COALESCE(pe.favorite,0) favorite, pe.notes
COALESCE(pe.favorite,0) favorite, pe.notes,
o.owned, o.checked_at AS ownership_checked_at
FROM games g
JOIN game_playtime p ON p.appid=g.appid
LEFT JOIN game_install i ON i.appid=g.appid
LEFT JOIN personal pe ON pe.appid=g.appid
LEFT JOIN game_ownership o ON o.appid=g.appid
WHERE g.appid = ?""", (appid,)).fetchone()
if not r:
self._error(404, "unknown appid")
@@ -1325,6 +1342,7 @@ class Handler(BaseHTTPRequestHandler):
item.update({
"size_gb": round((r["size_bytes"] or 0) / (1024 ** 3), 1),
"last_played": r["last_played"],
"ownership_checked_at": r["ownership_checked_at"],
"about": (d["about_ru"] or d["about"]) if d else None,
"steam_url": f"https://store.steampowered.com/app/{appid}/",
})