mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-04 05:01:37 +02:00
- New APIBrowser component with full OpenAPI schema integration
- Fetches and parses /openapi.json automatically
- Groups endpoints by API tags (printers, archives, settings, etc.)
- Expandable endpoint sections with color-coded method badges
- Path parameter, query parameter, and JSON body editors
- Auto-populates request body with schema examples
- Live API request execution with response display
- Response shows status code, timing, and formatted JSON
- Copy response button with clipboard fallback
- Search to filter endpoints across all categories
- Expand All / Collapse All buttons
- Link to Swagger UI (/docs)
- Two-column layout for API Keys tab
- Left: API key management + webhook documentation
- Right: API Browser with dedicated test key input
- Parameter validation
- Shows warning for missing required parameters
- Validates before sending requests to avoid 422 errors
- UX improvements
- "Use in API Browser" button on newly created keys
- Responsive layout (stacked on mobile, side-by-side on xl+)
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
import logging
|
|
|
|
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
|
|
|
from backend.app.core.websocket import ws_manager
|
|
from backend.app.services.printer_manager import printer_manager, printer_state_to_dict
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter()
|
|
|
|
|
|
@router.websocket("/ws")
|
|
async def websocket_endpoint(websocket: WebSocket):
|
|
"""WebSocket endpoint for real-time updates."""
|
|
logger.info("WebSocket client connecting...")
|
|
await ws_manager.connect(websocket)
|
|
logger.info("WebSocket client connected")
|
|
|
|
try:
|
|
# Send initial status of all printers
|
|
statuses = printer_manager.get_all_statuses()
|
|
for printer_id, state in statuses.items():
|
|
await websocket.send_json(
|
|
{
|
|
"type": "printer_status",
|
|
"printer_id": printer_id,
|
|
"data": printer_state_to_dict(state),
|
|
}
|
|
)
|
|
logger.info(f"Sent initial status for {len(statuses)} printers")
|
|
|
|
# Keep connection alive and handle incoming messages
|
|
while True:
|
|
data = await websocket.receive_json()
|
|
|
|
# Handle ping/pong for keepalive
|
|
if data.get("type") == "ping":
|
|
await websocket.send_json({"type": "pong"})
|
|
|
|
# Handle status request
|
|
elif data.get("type") == "get_status":
|
|
printer_id = data.get("printer_id")
|
|
if printer_id:
|
|
state = printer_manager.get_status(printer_id)
|
|
if state:
|
|
await websocket.send_json(
|
|
{
|
|
"type": "printer_status",
|
|
"printer_id": printer_id,
|
|
"data": printer_state_to_dict(state),
|
|
}
|
|
)
|
|
|
|
except WebSocketDisconnect:
|
|
logger.info("WebSocket client disconnected normally")
|
|
await ws_manager.disconnect(websocket)
|
|
except Exception as e:
|
|
logger.error(f"WebSocket error: {e}", exc_info=True)
|
|
await ws_manager.disconnect(websocket)
|