Solved loading bug

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-07 13:19:49 +02:00
parent cc0fc9b77f
commit 430ea4a120
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
5 changed files with 68 additions and 72 deletions

View File

@ -96,11 +96,8 @@ h3.footer-title {
font-size: 1.3em; font-size: 1.3em;
} }
.card-img-top i { .card-img-top i, .card-img-top object{
font-size: 100px; font-size: 100px;
}
svg {
fill: currentColor; fill: currentColor;
} }

View File

@ -3,7 +3,11 @@
<head> <head>
<title>{{platform.titel}}</title> <title>{{platform.titel}}</title>
<meta charset="utf-8" > <meta charset="utf-8" >
<link rel="icon" type="image/x-icon" href="{{platform.favicon.cache}}"> <link
rel="icon"
type="image/x-icon"
href="{% if platform.favicon.cache %}{{ url_for('static', filename=platform.favicon.cache) }}{% endif %}"
>
<!-- Bootstrap CSS only --> <!-- Bootstrap CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<!-- Bootstrap JavaScript Bundle with Popper --> <!-- Bootstrap JavaScript Bundle with Popper -->
@ -29,7 +33,10 @@
> >
<div class="container"> <div class="container">
<header class="header"> <header class="header">
<img src="{{platform.logo.cache}}" alt="logo"/> <img
src="{{ url_for('static', filename=platform.logo.cache) }}"
alt="logo"
/>
<h1>{{platform.titel}}</h1> <h1>{{platform.titel}}</h1>
<h2>{{platform.subtitel}}</h2> <h2>{{platform.subtitel}}</h2>
</header> </header>

View File

@ -4,14 +4,20 @@
<div class="card-img-top"> <div class="card-img-top">
{% if card.icon.cache %} {% if card.icon.cache %}
{% if card.icon.cache.endswith('.svg') %} {% if card.icon.cache.endswith('.svg') %}
<svg type="image/svg+xml" data="{{ card.icon.cache }}" style="width:100px; height:auto;"> <object
type="image/svg+xml"
data="{{ url_for('static', filename=card.icon.cache) }}"
style="width:100px; height:auto;">
{% if card.icon.class %} {% if card.icon.class %}
<i class="{{ card.icon.class }}"></i> <i class="{{ card.icon.class }}"></i>
{% endif %} {% endif %}
</svg> </object>
{% else %} {% else %}
<img src="{{ card.icon.cache }}" alt="{{ card.title }}" style="width:100px; height:auto;" <img
onerror="this.style.display='none'; var icon=this.nextElementSibling; if(icon) icon.style.display='inline-block';"> src="{{ url_for('static', filename=card.icon.cache) }}"
alt="{{ card.title }}"
style="width:100px; height:auto;"
onerror="this.style.display='none'; this.nextElementSibling?.style.display='inline-block';">
{% if card.icon.class %} {% if card.icon.class %}
<i class="{{ card.icon.class }}" style="display:none;"></i> <i class="{{ card.icon.class }}" style="display:none;"></i>
{% endif %} {% endif %}
@ -24,7 +30,9 @@
<h3 class="card-title">{{ card.title }}</h3> <h3 class="card-title">{{ card.title }}</h3>
<p class="card-text">{{ card.text }}</p> <p class="card-text">{{ card.text }}</p>
{% if card.url %} {% if card.url %}
<a href="{{ card.url }}" class="mt-auto btn btn-light stretched-link {% if card.iframe %}iframe-link{% endif %}"> <a
href="{{ card.url }}"
class="mt-auto btn btn-light stretched-link {% if card.iframe %}iframe-link{% endif %}">
<i class="fa-solid fa-globe"></i> {{ card.link_text }} <i class="fa-solid fa-globe"></i> {{ card.link_text }}
</a> </a>
{% else %} {% else %}

View File

@ -56,7 +56,7 @@
{% if menu_type == "header" %} {% if menu_type == "header" %}
<a class="navbar-brand d-flex align-items-center d-none" id="navbar_logo" href="/"> <a class="navbar-brand d-flex align-items-center d-none" id="navbar_logo" href="/">
<img <img
src="{{ platform.logo.cache }}" src="{{ url_for('static', filename=platform.logo.cache) }}"
alt="{{ platform.titel }}" alt="{{ platform.titel }}"
class="d-inline-block align-text-top" class="d-inline-block align-text-top"
style="height:2rem"> style="height:2rem">

View File

@ -9,53 +9,37 @@ class CacheManager:
self._ensure_cache_dir_exists() self._ensure_cache_dir_exists()
def _ensure_cache_dir_exists(self): def _ensure_cache_dir_exists(self):
"""Ensure the cache directory exists on disk."""
if not os.path.exists(self.cache_dir): if not os.path.exists(self.cache_dir):
os.makedirs(self.cache_dir) os.makedirs(self.cache_dir)
def clear_cache(self): def clear_cache(self):
"""Remove all files from the cache directory."""
if os.path.exists(self.cache_dir): if os.path.exists(self.cache_dir):
for filename in os.listdir(self.cache_dir): for filename in os.listdir(self.cache_dir):
file_path = os.path.join(self.cache_dir, filename) path = os.path.join(self.cache_dir, filename)
if os.path.isfile(file_path): if os.path.isfile(path):
os.remove(file_path) os.remove(path)
def cache_file(self, file_url): def cache_file(self, file_url):
""" # generate a short hash for filename
Download a file from `file_url` and store it in the cache. hash_suffix = hashlib.blake2s(file_url.encode('utf-8'), digest_size=8).hexdigest()
If any HTTP error occurs, return "Undefined" instead of raising. parts = file_url.rstrip("/").split("/")
""" base = parts[-2] if parts[-1] == "download" else parts[-1]
# Compute a short hash suffix for the URL
hash_object = hashlib.blake2s(file_url.encode('utf-8'), digest_size=8)
hash_suffix = hash_object.hexdigest()
# Derive a base filename: drop trailing 'download' if present
url_parts = file_url.rstrip("/").split("/")
base_name = url_parts[-2] if url_parts[-1] == "download" else url_parts[-1]
try: try:
# Attempt to download the file (streaming) resp = requests.get(file_url, stream=True, timeout=5)
response = requests.get(file_url, stream=True) resp.raise_for_status()
response.raise_for_status()
except requests.RequestException: except requests.RequestException:
# On any network/HTTP error, skip caching and return "Undefined" return None
return "Undefined"
# Determine file extension from Content-Type header content_type = resp.headers.get('Content-Type', '')
content_type = response.headers.get('Content-Type', '') ext = mimetypes.guess_extension(content_type.split(";")[0].strip()) or ".png"
extension = mimetypes.guess_extension(content_type.split(";")[0].strip()) filename = f"{base}_{hash_suffix}{ext}"
if extension is None:
extension = '.png' # default extension
# Build final filename and full path
filename = f"{base_name}_{hash_suffix}{extension}"
full_path = os.path.join(self.cache_dir, filename) full_path = os.path.join(self.cache_dir, filename)
# Write the file to cache if not already present
if not os.path.exists(full_path): if not os.path.exists(full_path):
with open(full_path, "wb") as out_file: with open(full_path, "wb") as f:
for chunk in response.iter_content(chunk_size=1024): for chunk in resp.iter_content(1024):
out_file.write(chunk) f.write(chunk)
return full_path # return path relative to /static/
return f"cache/{filename}"