From db31fc17de500351d33cefb7f655737501aa0894 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Tue, 29 Nov 2022 19:29:06 -0600 Subject: [PATCH] ratelimits: turn off autocheck so we can init required app context globals --- files/__main__.py | 3 ++- files/routes/allroutes.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index 265a15b56..61cc3fe41 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -56,7 +56,8 @@ limiter = Limiter( key_func=get_CF, default_limits=[DEFAULT_RATELIMIT], application_limits=["10/second;200/minute;5000/hour;10000/day"], - storage_uri=environ.get("REDIS_URL", "redis://localhost") + storage_uri=environ.get("REDIS_URL", "redis://localhost"), + auto_check=False, ) engine = create_engine(app.config['SQLALCHEMY_DATABASE_URL']) diff --git a/files/routes/allroutes.py b/files/routes/allroutes.py index 02ad05bae..7cfd61f9c 100644 --- a/files/routes/allroutes.py +++ b/files/routes/allroutes.py @@ -4,7 +4,7 @@ from files.helpers.const import * from files.helpers.settings import get_setting from files.helpers.cloudflare import CLOUDFLARE_AVAILABLE from files.routes.wrappers import * -from files.__main__ import app +from files.__main__ import app, limiter def session_init(): if not session.get("session_id"): @@ -21,8 +21,7 @@ def before_request(): if not g.agent and request.path != '/kofi': return 'Please use a "User-Agent" header!', 403 - ua = g.agent or '' - ua = ua.lower() + ua = g.agent.lower() if request.host != SITE: return {"error": "Unauthorized host provided"}, 403 @@ -31,7 +30,6 @@ def before_request(): if not get_setting('Bots') and request.headers.get("Authorization"): abort(403) - g.db = db_session() g.webview = '; wv) ' in ua if ' firefox/' in ua: @@ -49,6 +47,8 @@ def before_request(): if not request.full_path: request.full_path = '/' session_init() + limiter.check() + g.db = db_session() @app.after_request