From 10044c6d127f883ef14487827c64318d3660bafd Mon Sep 17 00:00:00 2001 From: Guillermo Rodriguez Date: Thu, 5 Oct 2023 15:58:00 -0300 Subject: [PATCH] Add new ipfs links to telegram bot --- skynet/frontend/telegram/__init__.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/skynet/frontend/telegram/__init__.py b/skynet/frontend/telegram/__init__.py index 57e4a02..c3af47a 100644 --- a/skynet/frontend/telegram/__init__.py +++ b/skynet/frontend/telegram/__init__.py @@ -237,9 +237,24 @@ class SkynetTelegramFrontend: user, params, tx_hash, worker, reward) # attempt to get the image and send it - ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}/image.png' - resp = await get_ipfs_file(ipfs_link) + results = {} + ipfs_link = f'https://ipfs.{DEFAULT_DOMAIN}/ipfs/{ipfs_hash}' + ipfs_link_legacy = ipfs_link + '/image.png' + async def get_and_set_results(link: str): + results[link] = await get_ipfs_file(link) + + tasks = [ + get_and_set_results(ipfs_link), + get_and_set_results(ipfs_link_legacy) + ] + await asyncio.gather(*tasks) + + resp = results[ipfs_link_legacy] + if not resp or resp.status_code != 200: + logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link_legacy}!') + + resp = results[ipfs_link] if not resp or resp.status_code != 200: logging.error(f'couldn\'t get ipfs hosted image at {ipfs_link}!') await self.update_status_message(