diff options
-rw-r--r-- | api/auth/login.py | 2 | ||||
-rw-r--r-- | api/auth/login_token.py | 2 | ||||
-rw-r--r-- | api/auth/signup.py | 2 | ||||
-rw-r--r-- | api/dynamic_import.py | 20 | ||||
-rw-r--r-- | api/game/random.py | 2 | ||||
-rw-r--r-- | api/game/voerbak_connector.py | 5 | ||||
-rw-r--r-- | api/log.py | 8 | ||||
-rw-r--r-- | api/main.py | 20 | ||||
-rw-r--r-- | api/status.py | 3 | ||||
-rw-r--r-- | api/user/info.py | 2 |
10 files changed, 43 insertions, 23 deletions
diff --git a/api/auth/login.py b/api/auth/login.py index ae6ca96..9b99ba9 100644 --- a/api/auth/login.py +++ b/api/auth/login.py @@ -32,3 +32,5 @@ def index(): res.set_cookie("token", new_token["token"], expires = int(new_token["expirationDate"] / 1000)) return res + +dynamic_route = ["/auth", login] diff --git a/api/auth/login_token.py b/api/auth/login_token.py index 5812189..67b2a42 100644 --- a/api/auth/login_token.py +++ b/api/auth/login_token.py @@ -17,3 +17,5 @@ def index(): if not auth_token: return "", 400 return "", 200 if token_login(auth_token) else 401 + +dynamic_route = ["/auth", token] diff --git a/api/auth/signup.py b/api/auth/signup.py index 69c786f..a29bc59 100644 --- a/api/auth/signup.py +++ b/api/auth/signup.py @@ -41,3 +41,5 @@ def index(): res.set_cookie("token", new_token["token"], expires = int(new_token["expirationDate"] / 1000)) return res + +dynamic_route = ["/auth", signup] diff --git a/api/dynamic_import.py b/api/dynamic_import.py new file mode 100644 index 0000000..f7945f9 --- /dev/null +++ b/api/dynamic_import.py @@ -0,0 +1,20 @@ +from app import app +import importlib +import os +import log +import glob + +files = glob.glob(os.path.dirname(__file__) + "/**/*.py", recursive=True) +files.remove(__file__) +files = [str(filename) + .replace(os.path.dirname(__file__) + "/", '') + .replace("/", ".") + .replace(".py", '') + for filename in files] + +for file in files: + mod = importlib.import_module(file) + if not hasattr(mod, "dynamic_route"): continue + app.register_blueprint(mod.dynamic_route[1], url_prefix=mod.dynamic_route[0]) + log.info(f"dynamically routing {mod.dynamic_route[0]}{mod.dynamic_route[1].import_name}") + diff --git a/api/game/random.py b/api/game/random.py index ab4323d..38b9ba6 100644 --- a/api/game/random.py +++ b/api/game/random.py @@ -42,3 +42,5 @@ def index(): player_1 = False return { "id": game_id, "player_1": player_1 }, 200 + +dynamic_route = ["/game", random_game] diff --git a/api/game/voerbak_connector.py b/api/game/voerbak_connector.py index 65551ca..6c08553 100644 --- a/api/game/voerbak_connector.py +++ b/api/game/voerbak_connector.py @@ -1,11 +1,8 @@ from colorama import Fore -import logging as log +import log import subprocess import os -VERBOSE = log.ERROR -log.basicConfig(format="[ %(levelname)s ]: %(message)s", level=VERBOSE) - DISC_SHAPE = "o" DISC_A = Fore.RED + DISC_SHAPE + Fore.RESET DISC_B = Fore.BLUE + DISC_SHAPE + Fore.RESET diff --git a/api/log.py b/api/log.py new file mode 100644 index 0000000..81346ed --- /dev/null +++ b/api/log.py @@ -0,0 +1,8 @@ +import logging + +VERBOSE = logging.INFO +logging.basicConfig(format="[ %(levelname)s ]: %(message)s", level=VERBOSE) + +error = logging.error +info = logging.info +warning = logging.warning diff --git a/api/main.py b/api/main.py index e371ed2..2d07f4c 100644 --- a/api/main.py +++ b/api/main.py @@ -1,24 +1,6 @@ +import dynamic_import from app import app -from status import status -from user.info import info -from auth.signup import signup -from auth.login import login -from auth.login_token import token -# from game.new import new_game -from game.random import random_game - -app.register_blueprint(status, url_prefix='/') - -app.register_blueprint(info, url_prefix='/user') - -app.register_blueprint(signup, url_prefix='/auth') -app.register_blueprint(login, url_prefix='/auth') -app.register_blueprint(token, url_prefix='/auth') - -# app.register_blueprint(new_game, url_prefix='/game') -app.register_blueprint(random_game, url_prefix='/game') - from socket_io import io import game.socket diff --git a/api/status.py b/api/status.py index 9d6ba37..6739c9d 100644 --- a/api/status.py +++ b/api/status.py @@ -5,3 +5,6 @@ status = Blueprint('status', __name__) @status.route('/status') def index(): return "" + +dynamic_route = ["/", status] + diff --git a/api/user/info.py b/api/user/info.py index 1339d8a..afb0720 100644 --- a/api/user/info.py +++ b/api/user/info.py @@ -35,3 +35,5 @@ def index(): "registered": user[4], "avatar": user[5], } + +dynamic_route = ["/user", info] |