add content friendlyList
This commit is contained in:
1 parent
5a523f4d66
commit
69b7ab9fdf
2 files changed
+56
-2
No files matched your search
@@ -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 = """
|
||||
<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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user