Spaces:
Running
Running
Download routers/sync.py from iamfebin/algospaced-dsa: direct link, hf CLI and curl.
- Browser
- Download file 860 Bytes
-
https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/routers/sync.py
- Command line
-
hf download hf://spaces/iamfebin/algospaced-dsa/routers/sync.py
-
curl -L -o sync.py https://huggingface.co/spaces/iamfebin/algospaced-dsa/resolve/main/routers/sync.py
860 Bytes
| import asyncio | |
| from fastapi import APIRouter, Depends, HTTPException | |
| import db | |
| import gdrive_sync | |
| from core.auth import Client, get_auth_session | |
| router = APIRouter(tags=["sync"]) | |
| async def trigger_sync(client: Client = Depends(get_auth_session)): | |
| user_id = db.get_current_user_id(client) | |
| if user_id == "sandbox-user-id": | |
| return { | |
| "message": "Google Drive Sync is not available in Sandbox Mode. Please log in to sync your notes." | |
| } | |
| try: | |
| res = await asyncio.to_thread(gdrive_sync.sync_gdrive, client) | |
| return {"message": res} | |
| except Exception as e: | |
| import traceback | |
| err_msg = f"Sync endpoint exception: {str(e)}\n{traceback.format_exc()}" | |
| await asyncio.to_thread(db.log_trace, err_msg) | |
| raise HTTPException(status_code=500, detail=err_msg) | |