From: Roland Häder Date: Sat, 24 Jun 2023 12:10:09 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=67401033b9698a7b87421e689bdc160182449eeb;p=fba.git Continued: - maximum API limit (500) now as a configuration key --- diff --git a/api.py b/api.py index 5ba8937..7d0dd52 100644 --- a/api.py +++ b/api.py @@ -56,7 +56,7 @@ def api_info(): @router.get(config.get("base_url") + "/api/scoreboard.json", response_class=JSONResponse) def api_scoreboard(mode: str, amount: int): - if amount > 500: + if amount > config.get("api_limit"): raise HTTPException(status_code=400, detail="Too many results") if mode == "blocked": @@ -98,7 +98,7 @@ def api_scoreboard(mode: str, amount: int): def api_index(request: Request, mode: str, value: str, amount: int): if mode is None or value is None or amount is None: raise HTTPException(status_code=500, detail="No filter specified") - elif amount > 500: + elif amount > config.get("api_limit"): raise HTTPException(status_code=500, detail=f"amount={amount} is to big") domain = whildchar = punycode = reason = None @@ -261,14 +261,14 @@ def index(request: Request): }) @router.get(config.get("base_url") + "/top") -def top(request: Request, mode: str, value: str, amount: int = 500): +def top(request: Request, mode: str, value: str, amount: int = config.get("api_limit")): response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/info.json") if not response.ok: raise HTTPException(status_code=response.status_code, detail=response.text) elif mode == "" or value == "" or amount == 0: raise HTTPException(status_code=500, detail="Parameter mode, value and amount must always be set") - elif amount > 500: + elif amount > config.get("api_limit"): raise HTTPException(status_code=500, detail=f"amount='{amount}' is to big") info = response.json() diff --git a/config.defaults.json b/config.defaults.json index e32a39d..5998798 100644 --- a/config.defaults.json +++ b/config.defaults.json @@ -20,5 +20,6 @@ "misskey_limit" : 100, "error_log_cleanup" : 604800, "write_error_log" : "true", - "rss_limit" : 50 + "rss_limit" : 50, + "api_limit" : 500 }