add content friendlyList
This commit is contained in:
parent
5a523f4d66
commit
69b7ab9fdf
|
|
@ -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.account import s_api_v1_account_get
|
||||||
from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \
|
from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \
|
||||||
s_api_v1_blockchain_send_purchase_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
|
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_list, "/api/v1/content.list", methods=["GET", "OPTIONS"])
|
||||||
app.add_route(s_api_v1_content_view, "/api/v1/content.view/<content_address>", methods=["GET", "OPTIONS"])
|
app.add_route(s_api_v1_content_view, "/api/v1/content.view/<content_address>", methods=["GET", "OPTIONS"])
|
||||||
|
app.add_route(s_api_v1_content_friendly_list, "/api/v1/content.friendlyList", methods=["GET", "OPTIONS"])
|
||||||
|
|
||||||
|
|
||||||
@app.exception(BaseException)
|
@app.exception(BaseException)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from app.core.models.node_storage import StoredContent
|
||||||
from app.core.models.keys import KnownKey
|
from app.core.models.keys import KnownKey
|
||||||
from app.core.models import StarsInvoice
|
from app.core.models import StarsInvoice
|
||||||
from app.core.models.content.user_content import UserContent
|
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 json
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
@ -143,3 +143,56 @@ async def s_api_v1_content_view(request, content_address: str):
|
||||||
'display_options': display_options
|
'display_options': display_options
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
async def s_api_v1_content_friendly_list(request):
|
||||||
|
# return html table with content list. bootstrap is used
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
result = """
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>CID</th>
|
||||||
|
<th>Title</th>
|
||||||
|
<th>Onchain</th>
|
||||||
|
<th>Preview link</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
"""
|
||||||
|
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"""
|
||||||
|
<tr>
|
||||||
|
<td>{content.cid}</td>
|
||||||
|
<td>{metadata['title']}</td>
|
||||||
|
<td>{content.meta.get('item_address')}</td>
|
||||||
|
<td><a href="{preview_link}">Preview</a></td>
|
||||||
|
</tr>
|
||||||
|
"""
|
||||||
|
result += """
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
return response.html(result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue