fix messages, save tonPerStar rate
This commit is contained in:
1 parent
bb2180f44b
commit
ddbd004633
7 files changed
+191
-86
No files matched your search
@@ -171,7 +171,7 @@ async def s_api_v1_content_friendly_list(request):
|
||||
with open(metadata_content.filepath, 'r') as f:
|
||||
metadata = json.loads(f.read())
|
||||
|
||||
preview_link = 'not ready'
|
||||
preview_link = None
|
||||
if content.meta.get('converted_content'):
|
||||
preview_link = f"{PROJECT_HOST}/api/v1.5/storage/{content.meta['converted_content']['low_preview']}"
|
||||
|
||||
@@ -180,7 +180,7 @@ async def s_api_v1_content_friendly_list(request):
|
||||
<td>{content.cid.serialize_v2()}</td>
|
||||
<td>{metadata.get('name', "")}</td>
|
||||
<td>{content.meta.get('item_address')}</td>
|
||||
<td><a href="{preview_link}">Preview</a></td>
|
||||
<td>""" + (f'<a href="{preview_link}">Preview</a>' if preview_link else "not ready") + """</td>
|
||||
</tr>
|
||||
"""
|
||||
result += """
|
||||
@@ -189,5 +189,65 @@ async def s_api_v1_content_friendly_list(request):
|
||||
</html>
|
||||
"""
|
||||
return response.html(result)
|
||||
|
||||
|
||||
async def s_api_v1_5_content_list(request):
|
||||
# Validate offset and limit parameters
|
||||
offset = int(request.args.get('offset', 0))
|
||||
limit = int(request.args.get('limit', 100))
|
||||
if offset < 0:
|
||||
return response.json({'error': 'Invalid offset'}, status=400)
|
||||
|
||||
if limit <= 0 or limit > 1000:
|
||||
return response.json({'error': 'Invalid limit'}, status=400)
|
||||
|
||||
# Query onchain contents which are not disabled
|
||||
contents = request.ctx.db_session.query(StoredContent).filter(
|
||||
StoredContent.type == 'onchain/content',
|
||||
StoredContent.disabled == False
|
||||
).order_by(StoredContent.created.desc()).offset(offset).limit(limit).all()
|
||||
|
||||
result = []
|
||||
for content in contents:
|
||||
# Retrieve metadata content using metadata_cid from content.meta
|
||||
metadata_cid = content.meta.get('metadata_cid')
|
||||
if not metadata_cid:
|
||||
continue # Skip if no metadata_cid is found
|
||||
|
||||
metadata_content = StoredContent.from_cid(request.ctx.db_session, metadata_cid)
|
||||
try:
|
||||
with open(metadata_content.filepath, 'r') as f:
|
||||
metadata = json.load(f)
|
||||
except Exception as e:
|
||||
metadata = {}
|
||||
|
||||
media_type = 'audio'
|
||||
|
||||
# Get title from metadata (key 'name')
|
||||
title = metadata.get('name', '')
|
||||
|
||||
# Build preview link if converted_content exists and contains 'low_preview'
|
||||
preview_link = None
|
||||
converted_content = content.meta.get('converted_content')
|
||||
if converted_content:
|
||||
converted_content = request.ctx.db_session.query(StoredContent).filter(
|
||||
StoredContent.hash == converted_content['low_preview']
|
||||
).first()
|
||||
preview_link = converted_content.web_url
|
||||
if converted_content.filename.split('.')[-1] in ('mp4', 'mov'):
|
||||
media_type = 'video'
|
||||
else:
|
||||
preview_link = None
|
||||
|
||||
# Get onchain address from content.meta
|
||||
onchain_address = content.meta.get('item_address', '')
|
||||
|
||||
result.append({
|
||||
'cid': content.cid.serialize_v2(),
|
||||
'onchain_address': onchain_address,
|
||||
'type': media_type,
|
||||
'title': title,
|
||||
'preview_link': preview_link,
|
||||
'created_at': content.created.isoformat() # ISO 8601 format for datetime
|
||||
})
|
||||
|
||||
return response.json(result)
|
||||
Reference in new issue
Block a user