dev@locazia: content list
This commit is contained in:
parent
a328f9227a
commit
ecd8c48352
|
|
@ -4,15 +4,42 @@ from aiogram import types, Router, F
|
||||||
from app.core._config import WEB_APP_URLS
|
from app.core._config import WEB_APP_URLS
|
||||||
from app.core._keyboards import get_inline_keyboard
|
from app.core._keyboards import get_inline_keyboard
|
||||||
from app.core._utils.tg_process_template import tg_process_template
|
from app.core._utils.tg_process_template import tg_process_template
|
||||||
|
from app.core.models.node_storage import StoredContent
|
||||||
|
import json
|
||||||
|
|
||||||
router = Router()
|
router = Router()
|
||||||
|
|
||||||
|
|
||||||
|
def chunks(lst, n):
|
||||||
|
"""Yield successive n-sized chunks from lst."""
|
||||||
|
for i in range(0, len(lst), n):
|
||||||
|
yield lst[i:i + n]
|
||||||
|
|
||||||
|
|
||||||
async def t_callback_owned_content(query: types.CallbackQuery, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
async def t_callback_owned_content(query: types.CallbackQuery, memory=None, user=None, db_session=None, chat_wrap=None, **extra):
|
||||||
message_text = user.translated("ownedContent_menu")
|
message_text = user.translated("ownedContent_menu")
|
||||||
|
content_list = []
|
||||||
|
for content in db_session.query(StoredContent).filter_by(
|
||||||
|
owner_address=user.wallet_address(db_session),
|
||||||
|
).all():
|
||||||
|
try:
|
||||||
|
metadata_content = StoredContent.from_cid(db_session, content.json_format()['metadata_cid'])
|
||||||
|
with open(metadata_content.file_path, 'r') as f:
|
||||||
|
metadata_content_json = json.loads(f.read())
|
||||||
|
except:
|
||||||
|
continue
|
||||||
|
|
||||||
|
content_list.append([
|
||||||
|
{
|
||||||
|
'text': metadata_content_json['title'],
|
||||||
|
'callback_data': f'NC_{content.cid.content_hash.hex()}'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
return await tg_process_template(
|
return await tg_process_template(
|
||||||
chat_wrap, message_text,
|
chat_wrap, message_text,
|
||||||
keyboard=get_inline_keyboard([
|
keyboard=get_inline_keyboard([
|
||||||
|
*content_list,
|
||||||
[{
|
[{
|
||||||
'text': user.translated('webApp_uploadContent_button'),
|
'text': user.translated('webApp_uploadContent_button'),
|
||||||
'web_app': types.WebAppInfo(
|
'web_app': types.WebAppInfo(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue