Initial commit - Trekker V2 source

This commit is contained in:
Cortex committed 2026-06-10 11:03:37 -04:00
commit d71faf19e3
65 files changed
+3615

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
"""Export API: enriched GPX / KML downloads."""
from __future__ import annotations
import re
from fastapi import APIRouter, HTTPException, Query
from fastapi.responses import Response
from app.deps import get_store
from app.export.gpx_writer import write_gpx
from app.export.kml_writer import write_kml
router = APIRouter(prefix="/api/routes", tags=["export"])
@router.get("/{route_id}/export")
def export_route(route_id: str, format: str = Query("gpx", pattern="^(gpx|kml)$")):
store = get_store()
route = store.get_route(route_id)
if route is None:
raise HTTPException(404, "route not found")
guide = store.get_trail_guide(route.trail_guide_id) if route.trail_guide_id else None
safe_name = re.sub(r"[^A-Za-z0-9_-]+", "_", route.name).strip("_") or "route"
if format == "gpx":
body, media = write_gpx(route, guide), "application/gpx+xml"
else:
body, media = write_kml(route, guide), "application/vnd.google-earth.kml+xml"
return Response(
content=body, media_type=media,
headers={"Content-Disposition": f'attachment; filename="{safe_name}.{format}"'},
)