Spaces:
Sleeping
Sleeping
slpk layer testing 1.1
Browse files
app.py
CHANGED
|
@@ -428,6 +428,35 @@ async def generate_i3s(request: GenerateI3SRequest):
|
|
| 428 |
traceback.print_exc()
|
| 429 |
raise HTTPException(status_code=500, detail=str(e))
|
| 430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
@app.get("/")
|
| 432 |
async def root():
|
| 433 |
return {"message": "CityPyPRT 3D Generation API"}
|
|
|
|
| 428 |
traceback.print_exc()
|
| 429 |
raise HTTPException(status_code=500, detail=str(e))
|
| 430 |
|
| 431 |
+
@app.middleware("http")
|
| 432 |
+
async def i3s_json_middleware(request: Request, call_next):
|
| 433 |
+
# Check for ArcGIS-style query param f=pjson or f=json
|
| 434 |
+
if request.query_params.get("f") in ["json", "pjson"]:
|
| 435 |
+
# Allow normal processing first? No, static files don't handle query params usually
|
| 436 |
+
# We check if the path corresponds to a directory with 3dSceneLayer.json
|
| 437 |
+
|
| 438 |
+
# Construct local path from URL path
|
| 439 |
+
# URL path: /layers/<uuid>/SceneLayer
|
| 440 |
+
# Local path: .../static/layers/<uuid>/SceneLayer
|
| 441 |
+
|
| 442 |
+
path = request.url.path
|
| 443 |
+
if path.startswith("/layers"):
|
| 444 |
+
rel_path = path[len("/layers"):] # e.g. /<uuid>/SceneLayer
|
| 445 |
+
if rel_path.startswith("/"): rel_path = rel_path[1:]
|
| 446 |
+
|
| 447 |
+
local_path = os.path.join(LAYERS_DIR, rel_path.replace("/", os.sep))
|
| 448 |
+
|
| 449 |
+
# If request is for a directory (or valid path that is a dir)
|
| 450 |
+
if os.path.exists(local_path) and os.path.isdir(local_path):
|
| 451 |
+
json_path = os.path.join(local_path, "3dSceneLayer.json")
|
| 452 |
+
if os.path.exists(json_path):
|
| 453 |
+
logger.info(f"Intercepting f=pjson for {path}, serving 3dSceneLayer.json")
|
| 454 |
+
from fastapi.responses import FileResponse
|
| 455 |
+
return FileResponse(json_path, media_type="application/json")
|
| 456 |
+
|
| 457 |
+
response = await call_next(request)
|
| 458 |
+
return response
|
| 459 |
+
|
| 460 |
@app.get("/")
|
| 461 |
async def root():
|
| 462 |
return {"message": "CityPyPRT 3D Generation API"}
|