Skip to content

Commit

Permalink
better config options
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Aug 30, 2024
1 parent 6229d5a commit e9208bf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
24 changes: 23 additions & 1 deletion frontend/src/gen/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,17 @@ export interface components {
/** Api Key */
api_key: string;
};
/** Body_pull_onshape_document_onshape_pull__listing_id__get */
Body_pull_onshape_document_onshape_pull__listing_id__get: {
/** Suffix To Joint Effort */
suffix_to_joint_effort?: {
[key: string]: number;
} | null;
/** Suffix To Joint Velocity */
suffix_to_joint_velocity?: {
[key: string]: number;
} | null;
};
/** Body_upload_artifacts_upload__listing_id__post */
Body_upload_artifacts_upload__listing_id__post: {
/** Files */
Expand Down Expand Up @@ -1892,14 +1903,25 @@ export interface operations {
parameters: {
query?: {
token?: string | null;
default_prismatic_joint_effort?: number;
default_prismatic_joint_velocity?: number;
default_revolute_joint_effort?: number;
default_revolute_joint_velocity?: number;
voxel_size?: number;
convex_collision_meshes?: boolean;
add_mjcf?: boolean;
};
header?: never;
path: {
listing_id: string;
};
cookie?: never;
};
requestBody?: never;
requestBody?: {
content: {
"application/json": components["schemas"]["Body_pull_onshape_document_onshape_pull__listing_id__get"];
};
};
responses: {
/** @description Successful Response */
200: {
Expand Down
30 changes: 25 additions & 5 deletions store/app/routers/onshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from fastapi import APIRouter, Depends, HTTPException, Request, status
from fastapi.responses import StreamingResponse
from kol.onshape.config import ConverterConfig
from pydantic.main import BaseModel

from store.app.db import Crud
Expand Down Expand Up @@ -40,9 +41,7 @@ async def set_onshape_document(


async def pull_onshape_document_generator(
listing_id: str,
user: User,
crud: Crud,
listing_id: str, user: User, crud: Crud, *, config: ConverterConfig | None = None
) -> AsyncIterable[str]:
# Gets the listing and makes sure the user has permission to write to it.
listing = await crud.get_listing(listing_id)
Expand All @@ -53,7 +52,7 @@ async def pull_onshape_document_generator(
if not await can_write_listing(user, listing):
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="User cannot write to this listing")
yield f"event: message\ndata: {json.dumps({'message': 'Starting download', 'level': 'success'})}\n\n"
async for event in crud.download_onshape_document(listing, onshape_url):
async for event in crud.download_onshape_document(listing, onshape_url, config=config):
yield event
yield "event: finish\ndata: finish\n\n"

Expand All @@ -64,6 +63,15 @@ async def pull_onshape_document(
request: Request,
crud: Annotated[Crud, Depends(Crud.get)],
token: str | None = None,
default_prismatic_joint_effort: float = 80.0,
default_prismatic_joint_velocity: float = 5.0,
default_revolute_joint_effort: float = 80.0,
default_revolute_joint_velocity: float = 5.0,
suffix_to_joint_effort: dict[str, float] | None = None,
suffix_to_joint_velocity: dict[str, float] | None = None,
voxel_size: float = 0.002,
convex_collision_meshes: bool = False,
add_mjcf: bool = True,
) -> StreamingResponse:
# Because the default EventStream implementation doesn't provide an easy
# way to pass the token in the header, we have to pass it as a query
Expand All @@ -77,7 +85,19 @@ async def pull_onshape_document(
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Permission denied")
user = await crud.get_user(api_key.user_id, throw_if_missing=True)

config = ConverterConfig(
default_prismatic_joint_effort=default_prismatic_joint_effort,
default_prismatic_joint_velocity=default_prismatic_joint_velocity,
default_revolute_joint_effort=default_revolute_joint_effort,
default_revolute_joint_velocity=default_revolute_joint_velocity,
suffix_to_joint_effort=suffix_to_joint_effort or {},
suffix_to_joint_velocity=suffix_to_joint_velocity or {},
voxel_size=voxel_size,
convex_collision_meshes=convex_collision_meshes,
add_mjcf=add_mjcf,
)

return StreamingResponse(
content=pull_onshape_document_generator(listing_id, user, crud),
content=pull_onshape_document_generator(listing_id, user, crud, config=config),
media_type="text/event-stream",
)

0 comments on commit e9208bf

Please sign in to comment.