Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 98a232f
Author: Crossoufire <47953962+Crossoufire@users.noreply.github.com>
Date:   Thu May 30 16:25:19 2024 +0200

    Added Changelog v1.4.0

commit 20224ab
Author: Crossoufire <47953962+Crossoufire@users.noreply.github.com>
Date:   Thu May 30 16:07:56 2024 +0200

    MyLists 1.4 update

commit e3e0206
Author: Crossoufire <47953962+Crossoufire@users.noreply.github.com>
Date:   Thu May 9 14:29:17 2024 +0200

    Replaced react router with tanstack router + loaders

commit 86c5d79
Author: Crossoufire <47953962+Crossoufire@users.noreply.github.com>
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 <47953962+Crossoufire@users.noreply.github.com>
Date:   Tue Mar 19 16:53:10 2024 +0100

    Misc refactoring

commit 9ae0a8d
Author: Crossoufire <47953962+Crossoufire@users.noreply.github.com>
Date:   Tue Mar 19 16:52:52 2024 +0100

    Better error handling for API calls

commit 2b74ade
Author: Crossoufire <47953962+Crossoufire@users.noreply.github.com>
Date:   Tue Mar 19 16:51:58 2024 +0100

    Merged series/anime models using abstract models

commit 8d0f3da
Author: Crossoufire <47953962+Crossoufire@users.noreply.github.com>
Date:   Tue Mar 19 16:50:59 2024 +0100

    Fix feeling drop for books in /details
  • Loading branch information
Crossoufire committed May 30, 2024
1 parent d5c06a5 commit 5984743
Show file tree
Hide file tree
Showing 246 changed files with 22,591 additions and 23,288 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ frontend/.env.production
build/*

# BACKEND STUFF
backend/cache/*

backend/api/static/profile_pics/*
!backend/api/static/profile_pics/default.jpg
!backend/api/static/profile_pics/anonymous.jpg
!backend/tests/images/anonymous.jpg

backend/api/static/background_pics/*
!backend/api/static/background_pics/default.jpg
Expand All @@ -117,5 +119,4 @@ backend/api/static/covers/books_covers/*
# FRONTEND STUFF
/frontend/node_modules


# -------------------------------------------------------------------------------------
36 changes: 34 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
## CHANGELOG v1.4.0
---
### Under the Hood
- Created different user routes settings in backend
- Misc refactoring backend
- Cleaned frontend components
- Add backend unit tests (5/11)
- Replaced React-router by TanStack Router (change the loading page behavior)
- Replaced Recharts with Nivo (reduce bundle size)

### Features
- Added a dedicated stats page for each user in `/stats/<media_type>/<username>`
- Added a present in list media checkmark for creator/actor/network etc... on `/details`
- Added a 20 min long-polling for the notifications system

### UI Modifications
- Re-created the `/settings` UI
- Re-created the `/list` interface completely
- Re-created the media cards in `/coming_next` and `/details/jobs` with the same style as `/list`
- Created a LabelManager, accessible in `/details` and `/list`
- Better edit forms in `/details/form`
- Removed ":" for the follow cards in `/details`

### Fixes
- Fix subtle errors for 401 Unauthorized errors
- Fix can add two times a label for the same media in `/details`
- Fix comments on `/lists`: subtle bad behaviors + no saving
- Fix Seasons and episodes in `/lists` and `/details`
- Fix books: avoid update page if page did not change
- Fix some frontend React keys and nested a/button warnings
- Fix cache and now using SystemFileCache instead of memory

## CHANGELOG v1.3.1
---
### Fixes
Expand Down Expand Up @@ -39,10 +71,10 @@
### Under the Hood
- Added Tailwind CSS
- Replaced Bootstrap by Shadcn-UI
- Moved from Create React App (CRA) to Vite with react plugin
- Moved from Create React App_old (CRA) to Vite with react plugin

### Features
- Implemented OAuth2 authentication: Github and Google
- Implemented OAuth2 authentication: GitHub and Google
- Added `React-Helmet` to manage metadata in the header
- Removed the changelog in the website (not a fan)

Expand Down
128 changes: 55 additions & 73 deletions backend/api/__init__.py
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()
Expand All @@ -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
Expand All @@ -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"):
Expand All @@ -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"]),
Expand All @@ -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="admin@admin.com",
# 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="manager@manager.com",
# 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="user@user.com",
# 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="admin@admin.com",
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)
Expand All @@ -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 *
Loading

0 comments on commit 5984743

Please sign in to comment.