-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: Add libraries API route and integrate library refresh functio…
…nality
- Loading branch information
1 parent
a254398
commit 5cadc31
Showing
2 changed files
with
49 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from flask import Blueprint, request | ||
|
||
from chocolate_app import DB, scans | ||
from chocolate_app.tables import Libraries, Users | ||
from chocolate_app.routes.api.auth import token_required | ||
from chocolate_app.utils.utils import generate_response, Codes | ||
|
||
lib_bp = Blueprint("profil", __name__, url_prefix="/profil") | ||
|
||
|
||
@lib_bp.route("/refresh/<lib_id>", methods=["GET", "POST"]) | ||
@token_required | ||
def profil(current_user, lib_id): | ||
if not current_user.account_type == "Admin": | ||
return generate_response(Codes.NOT_LOGGED_IN, True) | ||
|
||
lib = Libraries.query.filter_by(id=lib_id).first() | ||
|
||
if not lib: | ||
return generate_response(Codes.LIBRARY_NOT_FOUND, True) | ||
|
||
library = lib.__dict__ | ||
|
||
type_to_call = { | ||
"series": scans.getSeries, | ||
"consoles": scans.getGames, | ||
"others": scans.getOthersVideos, | ||
"books": scans.getBooks, | ||
"musics": scans.getMusics, | ||
} | ||
|
||
scanner = None | ||
if library["type"] == "movies": | ||
scanner = scans.MovieScanner() | ||
scanner.set_library_name(library["name"]) | ||
scanner.scan() | ||
elif library["type"] == "tv": | ||
scanner = scans.LiveTVScanner() | ||
scanner.set_library_name(library["name"]) | ||
scanner.scan() | ||
else: | ||
scanner = type_to_call[library["type"]] | ||
scanner(library["name"]) | ||
|
||
return generate_response(Codes.SUCCESS, False, {"message": "Library refreshed"}) |