diff --git a/app/bot/routers/content.py b/app/bot/routers/content.py index b5d1dd3..5d0ca80 100644 --- a/app/bot/routers/content.py +++ b/app/bot/routers/content.py @@ -1,4 +1,4 @@ - +import base58 from aiogram import types, Router, F from app.core._config import WEB_APP_URLS @@ -54,5 +54,16 @@ async def t_callback_owned_content(query: types.CallbackQuery, memory=None, user ) -router.callback_query.register(t_callback_owned_content, F.data == 'ownedContent') +async def t_callback_node_content(query: types.CallbackQuery, memory=None, user=None, db_session=None, chat_wrap=None, **extra): + content_hash = query.data.split('_')[1] + return await chat_wrap.send_player( + db_session.query(StoredContent).filter_by( + hash=base58.b58encode(bytes.fromhex(content_hash)).decode() + ).first(), + message_id=query.message.message_id + ) + + +router.callback_query.register(t_callback_owned_content, F.data == 'ownedContent') +router.callback_query.register(t_callback_node_content, F.data.startswith('NC_')) diff --git a/app/core/models/_telegram/templates/player.py b/app/core/models/_telegram/templates/player.py index 2777955..2359d81 100644 --- a/app/core/models/_telegram/templates/player.py +++ b/app/core/models/_telegram/templates/player.py @@ -8,18 +8,20 @@ from app.core._keyboards import get_inline_keyboard class PlayerTemplates: async def send_content(self, content: StoredContent, extra_buttons=None, message_id=None): - assert content.type.startswith('onchain/content'), "Invalid nodeStorage content type" - inline_keyboard_array = [] - cd_log = f"Content (SHA256: {content.hash}), Encrypted: {content.encrypted}, TelegramCID: {content.telegram_cid}. " - if not content.encrypted: - local_content = content - else: - local_content = content.decrypted_content - # TODO: add check decrypted_content by .format_json()['content_cid'] - if local_content: - cd_log += f"Decrypted: {local_content.hash}. " + local_content = None + if content: + assert content.type.startswith('onchain/content'), "Invalid nodeStorage content type" + inline_keyboard_array = [] + cd_log = f"Content (SHA256: {content.hash}), Encrypted: {content.encrypted}, TelegramCID: {content.telegram_cid}. " + if not content.encrypted: + local_content = content else: - cd_log += "Can't decrypt content. " + local_content = content.decrypted_content + # TODO: add check decrypted_content by .format_json()['content_cid'] + if local_content: + cd_log += f"Decrypted: {local_content.hash}. " + else: + cd_log += "Can't decrypt content. " if local_content: content_meta = content.json_format()