Imrao commited on
Commit
1b40890
·
1 Parent(s): 17f8425

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -9
app.py CHANGED
@@ -460,19 +460,44 @@ async def i3s_smart_middleware(request: Request, call_next):
460
  # Case B: Nodes (e.g. .../nodes/root or .../nodes/15)
461
  # Expects: .../nodes/root/3dNodeIndexDocument.json
462
  elif "/nodes/" in path:
463
- # If local_path is a directory, look for 3dNodeIndexDocument.json
464
- if os.path.isdir(local_path):
465
- possible_doc = os.path.join(local_path, "3dNodeIndexDocument.json")
466
- if os.path.isfile(possible_doc):
467
- target_file = possible_doc
468
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
469
  # Case C: NodePages (e.g. .../nodepages/0 or .../nodepages/0/)
470
  # Expects: .../nodepages/0.json
471
  elif "/nodepages/" in path:
472
  # Strip trailing slash if present to cleanly append .json
473
- clean_local_path = local_path
474
- if clean_local_path.endswith(os.sep):
475
- clean_local_path = clean_local_path[:-1]
476
 
477
  # Check if adding .json helps
478
  possible_json_page = clean_local_path + ".json"
 
460
  # Case B: Nodes (e.g. .../nodes/root or .../nodes/15)
461
  # Expects: .../nodes/root/3dNodeIndexDocument.json
462
  elif "/nodes/" in path:
463
+ # Handle sub-resources of nodes
464
+ clean_path = local_path.rstrip(os.sep)
465
+
466
+ if "/geometries/" in path:
467
+ # .../geometries/0 -> .../geometries/0.bin
468
+ possible_bin = clean_path + ".bin"
469
+ if os.path.isfile(possible_bin):
470
+ target_file = possible_bin
471
+ media_type="application/octet-stream"
472
+
473
+ elif "/features/" in path:
474
+ # .../features/0 -> .../features/0.json
475
+ possible_json = clean_path + ".json"
476
+ if os.path.isfile(possible_json):
477
+ target_file = possible_json
478
+
479
+ elif "/textures/" in path:
480
+ # Textures are tricky, often .jpg or .bin.dds
481
+ # Just try appending extensions
482
+ for ext in [".jpg", ".png", ".bin.dds", ".dds"]:
483
+ possible_tex = clean_path + ext
484
+ if os.path.isfile(possible_tex):
485
+ target_file = possible_tex
486
+ break
487
+
488
+ else:
489
+ # It is a Node itself (e.g. .../nodes/1)
490
+ # If directory, look for 3dNodeIndexDocument.json
491
+ if os.path.isdir(clean_path):
492
+ possible_doc = os.path.join(clean_path, "3dNodeIndexDocument.json")
493
+ if os.path.isfile(possible_doc):
494
+ target_file = possible_doc
495
+
496
  # Case C: NodePages (e.g. .../nodepages/0 or .../nodepages/0/)
497
  # Expects: .../nodepages/0.json
498
  elif "/nodepages/" in path:
499
  # Strip trailing slash if present to cleanly append .json
500
+ clean_local_path = local_path.rstrip(os.sep)
 
 
501
 
502
  # Check if adding .json helps
503
  possible_json_page = clean_local_path + ".json"