From 673665d03d5ec6221524c1e08f70665de2c981b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 8 May 2026 20:51:05 +0200 Subject: [PATCH] favicons --- pytorrent/__init__.py | 12 +++++++----- pytorrent/routes/main.py | 1 - pytorrent/static/favicon.svg | 9 +++++++++ pytorrent/templates/error.html | 2 ++ pytorrent/templates/index.html | 2 ++ pytorrent/templates/login.html | 2 ++ wsgi.py | 1 - 7 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 pytorrent/static/favicon.svg diff --git a/pytorrent/__init__.py b/pytorrent/__init__.py index 7875d21..9225d8f 100644 --- a/pytorrent/__init__.py +++ b/pytorrent/__init__.py @@ -30,7 +30,6 @@ def _wants_json_response() -> bool: def register_error_pages(app: Flask) -> None: - # Notatka: własne strony błędów zastępują generyczne 404/500 i zachowują JSON dla API. @app.errorhandler(404) def not_found(error): if _wants_json_response(): @@ -92,7 +91,6 @@ def create_app() -> Flask: return url_for("static", filename=filename) def frontend_asset_url(key: str) -> str: - # Notatka: helper przełącza szablony między CDN i lokalnymi plikami bez duplikowania logiki. path = asset_path(key) return path if path.startswith("http") else static_url(path) @@ -108,12 +106,16 @@ def create_app() -> Flask: @app.after_request def cache_headers(response): - response.headers.pop('Content-Disposition', None) - - if request.endpoint == "static": + response.headers.pop("Content-Disposition", None) + + static_file = request.path.startswith("/static/") + tracker_icon = request.path.startswith("/static/tracker_favicons/") + + if static_file and not tracker_icon: response.headers["Cache-Control"] = "public, max-age=31536000, immutable" else: response.headers["Cache-Control"] = "no-store, private" + return response from .routes.main import bp as main_bp diff --git a/pytorrent/routes/main.py b/pytorrent/routes/main.py index 9cd4c4c..3d6432d 100644 --- a/pytorrent/routes/main.py +++ b/pytorrent/routes/main.py @@ -9,7 +9,6 @@ bp = Blueprint("main", __name__) def _asset_url(key: str) -> str: - # Notatka: API docs korzysta z tego samego przełącznika CDN/offline co reszta aplikacji. path = asset_path(key) return path if path.startswith("http") else url_for("static", filename=path) diff --git a/pytorrent/static/favicon.svg b/pytorrent/static/favicon.svg new file mode 100644 index 0000000..5f52965 --- /dev/null +++ b/pytorrent/static/favicon.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/pytorrent/templates/error.html b/pytorrent/templates/error.html index e1e6dd0..16f4f94 100644 --- a/pytorrent/templates/error.html +++ b/pytorrent/templates/error.html @@ -4,6 +4,8 @@ pyTorrent {{ code }} + + diff --git a/pytorrent/templates/index.html b/pytorrent/templates/index.html index 750f5ad..07ba72b 100644 --- a/pytorrent/templates/index.html +++ b/pytorrent/templates/index.html @@ -4,6 +4,8 @@ pyTorrent + + diff --git a/pytorrent/templates/login.html b/pytorrent/templates/login.html index 7f90143..fb13912 100644 --- a/pytorrent/templates/login.html +++ b/pytorrent/templates/login.html @@ -4,6 +4,8 @@ pyTorrent login + + diff --git a/wsgi.py b/wsgi.py index 0e85347..6e0da8e 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,4 +1,3 @@ from pytorrent import create_app -# Note: Gunicorn imports this object; background Socket.IO tasks still start through create_app(). app = create_app()