1
0
Fork 0

Merge pull request #50 from Salvoxia/enhancement/serverVersionCheck

Enhancement: Server Version Check
This commit is contained in:
Salvoxia 2024-09-15 12:53:10 +00:00 committed by GitHub
commit e767ee0a4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -291,8 +291,8 @@ def fetchServerVersion() -> dict:
""" """
Fetches the API version from the immich server. Fetches the API version from the immich server.
If the API endpoint does not yet exist, returns the latest version If the API endpoint for getting the server version cannot be reached,
before that API endpoint was introduced: 1.105.1 raises HTTPError
Returns Returns
------- -------
@ -304,17 +304,13 @@ def fetchServerVersion() -> dict:
# This API call was only introduced with version 1.106.1, so it will fail # This API call was only introduced with version 1.106.1, so it will fail
# for older versions. # for older versions.
# Initialize the version with the latest version without this API call # Initialize the version with the latest version without this API call
version = {'major': 1, 'minor': 105, "patch": 1}
r = requests.get(root_url+'server-info/version', **requests_kwargs) r = requests.get(root_url+'server-info/version', **requests_kwargs)
assert r.status_code == 200 or r.status_code == 404
if r.status_code == 200: if r.status_code == 200:
version = r.json() version = r.json()
logging.info("Detected Immich server version %s.%s.%s", version['major'], version['minor'], version['patch']) logging.info("Detected Immich server version %s.%s.%s", version['major'], version['minor'], version['patch'])
# Since the API call did not exist prior to 1.106.1, we assume that 404 means we found an old version.
elif r.status_code == 404:
logging.info("Detected Immich server version %s.%s.%s or older", version['major'], version['minor'], version['patch'])
# Any other errors mean communication error with API # Any other errors mean communication error with API
else: else:
logging.error("Communication with Immich API failed! Make sure the passed API URL is correct!")
r.raise_for_status() r.raise_for_status()
return version return version