mirror of
https://github.com/rommapp/romm.git
synced 2026-12-03 10:33:22 +01:00
fix(steam): read appdetails envelope keyed by another app ID (#4774)
* fix(steam): read appdetails envelope keyed by another app ID Steam's appdetails endpoint keys some responses by a different ID than the one requested (e.g. app 242820 "140" comes back under its DLC ID 662290), so the lookup by the requested ID missed and the scraper returned no metadata. Only one app is requested per call, so fall back to the sole envelope when the requested key is absent. Fixes #4773 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QRCSTxaQC8momzANdULG7H * fix(steam): only accept a re-keyed envelope for the requested app Validate that the sole envelope is a mapping whose data.steam_appid matches the requested app before using it, so a mismatched or malformed response degrades to no result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QRCSTxaQC8momzANdULG7H --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -139,12 +139,28 @@ class SteamService:
|
||||
query["filters"] = filters
|
||||
url = self.url.joinpath("appdetails").with_query(query)
|
||||
response = await self._request(str(url))
|
||||
envelope = cast(SteamAppDetailsEnvelope | None, response.get(str(app_id)))
|
||||
envelope = response.get(str(app_id))
|
||||
if envelope is None and len(response) == 1:
|
||||
envelope = self._envelope_keyed_by_another_id(response, app_id)
|
||||
envelope = cast(SteamAppDetailsEnvelope | None, envelope)
|
||||
if not envelope or not envelope.get("success"):
|
||||
return None
|
||||
|
||||
return envelope.get("data")
|
||||
|
||||
@staticmethod
|
||||
def _envelope_keyed_by_another_id(response: dict, app_id: int) -> dict | None:
|
||||
"""Steam keys some apps' envelope by another ID, e.g. one of their DLC."""
|
||||
envelope = next(iter(response.values()))
|
||||
if not isinstance(envelope, dict):
|
||||
return None
|
||||
|
||||
data = envelope.get("data")
|
||||
if not isinstance(data, dict) or data.get("steam_appid") != app_id:
|
||||
return None
|
||||
|
||||
return envelope
|
||||
|
||||
async def get_library_capsule_url(self, app_id: int) -> str | None:
|
||||
"""The portrait capsule URL when the CDN serves one, else None."""
|
||||
return await self._probe_cdn_asset(
|
||||
|
||||
@@ -66,6 +66,36 @@ async def test_get_app_details_unwraps_envelope(session):
|
||||
assert details == {"type": "game", "name": "Portal"}
|
||||
|
||||
|
||||
async def test_get_app_details_unwraps_envelope_keyed_by_another_id(session):
|
||||
"""Steam keys some apps' details by a DLC ID instead of the requested one."""
|
||||
session.get.return_value = _response(
|
||||
{
|
||||
"662290": {
|
||||
"success": True,
|
||||
"data": {"type": "game", "name": "140", "steam_appid": 242820},
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
details = await SteamService().get_app_details(242820)
|
||||
|
||||
assert details == {"type": "game", "name": "140", "steam_appid": 242820}
|
||||
|
||||
|
||||
async def test_get_app_details_rejects_envelope_for_another_app(session):
|
||||
session.get.return_value = _response(
|
||||
{"662290": {"success": True, "data": {"type": "dlc", "steam_appid": 662290}}}
|
||||
)
|
||||
|
||||
assert await SteamService().get_app_details(242820) is None
|
||||
|
||||
|
||||
async def test_get_app_details_rejects_a_sole_value_that_is_not_an_envelope(session):
|
||||
session.get.return_value = _response({"error": "unavailable"})
|
||||
|
||||
assert await SteamService().get_app_details(242820) is None
|
||||
|
||||
|
||||
async def test_get_app_details_returns_none_on_unsuccessful_envelope(session):
|
||||
"""Steam reports an unknown or region-locked app as success: false."""
|
||||
session.get.return_value = _response({"400": {"success": False}})
|
||||
|
||||
Reference in New Issue
Block a user