From d577b4036f4821a38f6bccb6abd0a4c97c83818c Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 13 Apr 2026 20:10:24 +0300 Subject: Fix some issues --- app.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app.py b/app.py index 28f6de4..0c864c6 100644 --- a/app.py +++ b/app.py @@ -42,20 +42,6 @@ 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" @@ -111,7 +97,7 @@ def save_files_periodically(): # File not in DB — insert new with thumbnail thumb_path = download_and_create_thumbnail(f["id"]) cur.execute(""" - INSERT INTO files (id, name, description, date, thumbnail) + INSERT OR IGNORE INTO files (id, name, description, date, thumbnail) VALUES (?, ?, ?, ?, ?) """, (f["id"], f["name"], f.get("description", ""), date, thumb_path)) else: @@ -141,6 +127,20 @@ def save_files_periodically(): print("Error updating file list:", e) time.sleep(60) +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() + # Route: Gallery @app.route("/") def gallery(): -- cgit v1.3