Serve each track format's own file

/png and /geojson answered the SVG file under a PNG or GeoJSON media
type, so the GPS-traced GeoJSON of a layout was never served at all.
Each format now serves its own file; a layout without one answers 404.

Claude-Session: https://claude.ai/code/session_01NcbgfJAa38xFpzy69BWrqh
This commit is contained in:
2026-11-27 09:40:28 +01:00
parent 11c17cb9ad
commit 6352eea892
+10 -1
View File
@@ -49,6 +49,15 @@ def get_media_type(format: Format) -> str:
} }
return media_types.get(format, "application/octet-stream") # fallback for unknown formats return media_types.get(format, "application/octet-stream") # fallback for unknown formats
def get_relative_filepath(layout: TrackLayout, format: Format) -> Path:
# Each format serves its own file: the PNG, the SVG, or the GPS-traced GeoJSON
relative_filepaths = {
Format.PNG: layout.relative_png_filepath,
Format.SVG: layout.relative_svg_filepath,
Format.GEOJSON: layout.relative_geojson_filepath,
}
return relative_filepaths[format]
@app.get("/") @app.get("/")
async def root(): async def root():
"""Root endpoint returning API information""" """Root endpoint returning API information"""
@@ -227,7 +236,7 @@ async def get_grand_prix_circuit(grand_prix_name: str, season: int, image_format
def get_file_response(layout: TrackLayout, image_format: Format, response: Response) -> FileResponse: def get_file_response(layout: TrackLayout, image_format: Format, response: Response) -> FileResponse:
# layout = circuit_service.get_layout_details(country_slug, city_slug, circuit_slug, layout_slug) # layout = circuit_service.get_layout_details(country_slug, city_slug, circuit_slug, layout_slug)
file_path = Path(f"./circuits").joinpath(layout.relative_svg_filepath) file_path = Path(f"./circuits").joinpath(get_relative_filepath(layout, image_format))
if not file_path or not file_path.exists(): if not file_path or not file_path.exists():
logger.error(f"File not found: {file_path}") logger.error(f"File not found: {file_path}")
logger.info(f"Looking for {layout.slug} in format {image_format}") logger.info(f"Looking for {layout.slug} in format {image_format}")