This commit is contained in:
EvanLin3141
2025-03-01 00:44:34 +00:00
12 changed files with 162 additions and 89 deletions

View File

@@ -5,7 +5,7 @@ from utils.user_utils import get_user_id
from blueprints.middleware import login_required
from database.database import Database
from datetime import datetime
from celery_tasks import update_thumbnail, combine_ts_stream
from celery_tasks.streaming import update_thumbnail, combine_ts_stream
from dateutil import parser
from utils.path_manager import PathManager
import json
@@ -198,7 +198,7 @@ def init_stream():
# Create necessary directories
username = user_info["username"]
create_local_directories(username)
create_user_directories(username)
return redirect(f"/stream/{username}")
@@ -216,7 +216,6 @@ def publish_stream():
periodically update thumbnail
"""
try:
data = json.loads(request.form.get("data"))
except json.JSONDecodeError as ex:

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>')