dev@locazia: add content list
This commit is contained in:
1 parent
5d486544ca
commit
9e60503262
3 files changed
+40
No files matched your search
@@ -18,6 +18,7 @@ from app.api.routes.node_storage import s_api_v1_storage_post, s_api_v1_storage_
|
||||
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
|
||||
|
||||
app.add_route(s_index, "/", methods=["GET", "OPTIONS"])
|
||||
app.add_route(s_favicon, "/favicon.ico", methods=["GET", "OPTIONS"])
|
||||
@@ -39,6 +40,8 @@ app.add_route(s_api_v1_account_get, "/api/v1/account", methods=["GET", "OPTIONS"
|
||||
app.add_route(s_api_v1_blockchain_send_new_content_message, "/api/v1/blockchain.sendNewContentMessage", methods=["POST", "OPTIONS"])
|
||||
app.add_route(s_api_v1_blockchain_send_purchase_content_message, "/api/v1/blockchain.sendPurchaseContentMessage", methods=["POST", "OPTIONS"])
|
||||
|
||||
app.add_route(s_api_v1_content_list, "/api/v1/content.list", methods=["GET", "OPTIONS"])
|
||||
|
||||
|
||||
@app.exception(BaseException)
|
||||
async def s_handle_exception(request, exception):
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
from sanic import response
|
||||
from datetime import datetime, timedelta
|
||||
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"
|
||||
|
||||
content_list = request.ctx.db_session.query(StoredContent).filter(
|
||||
StoredContent.type == "local/bin"
|
||||
).order_by(StoredContent.created.desc()).offset(offset).limit(limit).all()
|
||||
result = {}
|
||||
for content in content_list:
|
||||
content_json = content.json_format()
|
||||
result[content_json["cid"]] = content_json
|
||||
|
||||
return response.json(result)
|
||||
Reference in new issue
Block a user