This commit is contained in:
pika 2025-03-30 23:42:24 +02:00
parent 3b2f1db4ce
commit 5c16964b76
47 changed files with 2080 additions and 1053 deletions

96
app/routes/static.py Normal file
View file

@ -0,0 +1,96 @@
from flask import Blueprint, send_from_directory, current_app
import os
bp = Blueprint("static_assets", __name__)
@bp.route("/static/libs/tabler-icons/tabler-icons.min.css")
def tabler_icons():
"""Serve tabler-icons CSS from node_modules or download if missing"""
icons_path = os.path.join(current_app.static_folder, "libs", "tabler-icons")
# Create directory if it doesn't exist
if not os.path.exists(icons_path):
os.makedirs(icons_path)
css_file = os.path.join(icons_path, "tabler-icons.min.css")
# If file doesn't exist, download from CDN
if not os.path.exists(css_file):
import requests
try:
cdn_url = "https://cdn.jsdelivr.net/npm/@tabler/icons@latest/iconfont/tabler-icons.min.css"
response = requests.get(cdn_url)
if response.status_code == 200:
with open(css_file, "wb") as f:
f.write(response.content)
print(f"Downloaded tabler-icons.min.css from CDN")
else:
print(f"Failed to download tabler-icons CSS: {response.status_code}")
except Exception as e:
print(f"Error downloading tabler-icons CSS: {e}")
return send_from_directory(icons_path, "tabler-icons.min.css")
@bp.route("/static/css/tabler.min.css")
def tabler_css():
"""Serve tabler CSS from static folder or download if missing"""
css_path = os.path.join(current_app.static_folder, "css")
# Create directory if it doesn't exist
if not os.path.exists(css_path):
os.makedirs(css_path)
css_file = os.path.join(css_path, "tabler.min.css")
# If file doesn't exist, download from CDN
if not os.path.exists(css_file):
import requests
try:
cdn_url = "https://cdn.jsdelivr.net/npm/@tabler/core@latest/dist/css/tabler.min.css"
response = requests.get(cdn_url)
if response.status_code == 200:
with open(css_file, "wb") as f:
f.write(response.content)
print(f"Downloaded tabler.min.css from CDN")
else:
print(f"Failed to download tabler CSS: {response.status_code}")
except Exception as e:
print(f"Error downloading tabler CSS: {e}")
return send_from_directory(css_path, "tabler.min.css")
@bp.route("/static/img/favicon.png")
def favicon():
"""Serve favicon from static folder or create a default one if missing"""
img_path = os.path.join(current_app.static_folder, "img")
# Create directory if it doesn't exist
if not os.path.exists(img_path):
os.makedirs(img_path)
favicon_file = os.path.join(img_path, "favicon.png")
# If file doesn't exist, create a simple one
if not os.path.exists(favicon_file):
# Try to download a default favicon
import requests
try:
# Using a simple placeholder favicon
cdn_url = "https://www.google.com/favicon.ico"
response = requests.get(cdn_url)
if response.status_code == 200:
with open(favicon_file, "wb") as f:
f.write(response.content)
print(f"Created default favicon.png")
else:
print(f"Failed to download favicon: {response.status_code}")
except Exception as e:
print(f"Error creating favicon: {e}")
return send_from_directory(img_path, "favicon.png")