From 171770b9eeac8bffcee8e52fe8d2467bf7bcc243 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:27:39 +0100 Subject: [PATCH] modified: app.py --- app.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index b83fd5d..9fdfacd 100644 --- a/app.py +++ b/app.py @@ -97,11 +97,15 @@ def make_discord_session(token=None, state=None): def fetch_and_cache_profile_picture(user_id, avatar_url): """Lädt das Profilbild herunter und speichert es lokal und in Redis.""" + if not user_id or not avatar_url: + # Fallback auf ein Standardprofilbild, wenn keine gültigen Werte vorhanden sind + return "/static/default_profile.png" + local_image_path = os.path.join(PROFILE_IMAGE_DIR, f"{user_id}.png") # Checken, ob das Bild schon lokal vorhanden ist if os.path.exists(local_image_path): - r.set(user_id, local_image_path) + r.set(str(user_id), local_image_path) # Sicherstellen, dass der Key ein String ist return local_image_path try: @@ -112,11 +116,12 @@ def fetch_and_cache_profile_picture(user_id, avatar_url): img_file.write(response.content) # Pfad in Redis speichern - r.set(user_id, local_image_path) + r.set(str(user_id), local_image_path) # Konvertiere user_id zu einem String return local_image_path except requests.RequestException as e: print(f"Error fetching profile picture for user {user_id}: {e}") - return "/static/default_profile.png" # Standardbild + return "/static/default_profile.png" # Standardbild verwenden + def get_profile_picture(user_id, avatar_url): """Gibt den Pfad zum Profilbild eines Benutzers zurück, entweder aus Redis oder durch Abruf."""