MAJOR Fix: Resolved API Request Delays;
Feat: Added a dev test account to users for expedited login; Refactor: Improve socket connection handling and add logging for API request duration & update to ListRow key generation for improved uniqueness; Feat: Made it so streams with no set thumbnail use their category's thumbnail; Minor Fix: Corrections to db recommendation methods;
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
|
||||
from blueprints.utils import logged_in_user, record_time
|
||||
from blueprints.errorhandlers import register_error_handlers
|
||||
# from flask_wtf.csrf import CSRFProtect, generate_csrf
|
||||
|
||||
@@ -9,7 +9,8 @@ from blueprints.authentication import auth_bp
|
||||
from blueprints.stripe import stripe_bp
|
||||
from blueprints.user import user_bp
|
||||
from blueprints.streams import stream_bp
|
||||
from blueprints.chat import chat_bp, socketio
|
||||
from blueprints.chat import chat_bp
|
||||
from blueprints.socket import socketio
|
||||
|
||||
from os import getenv
|
||||
|
||||
@@ -29,8 +30,11 @@ def create_app():
|
||||
CORS(app, supports_credentials=True)
|
||||
# csrf.init_app(app)
|
||||
|
||||
socketio.init_app(app)
|
||||
|
||||
Session(app)
|
||||
app.before_request(logged_in_user)
|
||||
app.after_request(record_time)
|
||||
|
||||
# adds in error handlers
|
||||
register_error_handlers(app)
|
||||
@@ -48,7 +52,6 @@ def create_app():
|
||||
app.register_blueprint(stream_bp)
|
||||
app.register_blueprint(chat_bp)
|
||||
|
||||
# Tell sockets where the initialisation app is
|
||||
socketio.init_app(app, cors_allowed_origins="*")
|
||||
socketio.init_app(app)
|
||||
|
||||
return app
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
from flask import Blueprint, jsonify, session
|
||||
from database.database import Database
|
||||
from flask_socketio import SocketIO, emit, join_room, leave_room
|
||||
from .socket import socketio
|
||||
from flask_socketio import emit, join_room, leave_room
|
||||
from datetime import datetime
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
chat_bp = Blueprint("chat", __name__)
|
||||
socketio = SocketIO()
|
||||
|
||||
# <---------------------- ROUTES NEEDS TO BE CHANGED TO VIDEO OR DELETED AS DEEMED APPROPRIATE ---------------------->
|
||||
|
||||
|
||||
3
web_server/blueprints/socket.py
Normal file
3
web_server/blueprints/socket.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
socketio = SocketIO(cors_allowed_origins="*", async_mode='gevent', logger=True, engineio_logger=True)
|
||||
@@ -120,7 +120,7 @@ def get_following_categories_streams():
|
||||
"""
|
||||
Returns popular streams in categories which the user followed
|
||||
"""
|
||||
streams = followed_categories_recommendations()
|
||||
streams = followed_categories_recommendations(get_user_id(session.get('username')))
|
||||
return jsonify(streams)
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
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)
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user