Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout to version and banner checks #550

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading