download bas: embed timeseries into the JSON so the file is self-contained
This commit is contained in:
@@ -114,10 +114,27 @@ async def download_activity(
|
|||||||
_check_download_permission(detail, handle, bincio_session)
|
_check_download_permission(detail, handle, bincio_session)
|
||||||
|
|
||||||
if fmt == "bas":
|
if fmt == "bas":
|
||||||
return FileResponse(
|
# Embed the timeseries so the downloaded file is self-contained.
|
||||||
detail_path,
|
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",
|
media_type="application/json",
|
||||||
filename=f"{activity_id}.json",
|
|
||||||
headers={"Content-Disposition": f'attachment; filename="{activity_id}.json"'},
|
headers={"Content-Disposition": f'attachment; filename="{activity_id}.json"'},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user