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;
}
.card-img-top i {
.card-img-top i, .card-img-top object{
font-size: 100px;
}
svg {
fill: currentColor;
}

View File

@ -3,7 +3,11 @@
<head>
<title>{{platform.titel}}</title>
<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 -->
<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 -->
@ -29,7 +33,10 @@
>
<div class="container">
<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>
<h2>{{platform.subtitel}}</h2>
</header>

View File

@ -1,35 +1,43 @@
<div class="card-column {{ lg_class }} {{ md_class }} col-12">
<div class="card h-100 d-flex flex-column">
<div class="card-body d-flex flex-column">
<div class="card-img-top">
{% if card.icon.cache %}
{% if card.icon.cache.endswith('.svg') %}
<svg type="image/svg+xml" data="{{ card.icon.cache }}" style="width:100px; height:auto;">
{% if card.icon.class %}
<i class="{{ card.icon.class }}"></i>
{% endif %}
</svg>
{% else %}
<img src="{{ card.icon.cache }}" alt="{{ card.title }}" style="width:100px; height:auto;"
onerror="this.style.display='none'; var icon=this.nextElementSibling; if(icon) icon.style.display='inline-block';">
{% if card.icon.class %}
<i class="{{ card.icon.class }}" style="display:none;"></i>
{% endif %}
{% endif %}
{% elif card.icon.class %}
<i class="{{ card.icon.class }}"></i>
{% endif %}
</div>
<hr />
<h3 class="card-title">{{ card.title }}</h3>
<p class="card-text">{{ card.text }}</p>
{% if card.url %}
<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 }}
</a>
{% else %}
<i class="fa-solid fa-hourglass"></i> {{ card.link_text }}
<div class="card h-100 d-flex flex-column">
<div class="card-body d-flex flex-column">
<div class="card-img-top">
{% if card.icon.cache %}
{% if card.icon.cache.endswith('.svg') %}
<object
type="image/svg+xml"
data="{{ url_for('static', filename=card.icon.cache) }}"
style="width:100px; height:auto;">
{% if card.icon.class %}
<i class="{{ card.icon.class }}"></i>
{% endif %}
</object>
{% else %}
<img
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 %}
<i class="{{ card.icon.class }}" style="display:none;"></i>
{% endif %}
</div>
{% endif %}
{% elif card.icon.class %}
<i class="{{ card.icon.class }}"></i>
{% endif %}
</div>
<hr />
<h3 class="card-title">{{ card.title }}</h3>
<p class="card-text">{{ card.text }}</p>
{% if card.url %}
<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 }}
</a>
{% else %}
<i class="fa-solid fa-hourglass"></i> {{ card.link_text }}
{% endif %}
</div>
</div>
</div>

View File

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

View File

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