uploader-bot/app/api/routes/content.py

27 lines
950 B
Python

from sanic import response
from app.core.logger import make_log
from app.core.models.node_storage import StoredContent
async def s_api_v1_content_list(request):
offset = int(request.args.get('offset', 0))
limit = int(request.args.get('limit', 100))
assert 0 <= offset, "Invalid offset"
assert 0 < limit <= 1000, "Invalid limit"
store = request.args.get('store', 'local')
assert store in ('local', 'onchain'), "Invalid store"
content_list = request.ctx.db_session.query(StoredContent).filter(
StoredContent.type.like(store + '%'),
StoredContent.disabled == False
).order_by(StoredContent.created.desc()).offset(offset).limit(limit)
make_log("Content", f"Listed {content_list.count()} contents", level='info')
result = {}
for content in content_list.all():
content_json = content.json_format()
result[content_json["cid"]] = content_json
return response.json(result)