From 10b613513c7ee5acd6c579ecb192ed82365c4515 Mon Sep 17 00:00:00 2001 From: cwilvx Date: Tue, 7 May 2024 23:00:53 +0300 Subject: [PATCH] fix: default user inserted before userId is created moved application setup function calls before flask app creation --- app/setup/__init__.py | 16 ++++++++------ manage.py | 51 ++++++++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/app/setup/__init__.py b/app/setup/__init__.py index 7a8ed41e..4f784bea 100644 --- a/app/setup/__init__.py +++ b/app/setup/__init__.py @@ -1,6 +1,7 @@ """ Prepares the server for use. """ + import uuid from app.db.sqlite.settings import load_settings from app.setup.files import create_config_dir @@ -14,6 +15,14 @@ from app.config import UserConfig def run_setup(): create_config_dir() + + # setup config file + config = UserConfig() + config.setup_config_file() + + if not config.userId: + config.userId = str(uuid.uuid4()) + setup_sqlite() run_migrations() @@ -23,13 +32,6 @@ def run_setup(): # settings table is empty pass - # setup config file - config = UserConfig() - config.setup_config_file() - - if not config.userId: - config.userId = str(uuid.uuid4()) - instance_key = get_random_str() # INFO: Load all tracks, albums, and artists into memory diff --git a/manage.py b/manage.py index cd83f9c8..7ad50916 100644 --- a/manage.py +++ b/manage.py @@ -47,8 +47,37 @@ mimetypes.add_type("application/manifest+json", ".webmanifest") werkzeug = logging.getLogger("werkzeug") werkzeug.setLevel(logging.ERROR) +# Set up the application HandleArgs() +@background +def bg_run_setup() -> None: + run_periodic_scans() + + +@background +def start_watchdog(): + WatchDog().run() + + +@background +def run_swingmusic(): + log_startup_info() + run_setup() + bg_run_setup() + register_plugins() + + start_watchdog() + + setproctitle.setproctitle(f"swingmusic ::{FLASKVARS.get_flask_port()}") + + +Info.load() +run_swingmusic() + + +# Create the Flask app + app = create_api() app.static_folder = get_home_res_path("client") @@ -160,31 +189,9 @@ def print_memory_usage(response: Response): return response -@background -def bg_run_setup() -> None: - run_periodic_scans() - - -@background -def start_watchdog(): - WatchDog().run() - - -@background -def run_swingmusic(): - log_startup_info() - run_setup() - bg_run_setup() - register_plugins() - - start_watchdog() - - setproctitle.setproctitle(f"swingmusic ::{FLASKVARS.get_flask_port()}") if __name__ == "__main__": - Info.load() - run_swingmusic() host = FLASKVARS.get_flask_host() port = FLASKVARS.get_flask_port()