UPDATE: Removed get profile picture route and moved it to NGINX, and updated how thumbnails were saved to use path_manager

This commit is contained in:
2025-02-28 20:35:58 +00:00
parent d204666d48
commit 3dddcdd107
2 changed files with 25 additions and 6 deletions

View File

@@ -4,6 +4,8 @@ from utils.auth import *
from utils.utils import get_category_id
from blueprints.middleware import login_required
from utils.email import send_email, forgot_password_body, newsletter_conf
from utils.path_manager import PathManager
from celery_tasks.streaming import convert_image_to_png
import redis
from io import BytesIO
@@ -14,6 +16,8 @@ r = redis.from_url(redis_url, decode_responses=True)
user_bp = Blueprint("user", __name__)
path_manager = PathManager()
@user_bp.route('/user/<string:username>')
def user_data(username: str):
"""
@@ -42,13 +46,28 @@ def user_profile_picture_save():
"""
Saves user profile picture
"""
user_id = session.get("user_id")
image = request.files['image']
ext = image.filename.split('.')[-1]
username = session.get("username")
thumbnail_path = path_manager.get_profile_picture_file_path(username)
image.save(f"/web_server/stream_data/{user_id}.{ext}")
# Check if the post request has the file part
if 'image' not in request.files:
return jsonify({"error": "No image found in request"}), 400
# Fetch image, convert to png, and save
image = Image.open(request.files['image'])
image.convert('RGB')
image.save(thumbnail_path, "PNG")
return "Success", 200
return jsonify({"message": "Profile picture saved"})
@user_bp.route('/user/profile_picture/<string:username>')
def user_profile_picture(username: str):
"""
Returns the profile picture of a user
"""
user_id = get_user_id(username)
image = Image.open(f"/web_server/stream_data/{user_id}.jpg")
@login_required
@user_bp.route('/user/same/<string:username>')