Spaces:
Sleeping
Sleeping
Commit ·
addc2cc
1
Parent(s): eb37565
added credentials
Browse files- .gitignore +3 -1
- facematch.db-shm +0 -0
- main.py +9 -3
.gitignore
CHANGED
|
@@ -5,5 +5,7 @@ __pycache__/
|
|
| 5 |
.venv
|
| 6 |
venv/
|
| 7 |
serviceAccountKey.json
|
| 8 |
-
facematch.db
|
|
|
|
|
|
|
| 9 |
*.DS_Store
|
|
|
|
| 5 |
.venv
|
| 6 |
venv/
|
| 7 |
serviceAccountKey.json
|
| 8 |
+
facematch.db*
|
| 9 |
+
credentials.json
|
| 10 |
+
user_credentials.json
|
| 11 |
*.DS_Store
|
facematch.db-shm
CHANGED
|
Binary files a/facematch.db-shm and b/facematch.db-shm differ
|
|
|
main.py
CHANGED
|
@@ -289,12 +289,15 @@ def get_drive_service():
|
|
| 289 |
creds_data = None
|
| 290 |
|
| 291 |
if creds_json:
|
| 292 |
-
creds_data = json.
|
|
|
|
| 293 |
elif os.path.exists('user_credentials.json'):
|
| 294 |
with open('user_credentials.json', 'r') as f:
|
| 295 |
creds_data = json.load(f)
|
|
|
|
| 296 |
|
| 297 |
if not creds_data:
|
|
|
|
| 298 |
raise Exception("No Google Credentials found (ENV or user_credentials.json)")
|
| 299 |
|
| 300 |
creds = Credentials.from_authorized_user_info(creds_data, GOOGLE_DRIVE_SCOPES)
|
|
@@ -304,7 +307,7 @@ def get_drive_service():
|
|
| 304 |
creds.refresh(GoogleRequest())
|
| 305 |
except Exception as e:
|
| 306 |
logger.error(f"Failed to refresh Google Token: {e}. The token might be expired or revoked.")
|
| 307 |
-
raise Exception("Google Drive Token Expired. Please run '
|
| 308 |
|
| 309 |
return build('drive', 'v3', credentials=creds, cache_discovery=False)
|
| 310 |
|
|
@@ -572,8 +575,11 @@ def get_status(uid: str, background_tasks: BackgroundTasks):
|
|
| 572 |
}
|
| 573 |
|
| 574 |
@app.get("/folders")
|
| 575 |
-
def get_folders(uid: str):
|
| 576 |
"""Returns a list of indexed folders accessible to the user (owned, shared, or public)"""
|
|
|
|
|
|
|
|
|
|
| 577 |
collections_ref = db_firestore.collection('collections')
|
| 578 |
|
| 579 |
# We want (owner_id == uid) OR (shared_with contains uid) OR (is_public == True)
|
|
|
|
| 289 |
creds_data = None
|
| 290 |
|
| 291 |
if creds_json:
|
| 292 |
+
creds_data = json.load(io.StringIO(creds_json)) if not isinstance(creds_json, dict) else creds_json
|
| 293 |
+
logger.info("Loaded Google Drive credentials from GOOGLE_USER_CREDENTIALS environment variable")
|
| 294 |
elif os.path.exists('user_credentials.json'):
|
| 295 |
with open('user_credentials.json', 'r') as f:
|
| 296 |
creds_data = json.load(f)
|
| 297 |
+
logger.info("Loaded Google Drive credentials from local user_credentials.json")
|
| 298 |
|
| 299 |
if not creds_data:
|
| 300 |
+
logger.error("No Google Drive credentials found! Please set GOOGLE_USER_CREDENTIALS or provide user_credentials.json")
|
| 301 |
raise Exception("No Google Credentials found (ENV or user_credentials.json)")
|
| 302 |
|
| 303 |
creds = Credentials.from_authorized_user_info(creds_data, GOOGLE_DRIVE_SCOPES)
|
|
|
|
| 307 |
creds.refresh(GoogleRequest())
|
| 308 |
except Exception as e:
|
| 309 |
logger.error(f"Failed to refresh Google Token: {e}. The token might be expired or revoked.")
|
| 310 |
+
raise Exception("Google Drive Token Expired. Please run 'python3 generate_token.py' to re-authenticate.")
|
| 311 |
|
| 312 |
return build('drive', 'v3', credentials=creds, cache_discovery=False)
|
| 313 |
|
|
|
|
| 575 |
}
|
| 576 |
|
| 577 |
@app.get("/folders")
|
| 578 |
+
def get_folders(uid: Optional[str] = None):
|
| 579 |
"""Returns a list of indexed folders accessible to the user (owned, shared, or public)"""
|
| 580 |
+
if not uid:
|
| 581 |
+
return {"collections": []}
|
| 582 |
+
|
| 583 |
collections_ref = db_firestore.collection('collections')
|
| 584 |
|
| 585 |
# We want (owner_id == uid) OR (shared_with contains uid) OR (is_public == True)
|