Skip to content

Commit c1ddf9b

Browse files
Merge pull request #320 from pollen-robotics/318-add-route-to-retrieve-the-stl-from-the-api
Add route for stl files.
2 parents a2d24fa + 0300e3d commit c1ddf9b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/reachy_mini/daemon/app/routers/kinematics.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
and other kinematics-related information.
66
"""
77

8+
from pathlib import Path
89
from typing import Any
910

10-
from fastapi import APIRouter, Depends
11+
from fastapi import APIRouter, Depends, HTTPException, Response
1112

1213
from ....daemon.backend.abstract import Backend
1314
from ..dependencies import get_backend
@@ -16,6 +17,14 @@
1617
prefix="/kinematics",
1718
)
1819

20+
STL_ASSETS_DIR = (
21+
Path(__file__).parent.parent.parent.parent
22+
/ "descriptions"
23+
/ "reachy_mini"
24+
/ "urdf"
25+
/ "assets"
26+
)
27+
1928

2029
@router.get("/info")
2130
async def get_kinematics_info(
@@ -34,3 +43,15 @@ async def get_kinematics_info(
3443
async def get_urdf(backend: Backend = Depends(get_backend)) -> dict[str, str]:
3544
"""Get the URDF representation of the robot."""
3645
return {"urdf": backend.get_urdf()}
46+
47+
48+
@router.get("/stl/{filename}")
49+
async def get_stl_file(filename: Path) -> Response:
50+
"""Get the path to an STL asset file."""
51+
file_path = STL_ASSETS_DIR / filename
52+
try:
53+
with open(file_path, "rb") as file:
54+
content = file.read()
55+
return Response(content, media_type="model/stl")
56+
except FileNotFoundError:
57+
raise HTTPException(status_code=404, detail=f"STL file not found {file_path}")

0 commit comments

Comments
 (0)