From 6352eea892f9cdab53aa2de968c7dae0b7c82aba Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 09:30:55 +0100 Subject: [PATCH] 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 --- cdn-api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cdn-api.py b/cdn-api.py index 6d0a3e2..a9a2fba 100644 --- a/cdn-api.py +++ b/cdn-api.py @@ -49,6 +49,15 @@ def get_media_type(format: Format) -> str: } 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("/") async def root(): """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: # 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(): logger.error(f"File not found: {file_path}") logger.info(f"Looking for {layout.slug} in format {image_format}")