FIX: General fixes and update to HomePage
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from flask import Flask
|
||||
from flask_session import Session
|
||||
from flask_cors import CORS
|
||||
from blueprints.utils import logged_in_user, record_time
|
||||
from blueprints.utils import logged_in_user
|
||||
from blueprints.errorhandlers import register_error_handlers
|
||||
# from flask_wtf.csrf import CSRFProtect, generate_csrf
|
||||
|
||||
@@ -48,7 +48,6 @@ def create_app():
|
||||
|
||||
Session(app)
|
||||
app.before_request(logged_in_user)
|
||||
app.after_request(record_time)
|
||||
|
||||
# adds in error handlers
|
||||
register_error_handlers(app)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, session, jsonify, request, redirect, abort
|
||||
from flask import Blueprint, session, jsonify, request, redirect
|
||||
from utils.stream_utils import *
|
||||
from utils.recommendation_utils import *
|
||||
from utils.user_utils import get_user_id
|
||||
@@ -45,15 +45,13 @@ def get_recommended_streams() -> list[dict]:
|
||||
streams = get_streams_based_on_category(category)
|
||||
return streams
|
||||
|
||||
@stream_bp.route('/streams/<string:streamer_username>/data')
|
||||
def get_stream(streamer_username):
|
||||
@stream_bp.route('/streams/<int:streamer_id>/data')
|
||||
def get_stream_data(streamer_id):
|
||||
"""
|
||||
Returns a streamer's most recent stream data
|
||||
Returns a streamer's current stream data
|
||||
"""
|
||||
|
||||
user_id = get_user_id(streamer_username)
|
||||
|
||||
return jsonify(get_most_recent_stream(user_id))
|
||||
return jsonify(get_current_stream_data(streamer_id))
|
||||
|
||||
|
||||
## Category Routes
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from flask import Blueprint, jsonify, session, abort, abort
|
||||
from flask import Blueprint, jsonify, session
|
||||
from utils.user_utils import *
|
||||
from blueprints.utils import login_required
|
||||
from blueprints.email import send_email, forgot_password_body
|
||||
@@ -10,14 +10,14 @@ r = redis.from_url(redis_url, decode_responses=True)
|
||||
user_bp = Blueprint("user", __name__)
|
||||
|
||||
@user_bp.route('/user/<string:username>')
|
||||
def get_user_data_(username):
|
||||
def get_user_data(username):
|
||||
"""
|
||||
Returns a given user's data
|
||||
"""
|
||||
user_id = get_user_id(username)
|
||||
if not user_id:
|
||||
abort(404)
|
||||
data = get_user_data(user_id)
|
||||
jsonify({"error": "User not found from username"}), 404
|
||||
data = get_user(user_id)
|
||||
return jsonify(data)
|
||||
|
||||
## Subscription Routes
|
||||
@@ -127,5 +127,5 @@ def user_reset_password(token, new_password):
|
||||
if response:
|
||||
return 200
|
||||
else:
|
||||
abort(500)
|
||||
return abort(404)
|
||||
return jsonify({"error": "Failed to reset password"}), 500
|
||||
return jsonify({"error": "Invalid token"}), 400
|
||||
@@ -1,25 +1,14 @@
|
||||
from flask import redirect, url_for, request, g, session
|
||||
from functools import wraps
|
||||
from re import match
|
||||
from time import time
|
||||
|
||||
def logged_in_user():
|
||||
"""
|
||||
Validator to make sure a user is logged in.
|
||||
"""
|
||||
g.start_time = time()
|
||||
g.user = session.get("username", None)
|
||||
print(f"Path: {request.path}, session username: {g.user}", flush=True)
|
||||
g.admin = session.get("username", None)
|
||||
|
||||
def record_time(response):
|
||||
if hasattr(g, 'start_time'):
|
||||
time_taken = time() - g.start_time
|
||||
print(f"Request to {request.endpoint} took {time_taken:.4f} seconds", flush=True)
|
||||
else:
|
||||
print("No start time found", flush=True)
|
||||
return response
|
||||
|
||||
def login_required(view):
|
||||
"""
|
||||
Add at start of routes where users need to be logged in to access.
|
||||
|
||||
@@ -94,18 +94,6 @@ INSERT INTO chat (stream_id, chatter_id, message) VALUES
|
||||
(1, 2, 'Woah, cannot believe that');
|
||||
|
||||
|
||||
SELECT * FROM users;
|
||||
SELECT * FROM follows;
|
||||
SELECT * FROM user_preferences;
|
||||
SELECT * FROM subscribes;
|
||||
SELECT * FROM categories;
|
||||
SELECT * FROM streams;
|
||||
SELECT * FROM chat;
|
||||
SELECT * FROM tags;
|
||||
SELECT * FROM stream_tags;
|
||||
|
||||
-- To see all tables in the database
|
||||
SELECT name FROM sqlite_master WHERE type='table';
|
||||
|
||||
SELECT users.user_id, streams.title, streams.num_viewers, users.username
|
||||
FROM streams JOIN users
|
||||
@@ -133,4 +121,17 @@ INSERT INTO followed_categories (user_id, category_id) VALUES
|
||||
|
||||
INSERT INTO subscribes (user_id, subscribed_id, since, expires) VALUES
|
||||
(7, 1, '2024-08-30', '2025-02-28 12:00:00'),
|
||||
(7, 2, '2024-08-30', '2025-02-15');
|
||||
(7, 2, '2024-08-30', '2025-02-15');
|
||||
|
||||
SELECT * FROM users;
|
||||
SELECT * FROM follows;
|
||||
SELECT * FROM user_preferences;
|
||||
SELECT * FROM subscribes;
|
||||
SELECT * FROM categories;
|
||||
SELECT * FROM streams;
|
||||
SELECT * FROM chat;
|
||||
SELECT * FROM tags;
|
||||
SELECT * FROM stream_tags;
|
||||
|
||||
-- To see all tables in the database
|
||||
SELECT name FROM sqlite_master WHERE type='table';
|
||||
|
||||
@@ -34,7 +34,7 @@ def get_followed_live_streams(user_id: int) -> Optional[List[dict]]:
|
||||
""", (user_id,))
|
||||
return live_streams
|
||||
|
||||
def get_most_recent_stream(user_id: int) -> Optional[dict]:
|
||||
def get_current_stream_data(user_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns data of the most recent stream by a streamer
|
||||
"""
|
||||
|
||||
@@ -195,7 +195,7 @@ def get_followed_streamers(user_id: int) -> Optional[List[dict]]:
|
||||
""", (user_id,))
|
||||
return followed_streamers
|
||||
|
||||
def get_user_data(user_id: int) -> Optional[dict]:
|
||||
def get_user(user_id: int) -> Optional[dict]:
|
||||
"""
|
||||
Returns username, bio, number of followers, and if user is partnered from user_id
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user