aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-06-16 21:24:51 +0300
committerJan Tuomi <jan@jantuomi.fi>2025-06-16 21:24:51 +0300
commitf01b3a41713204964f5c65d7c9cbd5613ae7098b (patch)
treea2a8d86f307013ab51f3f47f584815faf4c26630
parentbf31ea42ba606ba38081d84194c0dd7f806befab (diff)
Move init to create_app()
-rw-r--r--app.py24
1 files 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()