diff options
| -rw-r--r-- | app.py | 30 |
1 files changed, 15 insertions, 15 deletions
@@ -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(): |
