diff --git a/CB/Core.py b/CB/Core.py index 47d910c..972cf49 100644 --- a/CB/Core.py +++ b/CB/Core.py @@ -34,6 +34,7 @@ def __init__(self): self.dirIndex = None self.wowiCache = {} self.wagoCache = {} + self.wagoIdCache = None self.tukuiCache = None self.checksumCache = {} @@ -557,7 +558,7 @@ def parse_wagoapp_payload(self, url): payload = payload.json() return f'https://addons.wago.io/addons/{payload["slug"]}' - @retry() + # TODO Improve the check when Wago Addons API will be will be expanded def bulk_check(self, addons): ids_wowi = [] ids_wago = [] @@ -566,22 +567,33 @@ def bulk_check(self, addons): ids_wowi.append(re.findall(r'\d+', addon['URL'])[0].strip()) elif addon['URL'].startswith('https://addons.wago.io/addons/') and \ addon['URL'] not in self.config['IgnoreClientVersion'].keys(): - ids_wago.append(addon['URL'].replace('https://addons.wago.io/addons/', '')) + ids_wago.append({'slug': addon['URL'].replace('https://addons.wago.io/addons/', ''), 'id': ''}) if len(ids_wowi) > 0: payload = requests.get(f'https://api.mmoui.com/v3/game/WOW/filedetails/{",".join(ids_wowi)}.json', headers=HEADERS, timeout=5).json() if 'ERROR' not in payload: for addon in payload: self.wowiCache[str(addon['UID'])] = addon - # TODO Add bulk support - # if len(ids_wago) > 0 and self.config['WAAAPIKey'] != '': - # payload = requests.post(f'https://addons.wago.io/api/external/addons/_recents?game_version=' - # f'{self.clientType}', json={'addons': ids_wago}, headers=HEADERS, - # auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5) - # self.parse_wagoaddons_error(payload.status_code) - # payload = payload.json() - # for addon in payload['addons']: - # self.wagoCache[addon] = payload['addons'][addon] + if len(ids_wago) > 0 and self.config['WAAAPIKey'] != '': + if not self.wagoIdCache: + self.wagoIdCache = requests.get(f'https://addons.wago.io/api/data/slugs?game_version={self.clientType}', + headers=HEADERS, timeout=5) + self.parse_wagoaddons_error(self.wagoIdCache.status_code) + self.wagoIdCache = self.wagoIdCache.json() + for addon in ids_wago: + if addon['slug'] in self.wagoIdCache['addons']: + addon['id'] = self.wagoIdCache['addons'][addon['slug']]['id'] + payload = requests.post(f'https://addons.wago.io/api/external/addons/_recents?game_version=' + f'{self.clientType}', + json={'addons': [addon["id"] for addon in ids_wago if addon["id"] != ""]}, + headers=HEADERS, auth=APIAuth('Bearer', self.config['WAAAPIKey']), timeout=5) + self.parse_wagoaddons_error(payload.status_code) + payload = payload.json() + for addonid in payload['addons']: + for addon in ids_wago: + if addon['id'] == addonid: + self.wagoCache[addon['slug']] = payload['addons'][addonid] + break # TODO WotLK Cleanup @retry(custom_error='Failed to parse Tukui API data') diff --git a/CB/WagoAddons.py b/CB/WagoAddons.py index f73b41a..f4f791e 100644 --- a/CB/WagoAddons.py +++ b/CB/WagoAddons.py @@ -15,7 +15,6 @@ def __init__(self, url, checkcache, clienttype, allowdev, apikey): project = url.replace('https://addons.wago.io/addons/', '') self.apiKey = apikey self.clientType = clienttype - # TODO Add bulk support if project in checkcache: self.payload = checkcache[project] self.payload['display_name'] = self.payload['name'] @@ -83,13 +82,10 @@ def get_current_version(self): raise RuntimeError(f'{self.name}.\nFailed to find release for your client version.') release = self.payload['recent_release'][max(release, key=release.get)] - self.downloadUrl = release['download_link'] + self.downloadUrl = release['download_link'] if 'download_link' in release else release['link'] + self.uiVersion = release['patch'] if 'patch' in release else release[f'supported_{self.clientType}_patch'] self.changelogUrl = f'{self.payload["website_url"]}/versions' self.currentVersion = release['label'] - if 'patch' in release: - self.uiVersion = release['patch'] - else: - self.uiVersion = release[f'supported_{self.clientType}_patch'] @retry() def get_addon(self):