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}")