FEAT: Implemented auto-updating thumbnails (includes the addition of Redis and Celery)

This commit is contained in:
2025-01-31 00:12:28 +00:00
parent 21a45e5538
commit 4396d71c2d
8 changed files with 134 additions and 12 deletions

View File

@@ -11,6 +11,8 @@ from blueprints.user import user_bp
from blueprints.streams import stream_bp
from blueprints.chat import chat_bp
from blueprints.socket import socketio
from celery import Celery
from celery_tasks import celery_init_app
from os import getenv
@@ -26,6 +28,17 @@ def create_app():
app.config["SECRET_KEY"] = getenv("FLASK_SECRET_KEY")
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
app.config.from_mapping(
CELERY=dict(
broker_url="redis://redis:6379/0",
result_backend="redis://redis:6379/0",
task_ignore_result=True,
),
)
app.config.from_prefixed_env()
celery = celery_init_app(app)
#! ↓↓↓ For development purposes only - Allow cross-origin requests for the frontend
CORS(app, supports_credentials=True)
# csrf.init_app(app)

View File

@@ -1,10 +1,10 @@
from flask import Blueprint, session, jsonify, g, request, redirect, abort
from flask import Blueprint, session, jsonify, g, request, redirect, abort, send_from_directory
from utils.stream_utils import (
streamer_live_status,
streamer_most_recent_stream,
user_stream,
followed_live_streams,
followed_streamers,
followed_streamers
)
from utils.user_utils import get_user_id
from blueprints.utils import login_required
@@ -18,8 +18,13 @@ from utils.recommendation_utils import (
from utils.utils import most_popular_category
from database.database import Database
from datetime import datetime
from celery_tasks import update_thumbnail
stream_bp = Blueprint("stream", __name__)
# Constants
THUMBNAIL_GENERATION_INTERVAL = 180
@stream_bp.route('/get_streams')
def get_sample_streams() -> list[dict]:
@@ -185,6 +190,8 @@ def publish_stream():
datetime.now(),
1))
update_thumbnail.delay(user_info["user_id"])
return redirect(f"/{user_info['username']}")
@stream_bp.route("/end_stream", methods=["POST"])
@@ -201,4 +208,4 @@ def end_stream():
# Set stream to not live
db.execute("""UPDATE streams SET isLive = 0 WHERE user_id = ? AND isLive = 1""", (user_info["user_id"],))
return "Stream ended", 200
return "Stream ended", 200