Load the key from STEAMBASE_STEAM_API_KEY or data/steam_api_key.txt, expose GET /api/steam/achievements/{appid} with a 15-minute in-memory cache, show progress in the game card, and report steam_api in /api/meta. The key is never logged or returned to clients.
This commit is contained in:
1 parent
fc113b8794
commit
5b1b23d392
16 files changed
+423
-8
No files matched your search
@@ -40,6 +40,7 @@ for stream in (sys.stdout, sys.stderr):
|
||||
import covers
|
||||
import db
|
||||
import reco
|
||||
import steam_api
|
||||
import steam_source
|
||||
import translate_details as td
|
||||
from fetch_details import fetch_app_details, save_details
|
||||
@@ -1007,6 +1008,12 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self._compare(qs)
|
||||
elif path == "/api/activity":
|
||||
self._activity(qs)
|
||||
elif path.startswith("/api/steam/achievements/"):
|
||||
tail = path.rsplit("/", 1)[1]
|
||||
if not tail.isdigit():
|
||||
self._error(400, "invalid appid")
|
||||
else:
|
||||
self._steam_achievements(int(tail))
|
||||
elif path == "/api/moods/export":
|
||||
self._export_moods(qs)
|
||||
elif path == "/api/descriptions":
|
||||
@@ -1114,6 +1121,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"genres": genres, "tags": tags, "statuses": statuses,
|
||||
"signals": signals, "hltb_checked": hltb_checked,
|
||||
"hltb_matched": hltb_matched,
|
||||
"steam_api": bool(steam_api.has_key() and steam_api.steam_id(con)),
|
||||
})
|
||||
finally:
|
||||
con.close()
|
||||
@@ -1330,6 +1338,28 @@ class Handler(BaseHTTPRequestHandler):
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def _steam_achievements(self, appid):
|
||||
con = connect()
|
||||
try:
|
||||
if not steam_api.has_key():
|
||||
self._error(400, "Steam API key is not configured")
|
||||
return
|
||||
steamid = steam_api.steam_id(con)
|
||||
if not steamid:
|
||||
self._error(400, "SteamID is not known; run import_steam.py")
|
||||
return
|
||||
try:
|
||||
data = steam_api.achievements(appid, steamid)
|
||||
except steam_api.SteamApiError as exc:
|
||||
self._error(502, str(exc))
|
||||
return
|
||||
if data is None:
|
||||
self._error(404, "no achievements for this game")
|
||||
return
|
||||
self._json(data)
|
||||
finally:
|
||||
con.close()
|
||||
|
||||
def _activity(self, qs):
|
||||
year = (qs.get("year", [""])[0] or "").strip()
|
||||
if year and (len(year) != 4 or not year.isdigit()):
|
||||
|
||||
Reference in new issue
Block a user