Skip to content

Commit

Permalink
Add timeout to version and banner checks (#550)
Browse files Browse the repository at this point in the history
* Add timeout to version and banner checks

* Format
  • Loading branch information
Frostbyte0x70 authored Oct 31, 2024
1 parent 382e530 commit 10b7fa7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 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,25 @@ 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 10b7fa7

Please sign in to comment.