From 2cc0fb8c8daac0af907cd218fa28f536110cbafc Mon Sep 17 00:00:00 2001 From: dsc Date: Sun, 25 Apr 2021 21:29:33 +0200 Subject: [PATCH] Introduce limit/offset args for api call --- suchwow/routes/api.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/suchwow/routes/api.py b/suchwow/routes/api.py index 4139b0c..ff0f571 100644 --- a/suchwow/routes/api.py +++ b/suchwow/routes/api.py @@ -1,4 +1,4 @@ -from flask import jsonify, Blueprint, url_for +from flask import jsonify, Blueprint, url_for, request, abort from suchwow.models import Post from suchwow import wownero @@ -7,8 +7,15 @@ bp = Blueprint("api", "api") @bp.route("/api/list") def api_list(): + limit = request.args.get('limit', 30) + offset = request.args.get('offset', 0) + if not isinstance(limit, int) or not isinstance(offset, int): + abort(500, "Bleep bleep") + if limit > 30: + limit = 30 + all_posts = [] - posts = Post.select().where(Post.approved==True) + posts = Post.select().where(Post.approved==True).order_by(Post.timestamp.desc()).limit(limit).offset(offset) for post in posts: wallet = wownero.Wallet() if wallet.connected: