From 307f1fbbc11845c84f59174aa442bbfbe4a284e2 Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Fri, 15 May 2026 18:38:53 +0200 Subject: [PATCH] download bas: embed timeseries into the JSON so the file is self-contained --- bincio/serve/routers/download.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bincio/serve/routers/download.py b/bincio/serve/routers/download.py index 04f1f0c..bac95ab 100644 --- a/bincio/serve/routers/download.py +++ b/bincio/serve/routers/download.py @@ -114,10 +114,27 @@ async def download_activity( _check_download_permission(detail, handle, bincio_session) if fmt == "bas": - return FileResponse( - detail_path, + # Embed the timeseries so the downloaded file is self-contained. + ts_path: Path | None = None + data_dir = deps._get_data_dir() + for base in ( + data_dir / handle / "_merged" / "activities", + data_dir / handle / "activities", + ): + p = base / f"{activity_id}.timeseries.json" + if p.exists(): + ts_path = p + break + if ts_path: + try: + detail["timeseries"] = json.loads(ts_path.read_text(encoding="utf-8")) + detail.pop("timeseries_url", None) + except (OSError, json.JSONDecodeError): + pass + content = json.dumps(detail, ensure_ascii=False, indent=2) + return Response( + content=content, media_type="application/json", - filename=f"{activity_id}.json", headers={"Content-Disposition": f'attachment; filename="{activity_id}.json"'}, )