Merge branch 'main' of https://github.com/john-david3/cs3305-team11
This commit is contained in:
@@ -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
|
||||
@@ -60,7 +60,6 @@ def recommended_streams() -> list[dict]:
|
||||
"""
|
||||
|
||||
user_id = session.get("user_id")
|
||||
|
||||
# Get the user's most popular categories
|
||||
category = get_user_preferred_category(user_id)
|
||||
streams = get_streams_based_on_category(category)
|
||||
@@ -112,7 +111,7 @@ def recommended_categories() -> list | list[dict]:
|
||||
|
||||
"""
|
||||
user_id = session.get("user_id")
|
||||
categories = get_user_category_recommendations(user_id)
|
||||
categories = get_user_category_recommendations(1)
|
||||
return jsonify(categories)
|
||||
|
||||
|
||||
@@ -127,6 +126,18 @@ def following_categories_streams():
|
||||
return jsonify(streams)
|
||||
|
||||
|
||||
@login_required
|
||||
@stream_bp.route('/categories/your_categories')
|
||||
def following_your_categories():
|
||||
"""
|
||||
Returns categories which the user followed
|
||||
"""
|
||||
|
||||
streams = get_followed_your_categories(session.get('user_id'))
|
||||
return jsonify(streams)
|
||||
|
||||
|
||||
|
||||
# User Routes
|
||||
@stream_bp.route('/user/<string:username>/status')
|
||||
def user_live_status(username):
|
||||
@@ -162,6 +173,17 @@ def vods(username):
|
||||
vods = get_user_vods(user_id)
|
||||
return jsonify(vods)
|
||||
|
||||
@stream_bp.route('/vods/all')
|
||||
def get_all_vods():
|
||||
"""
|
||||
Returns data of all VODs by all streamers in a JSON-compatible format
|
||||
"""
|
||||
with Database() as db:
|
||||
vods = db.fetchall("SELECT * FROM vods")
|
||||
|
||||
print("Fetched VODs from DB:", vods)
|
||||
|
||||
return jsonify(vods)
|
||||
|
||||
# RTMP Server Routes
|
||||
|
||||
@@ -187,7 +209,7 @@ def init_stream():
|
||||
|
||||
# Create necessary directories
|
||||
username = user_info["username"]
|
||||
create_local_directories(username)
|
||||
create_user_directories(username)
|
||||
|
||||
return redirect(f"/stream/{username}")
|
||||
|
||||
|
||||
@@ -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,19 @@ 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"})
|
||||
|
||||
@login_required
|
||||
@user_bp.route('/user/same/<string:username>')
|
||||
|
||||
Reference in New Issue
Block a user