modified: app.py
This commit is contained in:
11
app.py
11
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."""
|
||||
|
||||
Reference in New Issue
Block a user