Refresh stale butlerd Fetch.* data (owned keys, caves, uploads) so a cold database doesn't report an empty library or no compatible uploads
This commit is contained in:
parent
e8111f89c2
commit
c4fdd2f974
2 changed files with 41 additions and 5 deletions
|
|
@ -366,12 +366,24 @@ func get_owned_games() -> Array:
|
||||||
func _get_owned_games() -> Array:
|
func _get_owned_games() -> Array:
|
||||||
if not is_logged_in:
|
if not is_logged_in:
|
||||||
return []
|
return []
|
||||||
var res := await _rpc_call("Fetch.ProfileOwnedKeys", {
|
var params := {
|
||||||
"profileId": profile.get("user", {}).get("id", profile.get("id", 0)),
|
"profileId": profile.get("user", {}).get("id", profile.get("id", 0)),
|
||||||
})
|
}
|
||||||
|
var res := await _rpc_call("Fetch.ProfileOwnedKeys", params)
|
||||||
if "error" in res:
|
if "error" in res:
|
||||||
logger.warn("Fetch.ProfileOwnedKeys failed: " + str(res["error"]))
|
logger.warn("Fetch.ProfileOwnedKeys failed: " + str(res["error"]))
|
||||||
return []
|
return []
|
||||||
|
# butlerd serves Fetch.* results from its local cache by default and only
|
||||||
|
# sets `stale` when the data hasn't been pulled from itch.io recently. On
|
||||||
|
# a fresh database that cache is empty, so without this refresh the
|
||||||
|
# library would stay empty until the daemon happens to refresh on its own.
|
||||||
|
if res.get("stale", false):
|
||||||
|
logger.info("Owned keys are stale. Refreshing from itch.io.")
|
||||||
|
params["fresh"] = true
|
||||||
|
res = await _rpc_call("Fetch.ProfileOwnedKeys", params)
|
||||||
|
if "error" in res:
|
||||||
|
logger.warn("Fetch.ProfileOwnedKeys (fresh) failed: " + str(res["error"]))
|
||||||
|
return []
|
||||||
return res.get("items", [])
|
return res.get("items", [])
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -381,10 +393,18 @@ func get_caves() -> Array:
|
||||||
|
|
||||||
|
|
||||||
func _get_caves() -> Array:
|
func _get_caves() -> Array:
|
||||||
var res := await _rpc_call("Fetch.Caves", {})
|
var params := {}
|
||||||
|
var res := await _rpc_call("Fetch.Caves", params)
|
||||||
if "error" in res:
|
if "error" in res:
|
||||||
logger.warn("Fetch.Caves failed: " + str(res["error"]))
|
logger.warn("Fetch.Caves failed: " + str(res["error"]))
|
||||||
return []
|
return []
|
||||||
|
if res.get("stale", false):
|
||||||
|
logger.info("Caves are stale. Refreshing from itch.io.")
|
||||||
|
params["fresh"] = true
|
||||||
|
res = await _rpc_call("Fetch.Caves", params)
|
||||||
|
if "error" in res:
|
||||||
|
logger.warn("Fetch.Caves (fresh) failed: " + str(res["error"]))
|
||||||
|
return []
|
||||||
return res.get("items", [])
|
return res.get("items", [])
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -416,7 +436,23 @@ func _install(game: Dictionary, cave_id: String) -> void:
|
||||||
var game_id: int = game.get("id", 0)
|
var game_id: int = game.get("id", 0)
|
||||||
var reason := "update" if cave_id != "" else "install"
|
var reason := "update" if cave_id != "" else "install"
|
||||||
|
|
||||||
var uploads_res := await _rpc_call("Fetch.GameUploads", {"gameId": game_id, "compatible": true})
|
var uploads_params := {"gameId": game_id, "compatible": true}
|
||||||
|
var uploads_res := await _rpc_call("Fetch.GameUploads", uploads_params)
|
||||||
|
if "error" in uploads_res:
|
||||||
|
logger.warn("Fetch.GameUploads failed: " + str(uploads_res["error"]))
|
||||||
|
emit_signal.call_deferred("app_installed", cave_id, false)
|
||||||
|
return
|
||||||
|
# Uploads are cached by butlerd just like owned keys, so retry fresh when
|
||||||
|
# the cached result is stale, otherwise a cold database would report every
|
||||||
|
# game as having no compatible upload.
|
||||||
|
if uploads_res.get("stale", false):
|
||||||
|
logger.info("Uploads are stale. Refreshing from itch.io.")
|
||||||
|
uploads_params["fresh"] = true
|
||||||
|
uploads_res = await _rpc_call("Fetch.GameUploads", uploads_params)
|
||||||
|
if "error" in uploads_res:
|
||||||
|
logger.warn("Fetch.GameUploads (fresh) failed: " + str(uploads_res["error"]))
|
||||||
|
emit_signal.call_deferred("app_installed", cave_id, false)
|
||||||
|
return
|
||||||
var uploads: Array = uploads_res.get("uploads", [])
|
var uploads: Array = uploads_res.get("uploads", [])
|
||||||
if uploads.is_empty():
|
if uploads.is_empty():
|
||||||
logger.error("No compatible uploads found for game id " + str(game_id))
|
logger.error("No compatible uploads found for game id " + str(game_id))
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"plugin.id": "itch",
|
"plugin.id": "itch",
|
||||||
"plugin.name": "itch.io",
|
"plugin.name": "itch.io",
|
||||||
"plugin.version": "0.1.1",
|
"plugin.version": "0.1.3",
|
||||||
"plugin.min-api-version": "1.1.0",
|
"plugin.min-api-version": "1.1.0",
|
||||||
"plugin.link": "https://github.com/YOUR_USERNAME/OpenGamepadUI-itch",
|
"plugin.link": "https://github.com/YOUR_USERNAME/OpenGamepadUI-itch",
|
||||||
"plugin.source": "https://github.com/YOUR_USERNAME/OpenGamepadUI-itch",
|
"plugin.source": "https://github.com/YOUR_USERNAME/OpenGamepadUI-itch",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue