Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -908,6 +908,17 @@ async def sync_data(data_json: str = Form(...), user_id: str = Form(...)):
|
|
| 908 |
|
| 909 |
|
| 910 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 911 |
|
| 912 |
class DriveWatcher:
|
| 913 |
def __init__(self):
|
|
@@ -972,11 +983,18 @@ class DriveWatcher:
|
|
| 972 |
await self.close_channel(channel_id, channel_info['resourceId'])
|
| 973 |
del self.channels[channel_id]
|
| 974 |
break
|
| 975 |
-
|
| 976 |
@app.on_event("startup")
|
| 977 |
async def startup_event():
|
| 978 |
app.state.drive_watcher = DriveWatcher()
|
| 979 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 980 |
|
| 981 |
# Fetch all users and initialize the watch list
|
| 982 |
users_ref = app.state.firestore_client.collection('users')
|
|
@@ -992,6 +1010,7 @@ async def startup_event():
|
|
| 992 |
# Set up the Firebase listener
|
| 993 |
app.state.users_watch = users_ref.on_snapshot(app.state.drive_watcher.on_user_change)
|
| 994 |
|
|
|
|
| 995 |
@app.on_event("shutdown")
|
| 996 |
async def shutdown_event():
|
| 997 |
# Close all channels
|
|
|
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
+
# Initialize Google API credentials
|
| 912 |
+
with open('/app/secrets/googleapi_secret.json', 'r') as f:
|
| 913 |
+
google_credentials_info = json.load(f)
|
| 914 |
+
|
| 915 |
+
google_credentials = service_account.Credentials.from_service_account_info(
|
| 916 |
+
google_credentials_info,
|
| 917 |
+
scopes=['https://www.googleapis.com/auth/drive']
|
| 918 |
+
)
|
| 919 |
+
|
| 920 |
+
|
| 921 |
+
|
| 922 |
|
| 923 |
class DriveWatcher:
|
| 924 |
def __init__(self):
|
|
|
|
| 983 |
await self.close_channel(channel_id, channel_info['resourceId'])
|
| 984 |
del self.channels[channel_id]
|
| 985 |
break
|
|
|
|
| 986 |
@app.on_event("startup")
|
| 987 |
async def startup_event():
|
| 988 |
app.state.drive_watcher = DriveWatcher()
|
| 989 |
+
|
| 990 |
+
# Initialize Firestore client with explicit credentials
|
| 991 |
+
app.state.firestore_client = firestore.AsyncClient(
|
| 992 |
+
project=firebase_configuration['project_id'],
|
| 993 |
+
credentials=firebase_credentials
|
| 994 |
+
)
|
| 995 |
+
|
| 996 |
+
# Initialize Drive service with explicit credentials
|
| 997 |
+
app.state.drive_service = build('drive', 'v3', credentials=google_credentials)
|
| 998 |
|
| 999 |
# Fetch all users and initialize the watch list
|
| 1000 |
users_ref = app.state.firestore_client.collection('users')
|
|
|
|
| 1010 |
# Set up the Firebase listener
|
| 1011 |
app.state.users_watch = users_ref.on_snapshot(app.state.drive_watcher.on_user_change)
|
| 1012 |
|
| 1013 |
+
|
| 1014 |
@app.on_event("shutdown")
|
| 1015 |
async def shutdown_event():
|
| 1016 |
# Close all channels
|