This commit is contained in:
@@ -18,13 +18,17 @@ router = APIRouter()
|
||||
|
||||
class ClickInteraction(BaseModel):
|
||||
action: Literal["click"]
|
||||
selector: str
|
||||
selector: Optional[str] = None
|
||||
x: Optional[int] = None
|
||||
y: Optional[int] = None
|
||||
|
||||
|
||||
class TypeInteraction(BaseModel):
|
||||
action: Literal["type"]
|
||||
selector: str
|
||||
selector: Optional[str] = None
|
||||
text: str
|
||||
x: Optional[int] = None
|
||||
y: Optional[int] = None
|
||||
|
||||
|
||||
Interaction = Annotated[
|
||||
@@ -33,9 +37,17 @@ Interaction = Annotated[
|
||||
]
|
||||
|
||||
|
||||
class Viewport(BaseModel):
|
||||
width: int
|
||||
height: int
|
||||
|
||||
|
||||
class InteractionsRequest(BaseModel):
|
||||
url: str
|
||||
returnType: Optional[Literal["screenshot", "html"]] = "screenshot"
|
||||
viewport: Optional[Viewport] = None
|
||||
scrollX: Optional[int] = None
|
||||
scrollY: Optional[int] = None
|
||||
interactions: List[Interaction]
|
||||
|
||||
@router.get("/")
|
||||
@@ -99,7 +111,14 @@ async def run_interactions(payload: InteractionsRequest, x_api_key: Optional[str
|
||||
return_type = (payload.returnType or "screenshot").lower()
|
||||
|
||||
try:
|
||||
result = await interactions_service(decoded_url, payload.interactions, return_type)
|
||||
result = await interactions_service(
|
||||
decoded_url,
|
||||
payload.interactions,
|
||||
return_type,
|
||||
viewport=payload.viewport,
|
||||
scroll_x=payload.scrollX,
|
||||
scroll_y=payload.scrollY,
|
||||
)
|
||||
|
||||
if isinstance(result, dict) and result.get("status") == "error":
|
||||
raise HTTPException(status_code=500, detail=result.get("error", "Interaction failed"))
|
||||
|
||||
Reference in New Issue
Block a user