Files
putzliga/app/routes/main.py
2026-04-13 08:32:28 +02:00

46 lines
1.2 KiB
Python

from __future__ import annotations
from functools import lru_cache
from pathlib import Path
from flask import Blueprint, current_app, redirect, send_from_directory, url_for
from flask_login import current_user
bp = Blueprint("main", __name__)
@bp.route("/")
def index():
if current_user.is_authenticated:
return redirect(url_for("tasks.my_tasks"))
return redirect(url_for("auth.login"))
@bp.route("/healthz")
def healthz():
return {"status": "ok"}, 200
@bp.route("/manifest.json")
def manifest():
return send_from_directory(current_app.static_folder, "manifest.json", mimetype="application/manifest+json")
@bp.route("/service-worker.js")
def service_worker():
response = send_from_directory(current_app.static_folder, "service-worker.js", mimetype="application/javascript")
response.headers["Service-Worker-Allowed"] = "/"
return response
@bp.route("/uploads/<path:filename>")
def uploads(filename: str):
return send_from_directory(current_app.config["UPLOAD_FOLDER"], filename)
@lru_cache(maxsize=64)
def load_icon_svg(name: str, static_folder: str) -> str:
path = Path(static_folder) / "icons" / f"{name}.svg"
return path.read_text(encoding="utf-8") if path.exists() else ""