From 7dfed6af6c012589c4d79ae9db697ca2f095e339 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Sun, 17 Nov 2024 21:27:50 -0600 Subject: [PATCH] Change API to rof.tools mirrors --- app/release_checker.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/release_checker.py b/app/release_checker.py index 032a26c..d5c897f 100644 --- a/app/release_checker.py +++ b/app/release_checker.py @@ -11,6 +11,7 @@ from app.utils import get_app_data_folder, keep_latest_versions CACHE_FILE = get_app_data_folder() + '/cache.json' CACHE_DURATION = timedelta(minutes=30) +LATEST_RELEASE_ENDPOINT = "https://git.rof.tools/api/v1/repos/mirrors/btclock_v3/tags" class ReleaseChecker: '''Release Checker for firmware updates''' @@ -34,7 +35,7 @@ class ReleaseChecker: def fetch_latest_release(self): '''Fetch latest firmware release from GitHub''' - repo = "btclock/btclock_v3" + repo = "mirrors/btclock_v3" cache = self.load_cache() now = datetime.now() @@ -42,7 +43,8 @@ class ReleaseChecker: if 'latest_release' in cache and (now - datetime.fromisoformat(cache['latest_release']['timestamp'])) < CACHE_DURATION: latest_release = cache['latest_release']['data'] else: - url = f"https://api.github.com/repos/{repo}/releases/latest" +# url = f"https://api.github.com/repos/{repo}/releases/latest" + url = f"https://git.rof.tools/api/v1/repos/{repo}/releases/latest" try: response = requests.get(url) response.raise_for_status() @@ -72,8 +74,9 @@ class ReleaseChecker: for asset_url in asset_urls: self.download_file(asset_url, release_name) - ref_url = f"https://api.github.com/repos/{ - repo}/git/ref/tags/{release_name}" + ref_url = f"https://git.rof.tools/api/v1/repos/{repo}/tags/{release_name}" + #ref_url = f"https://api.github.com/repos/{ +# repo}/git/ref/tags/{release_name}" if ref_url in cache and (now - datetime.fromisoformat(cache[ref_url]['timestamp'])) < CACHE_DURATION: commit_hash = cache[ref_url]['data'] @@ -81,15 +84,8 @@ class ReleaseChecker: response = requests.get(ref_url) response.raise_for_status() ref_info = response.json() - if ref_info["object"]["type"] == "commit": - commit_hash = ref_info["object"]["sha"] - else: - tag_url = f"https://api.github.com/repos/{ - repo}/git/tags/{ref_info['object']['sha']}" - response = requests.get(tag_url) - response.raise_for_status() - tag_info = response.json() - commit_hash = tag_info["object"]["sha"] + commit_hash = ref_info["commit"]["sha"] + cache[ref_url] = { 'data': commit_hash, 'timestamp': now.isoformat()