Commit b4a5190c authored by Alex Smith's avatar Alex Smith

cache on getSteamId

parent aea3d99a
......@@ -92,17 +92,29 @@ getAppId() {
getSteamId() {
unset SteamAppId
NOSTAPPNAME="$1"
if [[ -n "${NOSTAPPNAME}" ]]; then
local cache_file="${PORT_WINE_TMP_PATH:-/tmp}/steamid_cache.json"
[[ -n "${1:-}" ]] && NOSTAPPNAME="$1"
if [[ -z "${SteamIds:-}" ]] && [[ -f "${cache_file}" ]]; then
SteamIds=$(<"${cache_file}")
fi
if [[ -n "${SteamIds:-}" ]] && jq -e --arg key "$NOSTAPPNAME" 'has($key)' <<< "${SteamIds}" > /dev/null; then
SteamAppId=$(jq -r --arg key "${NOSTAPPNAME}" '.[$key]' <<< "${SteamIds}")
else
if [[ -n "${1:-}" ]]; then
getSteamGridDBId "${NOSTAPPNAME}" > /dev/null
fi
if [[ $SteamGridDBTypeSteam == true ]]; then
SRES=$(curl -Ls -e "https://www.steamgriddb.com/game/${SteamGridDBId}" "https://www.steamgriddb.com/api/public/game/${SteamGridDBId}")
if jq -e ".success == true" <<< "${SRES}" > /dev/null 2>&1; then
SteamAppId="$(jq -r '.data.platforms.steam.id' <<< "${SRES}")"
echo ${SteamAppId}
fi
fi
SteamIds=$(jq --arg key "${NOSTAPPNAME}" --arg value "${SteamAppId:-}" '. + {($key): $value}' <<< "${SteamIds:-$(jq -n '{}')}")
echo "${SteamIds}" > "${cache_file}"
fi
if [[ -n "${SteamAppId:-}" ]]; then
echo "${SteamAppId}"
fi
}
getSteamGridDBId() {
......@@ -116,7 +128,7 @@ getSteamGridDBId() {
SteamGridDBTypeSteam=false
fi
SteamGridDBId="$(jq '.data[0].id' <<< "${SGDBRES}")"
echo ${SteamGridDBId}
echo "${SteamGridDBId}"
fi
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment