Skip to content

Commit

Permalink
Add timeout to version and banner checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostbyte0x70 committed Oct 31, 2024
1 parent 382e530 commit efcc863
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions skytemple_files/common/version_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
RELEASE_WEB = "https://release.skytemple.org/"
BANNER_LINK = "banner"
BANNER_IMG = "banner.png"
CONNECTION_TIMEOUT = 4


class ReleaseType(Enum):
Expand All @@ -35,13 +36,16 @@ def check_newest_release(rtype: ReleaseType) -> str:
Returns the newest release using release.skytemple.org.
May fail if no connection can be established!
"""
return urllib.request.urlopen(RELEASE_WEB + rtype.value, context=create_context()).read().decode("utf-8").strip()
return (urllib.request.urlopen(RELEASE_WEB + rtype.value, context=create_context(), timeout=CONNECTION_TIMEOUT)
.read().decode("utf-8").strip())


def get_event_banner() -> tuple[bytes | None, str | None]:
try:
url = urllib.request.urlopen(RELEASE_WEB + BANNER_LINK, context=create_context()).read().decode("utf-8").strip()
img = urllib.request.urlopen(RELEASE_WEB + BANNER_IMG, context=create_context()).read()
url = (urllib.request.urlopen(RELEASE_WEB + BANNER_LINK, context=create_context(), timeout=CONNECTION_TIMEOUT)
.read().decode("utf-8").strip())
img = (urllib.request.urlopen(RELEASE_WEB + BANNER_IMG, context=create_context(), timeout=CONNECTION_TIMEOUT)
.read())
return img, url
except Exception:
return None, None
Expand Down

0 comments on commit efcc863

Please sign in to comment.