fix strava import?
This commit is contained in:
+32
-1
@@ -18,7 +18,7 @@ from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
|
||||
from fastapi import Cookie, FastAPI, File, Form, HTTPException, Request, Response, UploadFile
|
||||
from fastapi.responses import RedirectResponse
|
||||
from fastapi.responses import RedirectResponse, StreamingResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.middleware.gzip import GZipMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
@@ -712,6 +712,37 @@ async def strava_callback(
|
||||
return RedirectResponse(f"{site_origin}/?strava=connected")
|
||||
|
||||
|
||||
@app.get("/api/strava/sync/stream")
|
||||
async def serve_strava_sync_stream(bincio_session: Optional[str] = Cookie(default=None)) -> StreamingResponse:
|
||||
"""SSE endpoint — streams per-activity progress then a final summary event."""
|
||||
user = _require_user(bincio_session)
|
||||
if not strava_client_id or not strava_client_secret:
|
||||
raise HTTPException(400, "Strava not configured on this server")
|
||||
dd = _get_data_dir() / user.handle
|
||||
store_orig_setting = get_setting(_get_db(), "store_originals")
|
||||
store_orig = store_orig_setting == "true"
|
||||
originals_dir = (dd / "originals" / "strava") if store_orig else None
|
||||
if originals_dir:
|
||||
originals_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
from bincio.extract.ingest import strava_sync_iter
|
||||
|
||||
def event_stream():
|
||||
try:
|
||||
for event in strava_sync_iter(dd, strava_client_id, strava_client_secret, originals_dir):
|
||||
yield f"data: {json.dumps(event)}\n\n"
|
||||
if event["type"] == "done":
|
||||
_trigger_rebuild(user.handle)
|
||||
except Exception as exc:
|
||||
yield f"data: {json.dumps({'type': 'error', 'message': str(exc)})}\n\n"
|
||||
|
||||
return StreamingResponse(
|
||||
event_stream(),
|
||||
media_type="text/event-stream",
|
||||
headers={"Cache-Control": "no-cache", "X-Accel-Buffering": "no"},
|
||||
)
|
||||
|
||||
|
||||
@app.post("/api/strava/sync")
|
||||
async def serve_strava_sync(bincio_session: Optional[str] = Cookie(default=None)) -> JSONResponse:
|
||||
user = _require_user(bincio_session)
|
||||
|
||||
Reference in New Issue
Block a user