Skip to content

Commit

Permalink
[API] Fix getVersion discrepency causing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
HotaruBlaze committed May 10, 2024
1 parent e5109a6 commit 4a14b10
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions client/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@
import pickle


def getVersionRegex(html: str):
try:
# Attempt to determine the appropriate regex pattern with prefix
version_with_prefix = re.compile(r'Version\s*\s*(\d+\.\d+\.\d+)').search(html)
if version_with_prefix:
return version_with_prefix
except Exception as e:
print(f"Failed to determine regex pattern with prefix: {e}")

try:
# Attempt to determine an alternative regex pattern with prefix
version_without_space = re.compile(r'Version\s*(\d+\.\d+\.\d+)').search(html)
if version_without_space:
return version_without_space
except Exception as e:
print(f"Failed to determine alternative regex pattern with prefix: {e}")

try:
# Attempt to determine an alternative regex pattern without prefix
version_no_prefix = re.compile(r'(\d+\.\d+\.\d+)').search(html)
if version_no_prefix:
return version_no_prefix
except Exception as e:
print(f"Failed to determine regex pattern without prefix: {e}")
return None


def getAppPath():
# Check for macOS platform and NSO-RPC freeze status
if sys.platform.startswith('darwin') and hasattr(sys, 'frozen') and sys.frozen == 'macosx_app':
Expand Down Expand Up @@ -70,10 +97,10 @@ def getVersion():
else:
log('Failed to get Apple\'s store page after multiple retries.')
if r:
searchPattern = re.compile(r'Version\s*(\d\.\d\.\d)+')
version = searchPattern.search(r.text)
version = getVersionRegex(r.text)
if version:
return version.group(1)
app_version = version.group(1)
return app_version
return ''


Expand All @@ -97,11 +124,11 @@ def getVersion():

class API():
def __init__(self, session_token, user_lang, targetID, version):
pattern = re.compile(r'(\d.\d.\d)')
if not version or not re.search(pattern, version):
version_match = getVersionRegex(version)
if not version_match:
raise Exception('missing app version')
global nsoAppVersion
nsoAppVersion = version
nsoAppVersion = version_match.group(1)
self.headers = {
'X-ProductVersion': nsoAppVersion,
'X-Platform': 'iOS',
Expand Down Expand Up @@ -287,7 +314,8 @@ def __init__(self, userInfo, userLang, accessToken, guid):
if 'error' in self.imink or self.imink.get('error') is not None:
iminkApiError = (
'Unable to authenticate with imink. \n\n'
'The F Calculation API may be experiencing issues. \n'
'The F Calculation API may be experiencing issues or this build of NSO-RPC is outdated \n'
'Please try the most upto date build of NSO-RPC before submitting an issue. \n'
'Please check the website for more details: \n'
'https://status.imink.app/ \n'
)
Expand Down

0 comments on commit 4a14b10

Please sign in to comment.