From f01b3a41713204964f5c65d7c9cbd5613ae7098b Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 16 Jun 2025 21:24:51 +0300 Subject: Move init to create_app() --- app.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 0de55f2..28f6de4 100644 --- a/app.py +++ b/app.py @@ -26,11 +26,6 @@ AUTHOR = os.environ["AUTHOR"] IG_LINK = os.environ.get("IG_LINK", None) BASE_URL = os.environ["BASE_URL"] -# Setup -os.makedirs(THUMBNAIL_DIR, exist_ok=True) -app = Flask(__name__) -Compress(app) - # Initialize DB def init_db(): # Create dir if not exists @@ -47,6 +42,20 @@ def init_db(): ) """) +def create_app() -> Flask: + init_db() + + os.makedirs(THUMBNAIL_DIR, exist_ok=True) + thread = threading.Thread(target=save_files_periodically, daemon=True) + thread.start() + + app = Flask(__name__) + Compress(app) + return app + +# Setup +app = create_app() + # Get image files from the given Google Drive folder (non-recursive) def list_drive_files(folder_id): url = "https://www.googleapis.com/drive/v3/files" @@ -175,8 +184,3 @@ def serve_thumbnail(filename): response = make_response(send_file(path)) response.headers["Cache-Control"] = "public, max-age=86400, stale-while-revalidate=604800" return response - -init_db() - -thread = threading.Thread(target=save_files_periodically, daemon=True) -thread.start() -- cgit v1.3