planning
This commit is contained in:
@@ -607,6 +607,61 @@ async def upload_activity(file: UploadFile = File(...)) -> JSONResponse:
|
||||
return JSONResponse({"ok": True, "id": activity_id})
|
||||
|
||||
|
||||
@app.post("/api/import-bas")
|
||||
async def import_bas(payload: dict[str, Any]) -> JSONResponse:
|
||||
"""Accept a pre-converted BAS detail JSON (from the /convert/ page) and save it."""
|
||||
dd = _get_data_dir()
|
||||
detail = payload.get("detail")
|
||||
geojson = payload.get("geojson")
|
||||
|
||||
if not isinstance(detail, dict) or not detail.get("id"):
|
||||
raise HTTPException(400, "Missing or invalid 'detail' field")
|
||||
|
||||
activity_id = detail["id"]
|
||||
_check_id(activity_id)
|
||||
|
||||
acts_dir = dd / "activities"
|
||||
acts_dir.mkdir(exist_ok=True)
|
||||
|
||||
dest = acts_dir / f"{activity_id}.json"
|
||||
if dest.exists():
|
||||
raise HTTPException(409, f"Activity already exists: {activity_id}")
|
||||
|
||||
dest.write_text(json.dumps(detail, indent=2, ensure_ascii=False))
|
||||
|
||||
if geojson:
|
||||
(acts_dir / f"{activity_id}.geojson").write_text(
|
||||
json.dumps(geojson, indent=2, ensure_ascii=False)
|
||||
)
|
||||
|
||||
# Rebuild index
|
||||
index_path = dd / "index.json"
|
||||
if index_path.exists():
|
||||
index_data = json.loads(index_path.read_text(encoding="utf-8"))
|
||||
else:
|
||||
index_data = {"owner": {"handle": "unknown"}, "activities": []}
|
||||
owner = index_data.get("owner", {})
|
||||
existing = {s["id"]: s for s in index_data.get("activities", [])}
|
||||
|
||||
# Build a minimal summary from the detail
|
||||
summary_keys = [
|
||||
"id", "title", "sport", "sub_sport", "started_at", "distance_m",
|
||||
"duration_s", "moving_time_s", "elevation_gain_m", "avg_speed_kmh",
|
||||
"avg_hr_bpm", "avg_cadence_rpm", "avg_power_w", "privacy",
|
||||
"detail_url", "track_url", "preview_coords", "highlight", "duplicate_of",
|
||||
]
|
||||
summary = {k: detail[k] for k in summary_keys if k in detail}
|
||||
existing[activity_id] = summary
|
||||
|
||||
from bincio.extract.writer import write_index
|
||||
write_index(list(existing.values()), dd, owner)
|
||||
|
||||
from bincio.render.merge import merge_all
|
||||
merge_all(dd)
|
||||
|
||||
return JSONResponse({"ok": True, "id": activity_id})
|
||||
|
||||
|
||||
@app.delete("/api/activity/{activity_id}/images/{filename}")
|
||||
async def delete_image(activity_id: str, filename: str) -> JSONResponse:
|
||||
dd = _get_data_dir()
|
||||
|
||||
Reference in New Issue
Block a user