Spaces:
Sleeping
Sleeping
reset
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ FastAPI URL Blink Application
|
|
| 4 |
Production-grade API for receiving encrypted user data,
|
| 5 |
decrypting it, and storing in SQLite database.
|
| 6 |
"""
|
|
|
|
| 7 |
import logging
|
| 8 |
from contextlib import asynccontextmanager
|
| 9 |
from fastapi import FastAPI, Request
|
|
@@ -32,9 +33,16 @@ async def lifespan(app: FastAPI):
|
|
| 32 |
"""
|
| 33 |
logger.info("Starting up - initializing database...")
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
await init_db()
|
| 40 |
logger.info("Database initialized successfully")
|
|
|
|
| 4 |
Production-grade API for receiving encrypted user data,
|
| 5 |
decrypting it, and storing in SQLite database.
|
| 6 |
"""
|
| 7 |
+
import os
|
| 8 |
import logging
|
| 9 |
from contextlib import asynccontextmanager
|
| 10 |
from fastapi import FastAPI, Request
|
|
|
|
| 33 |
"""
|
| 34 |
logger.info("Starting up - initializing database...")
|
| 35 |
|
| 36 |
+
# Check for RESET_DB environment variable
|
| 37 |
+
if os.getenv("RESET_DB", "").lower() == "true":
|
| 38 |
+
logger.warning("RESET_DB is set to true. Skipping download and clearing local database.")
|
| 39 |
+
if os.path.exists("blink_data.db"):
|
| 40 |
+
os.remove("blink_data.db")
|
| 41 |
+
logger.info("Local database deleted.")
|
| 42 |
+
else:
|
| 43 |
+
# Startup: Download DB from Drive
|
| 44 |
+
logger.info("Startup: Attempting to download database from Google Drive...")
|
| 45 |
+
drive_service.download_db()
|
| 46 |
|
| 47 |
await init_db()
|
| 48 |
logger.info("Database initialized successfully")
|