Compare commits

..

No commits in common. "9e63cbc2f09798c6001c4b83b5825b6b46dbab5f" and "b81d0ae81c1f8c4d86124cb4679250bc21f7df96" have entirely different histories.

4 changed files with 9 additions and 18 deletions

View File

@ -1,5 +1,5 @@
[tool.bumpversion] [tool.bumpversion]
current_version = "1.3.35" current_version = "1.3.34"
commit = true commit = true
tag = true tag = true
tag_name = "{new_version}" tag_name = "{new_version}"

View File

@ -1 +1 @@
1.3.35 1.3.34

23
app.py
View File

@ -30,10 +30,7 @@ if os.environ.get("FLASK_ENV") == "production":
else: else:
app.config.from_object(DevelopmentConfig) app.config.from_object(DevelopmentConfig)
cache = Cache(app, config={ cache = Cache(app, config={"CACHE_TYPE": "SimpleCache"})
"CACHE_TYPE": "redis",
"CACHE_REDIS_URL": app.config.get("REDIS_URL", "redis://localhost:6379/0")
})
if app.config.get("OCR_ENABLED") and OCR_AVAILABLE: if app.config.get("OCR_ENABLED") and OCR_AVAILABLE:
ocr = PaddleOCR(use_angle_cls=True, lang='en') ocr = PaddleOCR(use_angle_cls=True, lang='en')
@ -63,12 +60,6 @@ def inject_version() -> Dict[str, str]:
"""Injects the version into all templates.""" """Injects the version into all templates."""
return dict(version=get_version(), config=app.config, session=session) return dict(version=get_version(), config=app.config, session=session)
def make_cache_key(*args, **kwargs):
"""Generate a cache key based on the user's session and request path."""
username = session.get('username', 'anonymous')
path = request.path
return f"view/{username}/{path}"
@app.before_request @app.before_request
def make_session_permanent() -> None: def make_session_permanent() -> None:
"""Makes the user session permanent.""" """Makes the user session permanent."""
@ -149,7 +140,7 @@ def send_test_notification_proxy():
return jsonify({"error": str(e)}), 502 return jsonify({"error": str(e)}), 502
@app.route("/home") @app.route("/home")
@cache.cached(timeout=60, key_prefix=make_cache_key) @cache.cached(timeout=60)
def home() -> str: def home() -> str:
"""Renders the home page with account statistics.""" """Renders the home page with account statistics."""
if session.get("logged_in"): if session.get("logged_in"):
@ -195,7 +186,7 @@ def login() -> Union[Response, str]:
return render_template("index.html", error=error) return render_template("index.html", error=error)
@app.route("/urls", methods=["GET"]) @app.route("/urls", methods=["GET"])
@cache.cached(timeout=300, key_prefix=make_cache_key) @cache.cached(timeout=300)
def urls() -> Union[Response, str]: def urls() -> Union[Response, str]:
"""Renders the URLs page.""" """Renders the URLs page."""
if not session.get("logged_in"): if not session.get("logged_in"):
@ -206,7 +197,7 @@ def urls() -> Union[Response, str]:
) )
@app.route("/accounts", methods=["GET"]) @app.route("/accounts", methods=["GET"])
@cache.cached(timeout=60, key_prefix=make_cache_key) @cache.cached(timeout=60)
def user_accounts() -> Union[Response, str]: def user_accounts() -> Union[Response, str]:
"""Renders the user accounts page.""" """Renders the user accounts page."""
if not session.get("logged_in"): if not session.get("logged_in"):
@ -243,7 +234,7 @@ def add_account() -> Union[Response, str]:
if add_user_account( if add_user_account(
base_url, session["auth_credentials"], username, password, stream base_url, session["auth_credentials"], username, password, stream
): ):
cache.delete_memoized(user_accounts, key_prefix=make_cache_key) cache.delete_memoized(user_accounts)
return redirect(url_for("user_accounts")) return redirect(url_for("user_accounts"))
return render_template( return render_template(
@ -260,7 +251,7 @@ def delete_account() -> Response:
username = request.form.get("username") username = request.form.get("username")
base_url = app.config["BASE_URL"] base_url = app.config["BASE_URL"]
delete_user_account(base_url, session["auth_credentials"], stream, username) delete_user_account(base_url, session["auth_credentials"], stream, username)
cache.delete_memoized(user_accounts, key_prefix=make_cache_key) cache.delete_memoized(user_accounts)
return redirect(url_for("user_accounts")) return redirect(url_for("user_accounts"))
@app.route("/validateAccount", methods=["POST"]) @app.route("/validateAccount", methods=["POST"])
@ -280,7 +271,7 @@ def validate_account() -> Tuple[Response, int]:
response.raise_for_status() response.raise_for_status()
response_data = response.json() response_data = response.json()
if response_data.get("message") == "Account is valid and updated": if response_data.get("message") == "Account is valid and updated":
cache.delete_memoized(user_accounts, key_prefix=make_cache_key) cache.delete_memoized(user_accounts)
return jsonify(response_data), response.status_code return jsonify(response_data), response.status_code
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 500 return jsonify({"error": str(e)}), 500

Binary file not shown.