From 3a8249f2e8e119b0d6912692e86c53a5f1296547 Mon Sep 17 00:00:00 2001 From: pollutri Date: Tue, 17 Feb 2026 18:02:33 +0100 Subject: [PATCH] Download maps API --- .env | 1 + app.py | 32 ++++++++++++++++++++++++++++++++ config_env.py | 5 +++++ 3 files changed, 38 insertions(+) diff --git a/.env b/.env index 517b365..8274019 100644 --- a/.env +++ b/.env @@ -17,3 +17,4 @@ KEYCLOAK_TOKEN_URL=${KEYCLOAK_PROTOCOL_ENDPOINT}/token #BLE AI infer CSV BLE_AI_INFER_CSV=/data/service/ble-ai-localizer/data/infer/infer.csv BLE_AI_META_DIR=/data/service/ble-ai-localizer/data/maps/ +BLE_AI_MAPS_DIR=/data/service/ble-ai-localizer/data/maps diff --git a/app.py b/app.py index 5420233..9e0e557 100644 --- a/app.py +++ b/app.py @@ -297,6 +297,38 @@ async def get_ble_ai_metadata(floor: Optional[int] = Query(default=None)): return {"items": items, "count": len(items)} +@app.get("/ble-ai/maps", tags=["BLE-AI"], dependencies=[Depends(get_current_user)]) +async def get_ble_ai_maps(): + maps_dir = config_env.BLE_AI_MAPS_DIR + if not os.path.isdir(maps_dir): + raise HTTPException(status_code=404, detail="Maps directory not found") + + items = [] + for file_name in sorted(os.listdir(maps_dir), key=str.lower): + if not file_name.lower().endswith(".png"): + continue + + file_path = os.path.join(maps_dir, file_name) + if not os.path.isfile(file_path): + continue + + with open(file_path, "rb") as f: + encoded = base64.b64encode(f.read()).decode("ascii") + + items.append( + { + "name": file_name, + "mime_type": "image/png", + "content_base64": encoded, + } + ) + + if not items: + raise HTTPException(status_code=404, detail="No PNG maps found") + + return {"items": items, "count": len(items)} + + @app.get("/openapi.json/", tags=["Documentation"]) async def get_open_api_endpoint(): #async def get_open_api_endpoint(current_user: User = Depends(get_current_active_user)): diff --git a/config_env.py b/config_env.py index 9d97817..e863c69 100644 --- a/config_env.py +++ b/config_env.py @@ -32,3 +32,8 @@ BLE_AI_META_DIR = os.getenv( "/data/service/ble-ai-localizer/data/maps/", ) +BLE_AI_MAPS_DIR = os.getenv( + "BLE_AI_MAPS_DIR", + "/data/service/ble-ai-localizer/data/maps", +) +