Fix avatar display by using url_for to generate correct static URLs

parent fc67c67d
...@@ -19,6 +19,7 @@ Common utilities for Video AI application. ...@@ -19,6 +19,7 @@ Common utilities for Video AI application.
Includes authentication decorators and helper functions. Includes authentication decorators and helper functions.
""" """
from flask import url_for
from .auth import get_current_user from .auth import get_current_user
def get_current_user_session(): def get_current_user_session():
...@@ -41,7 +42,7 @@ def get_current_user_session(): ...@@ -41,7 +42,7 @@ def get_current_user_session():
user['gravatar_url'] = f"https://www.gravatar.com/avatar/{email_hash}?s=32&d=404" user['gravatar_url'] = f"https://www.gravatar.com/avatar/{email_hash}?s=32&d=404"
# If custom avatar, use that instead # If custom avatar, use that instead
if user.get('avatar'): if user.get('avatar'):
user['avatar_url'] = f"/static/avatars/{user['avatar']}?t={int(time.time())}" user['avatar_url'] = url_for('static', filename=f'avatars/{user["avatar"]}') + f'?t={int(time.time())}'
else: else:
user['avatar_url'] = user['gravatar_url'] user['avatar_url'] = user['gravatar_url']
return user return user
......
...@@ -1109,12 +1109,6 @@ def delete_avatar(): ...@@ -1109,12 +1109,6 @@ def delete_avatar():
return redirect(url_for('account')) return redirect(url_for('account'))
@app.route('/static/avatars/<filename>')
def serve_avatar(filename):
"""Serve user avatar files."""
return send_from_directory(avatars_dir, filename)
@app.route('/account/change_password', methods=['POST']) @app.route('/account/change_password', methods=['POST'])
@login_required @login_required
def change_password(): def change_password():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment