download bas: embed timeseries into the JSON so the file is self-contained

This commit is contained in:
Davide Scaini
2026-05-15 18:38:53 +02:00
parent c465e518e5
commit 307f1fbbc1
+20 -3
View File
@@ -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"'},
)