diff --git a/app/api/__init__.py b/app/api/__init__.py index 9b70f64..d46ed6c 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -21,7 +21,7 @@ from app.api.routes.progressive_storage import s_api_v1_5_storage_get, s_api_v1_ from app.api.routes.account import s_api_v1_account_get from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \ s_api_v1_blockchain_send_purchase_content_message -from app.api.routes.content import s_api_v1_content_list, s_api_v1_content_view +from app.api.routes.content import s_api_v1_content_list, s_api_v1_content_view, s_api_v1_content_friendly_list from app.api.routes.tonconnect import s_api_v1_tonconnect_new, s_api_v1_tonconnect_logout @@ -54,6 +54,7 @@ app.add_route(s_api_v1_blockchain_send_purchase_content_message, "/api/v1/blockc app.add_route(s_api_v1_content_list, "/api/v1/content.list", methods=["GET", "OPTIONS"]) app.add_route(s_api_v1_content_view, "/api/v1/content.view/", methods=["GET", "OPTIONS"]) +app.add_route(s_api_v1_content_friendly_list, "/api/v1/content.friendlyList", methods=["GET", "OPTIONS"]) @app.exception(BaseException) diff --git a/app/api/routes/content.py b/app/api/routes/content.py index 2dc33a5..257579f 100644 --- a/app/api/routes/content.py +++ b/app/api/routes/content.py @@ -7,7 +7,7 @@ from app.core.models.node_storage import StoredContent from app.core.models.keys import KnownKey from app.core.models import StarsInvoice from app.core.models.content.user_content import UserContent -from app.core._config import CLIENT_TELEGRAM_API_KEY +from app.core._config import CLIENT_TELEGRAM_API_KEY, PROJECT_HOST import json import uuid @@ -143,3 +143,56 @@ async def s_api_v1_content_view(request, content_address: str): 'display_options': display_options }) + +async def s_api_v1_content_friendly_list(request): + # return html table with content list. bootstrap is used + + + + result = """ + + + + + + + + + + + + + + + +""" + for content in request.ctx.db_session.query(StoredContent).filter( + StoredContent.type == 'onchain/content' + ).all(): + metadata_content = StoredContent.from_cid(request.ctx.db_session, content.meta.get('metadata_cid')) + with open(metadata_content.filepath, 'r') as f: + metadata = json.loads(f.read()) + + preview_link = 'not ready' + if content.meta.get('converted_content'): + preview_link = f"{PROJECT_HOST}/api/v1.5/storage/{content.meta['converted_content']['low_preview']}" + + result += f""" + + + + + + + """ + result += """ +
CIDTitleOnchainPreview link
{content.cid}{metadata['title']}{content.meta.get('item_address')}Preview
+ + + """ + return response.html(result) + + + + +