mirror of
https://github.com/trycua/computer.git
synced 2025-12-31 02:19:58 -06:00
Added sync command support
This commit is contained in:
@@ -233,7 +233,11 @@ async def websocket_endpoint(websocket: WebSocket):
|
||||
sig = inspect.signature(handler_func)
|
||||
filtered_params = {k: v for k, v in params.items() if k in sig.parameters}
|
||||
|
||||
result = await handler_func(**filtered_params)
|
||||
# Handle both sync and async functions
|
||||
if asyncio.iscoroutinefunction(handler_func):
|
||||
result = await handler_func(**filtered_params)
|
||||
else:
|
||||
result = handler_func(**filtered_params)
|
||||
await websocket.send_json({"success": True, **result})
|
||||
except Exception as cmd_error:
|
||||
logger.error(f"Error executing command {command}: {str(cmd_error)}")
|
||||
@@ -356,8 +360,11 @@ async def cmd_endpoint(
|
||||
sig = inspect.signature(handler_func)
|
||||
filtered_params = {k: v for k, v in params.items() if k in sig.parameters}
|
||||
|
||||
# Execute the command
|
||||
result = await handler_func(**filtered_params)
|
||||
# Handle both sync and async functions
|
||||
if asyncio.iscoroutinefunction(handler_func):
|
||||
result = await handler_func(**filtered_params)
|
||||
else:
|
||||
result = handler_func(**filtered_params)
|
||||
|
||||
# Stream the successful result
|
||||
response_data = {"success": True, **result}
|
||||
|
||||
Reference in New Issue
Block a user