-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit 98a232f Author: Crossoufire <[email protected]> Date: Thu May 30 16:25:19 2024 +0200 Added Changelog v1.4.0 commit 20224ab Author: Crossoufire <[email protected]> Date: Thu May 30 16:07:56 2024 +0200 MyLists 1.4 update commit e3e0206 Author: Crossoufire <[email protected]> Date: Thu May 9 14:29:17 2024 +0200 Replaced react router with tanstack router + loaders commit 86c5d79 Author: Crossoufire <[email protected]> Date: Wed May 1 16:28:42 2024 +0200 alpha 1.4.0 - Fix comments on /lists: subtles bad behaviors + no saving - Fix remove Seasons and episodes and times in general in Plan to - Fix books: avoid update page if page did not change - Remove the ":" in follow card in /details - Fix frontend React keys and nested <a>/<button> warnings - Fix cache and now using SystemFileCache instead of memory - Create different user routes settings in backend - Misc refactoring backend - Replace BrowserRouter with RouterProvider for frontend - Cleaned frontend components - Re-created Settings UI - Added Skeleton Loading for HoF - Create a dedicated stats page for each user instead of /lists - Added ribbon "in_list" for creator/actor/network etc... on /details - Add backend unit tests commit a721e87 Author: Crossoufire <[email protected]> Date: Tue Mar 19 16:53:10 2024 +0100 Misc refactoring commit 9ae0a8d Author: Crossoufire <[email protected]> Date: Tue Mar 19 16:52:52 2024 +0100 Better error handling for API calls commit 2b74ade Author: Crossoufire <[email protected]> Date: Tue Mar 19 16:51:58 2024 +0100 Merged series/anime models using abstract models commit 8d0f3da Author: Crossoufire <[email protected]> Date: Tue Mar 19 16:50:59 2024 +0100 Fix feeling drop for books in /details
- Loading branch information
1 parent
d5c06a5
commit 5984743
Showing
246 changed files
with
22,591 additions
and
23,288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import logging | ||
import os | ||
from logging.handlers import SMTPHandler, RotatingFileHandler | ||
from typing import Type | ||
from flask import Flask | ||
from flask_migrate import Migrate | ||
from flask_bcrypt import Bcrypt | ||
from flask_caching import Cache | ||
from flask_cors import CORS | ||
from flask_mail import Mail | ||
from flask_migrate import Migrate | ||
from flask_sqlalchemy import SQLAlchemy | ||
from backend.api.utils.enums import RoleType | ||
from backend.config import Config | ||
|
||
|
||
# Globally accessible Flask modules | ||
config = Config() | ||
mail = Mail() | ||
db = SQLAlchemy() | ||
migrate = Migrate() | ||
|
@@ -24,7 +25,6 @@ | |
def _import_blueprints(app: Flask): | ||
""" Import and register the blueprints for the app """ | ||
|
||
# Import API blueprints | ||
from backend.api.routes.tokens import tokens as api_tokens_bp | ||
from backend.api.routes.users import users as api_users_bp | ||
from backend.api.routes.media import media_bp as api_media_bp | ||
|
@@ -34,22 +34,20 @@ def _import_blueprints(app: Flask): | |
from backend.api.routes.admin import admin_bp as api_admin_bp | ||
from backend.api.routes.details import details_bp as api_details_bp | ||
from backend.api.routes.lists import lists_bp as api_lists_bp | ||
from backend.api.routes.labels import labels_bp as api_labels_bp | ||
|
||
# Blueprints list | ||
api_blueprints = [api_tokens_bp, api_users_bp, api_media_bp, api_search_bp, api_general_bp, api_errors_bp, | ||
api_admin_bp, api_details_bp, api_lists_bp] | ||
api_admin_bp, api_details_bp, api_lists_bp, api_labels_bp] | ||
|
||
# Register blueprints | ||
for blueprint in api_blueprints: | ||
app.register_blueprint(blueprint, url_prefix="/api") | ||
|
||
|
||
def _create_app_logger(app: Flask): | ||
""" Create an app logger registering the INFO, WARNING, and ERRORS, for the app """ | ||
""" Create an app logger registering the INFO, WARNING, and ERRORS for the app """ | ||
|
||
log_file_path = "MyLists/backend/api/static/log/mylists.log" | ||
log_file_path = f"{os.path.abspath(os.path.dirname(__file__))}/static/log/mylists.log" | ||
|
||
# Check if log file exists, if not, create it | ||
if not os.path.exists(log_file_path): | ||
os.makedirs(os.path.dirname(log_file_path), exist_ok=True) | ||
with open(log_file_path, "a"): | ||
|
@@ -65,7 +63,7 @@ def _create_app_logger(app: Flask): | |
|
||
|
||
def _create_mail_handler(app: Flask): | ||
""" Create a mail handler (TSL only) associated with the app logger: send an email when an error occurs """ | ||
""" Create a mail handler (TLS only) associated with the app logger: send email when errors occurs """ | ||
|
||
mail_handler = SMTPHandler( | ||
mailhost=(app.config["MAIL_SERVER"], app.config["MAIL_PORT"]), | ||
|
@@ -76,75 +74,48 @@ def _create_mail_handler(app: Flask): | |
secure=(), | ||
) | ||
|
||
# Set logger level to ERROR only | ||
mail_handler.setLevel(logging.ERROR) | ||
app.logger.addHandler(mail_handler) | ||
|
||
|
||
# def _create_first_db_data(): | ||
# """ Create all the database tables the first time and add the first data to the database """ | ||
# | ||
# from MyLists.models.user_models import User | ||
# from datetime import datetime | ||
# from MyLists.utils.scheduled_tasks import compute_media_time_spent | ||
# from MyLists.models.utils_models import Badges, Ranks | ||
# | ||
# # Create all DB tables - does not update existing tables | ||
# db.create_all() | ||
# | ||
# # Create an <admin>, a <manager> and a <user> if <admin> does not exist | ||
# if User.query.filter_by(id="1").first() is None: | ||
# admin1 = User( | ||
# username="admin", | ||
# email="[email protected]", | ||
# password=bcrypt.generate_password_hash("password").decode("utf-8"), | ||
# active=True, | ||
# private=True, | ||
# registered_on=datetime.utcnow(), | ||
# activated_on=datetime.utcnow(), | ||
# role=RoleType.ADMIN, | ||
# ) | ||
# manager1 = User( | ||
# username="manager", | ||
# email="[email protected]", | ||
# password=bcrypt.generate_password_hash("password").decode("utf-8"), | ||
# active=True, | ||
# registered_on=datetime.utcnow(), | ||
# activated_on=datetime.utcnow(), | ||
# role=RoleType.MANAGER, | ||
# ) | ||
# user1 = User( | ||
# username="user", | ||
# email="[email protected]", | ||
# password=bcrypt.generate_password_hash("password").decode("utf-8"), | ||
# active=True, | ||
# registered_on=datetime.utcnow(), | ||
# activated_on=datetime.utcnow(), | ||
# ) | ||
# | ||
# db.session.add_all([admin1, manager1, user1]) | ||
# | ||
# Badges.add_badges_to_db() | ||
# Ranks.add_ranks_to_db() | ||
# | ||
# # Refresh badges, ranks and compute time spent for each user | ||
# Badges.refresh_db_badges() | ||
# Ranks.refresh_db_ranks() | ||
# compute_media_time_spent() | ||
# | ||
# # Commit changes | ||
# db.session.commit() | ||
|
||
|
||
def init_app() -> Flask: | ||
""" Create and initialize the application """ | ||
|
||
# Fetch Flask app name (.flaskenv) and check config from <.env> file | ||
def _create_first_db_data(): | ||
""" Create all DB tables the first time and add the first data to the DB """ | ||
|
||
from backend.api.models.user_models import User | ||
from backend.api.utils.scheduled_tasks import compute_media_time_spent | ||
from backend.api.models.utils_models import Ranks, Frames | ||
|
||
# Create all DB tables - does not update existing tables | ||
db.create_all() | ||
|
||
# Create an <admin> if no user in DB | ||
if User.query.filter_by(id=1).first() is None: | ||
admin = User( | ||
username="admin", | ||
email="[email protected]", | ||
password=bcrypt.generate_password_hash("password").decode("utf-8"), | ||
active=True, | ||
registered_on=datetime.utcnow(), | ||
activated_on=datetime.utcnow(), | ||
role=RoleType.ADMIN, | ||
) | ||
|
||
db.session.add(admin) | ||
db.session.commit() | ||
|
||
Ranks.update_db_ranks() | ||
Frames.update_db_frames() | ||
compute_media_time_spent() | ||
db.session.commit() | ||
|
||
|
||
def create_app(config_class: Type[Config] = Config) -> Flask: | ||
""" Create and initialize the app """ | ||
|
||
app = Flask(__name__, static_url_path="/api/static") | ||
app.config.from_object(config) | ||
app.config.from_object(config_class) | ||
app.url_map.strict_slashes = False | ||
|
||
# Initialize modules | ||
mail.init_app(app) | ||
db.init_app(app) | ||
bcrypt.init_app(app) | ||
|
@@ -155,11 +126,22 @@ def init_app() -> Flask: | |
with app.app_context(): | ||
_import_blueprints(app) | ||
|
||
if app.debug is False: | ||
if not app.debug and not app.testing: | ||
_create_app_logger(app) | ||
_create_mail_handler(app) | ||
|
||
from backend.api.utils.scheduled_tasks import add_cli_commands | ||
add_cli_commands() | ||
|
||
# _create_first_db_data() | ||
|
||
return app | ||
|
||
|
||
# Needed for import problems | ||
from backend.api.models.books_models import * | ||
from backend.api.models.games_models import * | ||
from backend.api.models.movies_models import * | ||
from backend.api.models.tv_models import * | ||
from backend.api.models.user_models import * | ||
from backend.api.models.utils_models import * |
Oops, something went wrong.