mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-25 23:21:21 +01:00
this logically groups api endpoints and gioves them specific openapi tags. which makes them nice on the `/docs` endpoint and makes the `api.py` more approachable * add wallets list endpoint * remove trailing slashes from endpoints * fixup topup url * fix trailing slash on auth * backwards compatibility
40 lines
1 KiB
Python
40 lines
1 KiB
Python
from fastapi import (
|
|
APIRouter,
|
|
WebSocket,
|
|
WebSocketDisconnect,
|
|
)
|
|
|
|
from ..services import (
|
|
websocketManager,
|
|
websocketUpdater,
|
|
)
|
|
|
|
websocket_router = APIRouter(prefix="/api/v1/ws", tags=["Websocket"])
|
|
|
|
|
|
@websocket_router.websocket("/{item_id}")
|
|
async def websocket_connect(websocket: WebSocket, item_id: str):
|
|
await websocketManager.connect(websocket, item_id)
|
|
try:
|
|
while True:
|
|
await websocket.receive_text()
|
|
except WebSocketDisconnect:
|
|
websocketManager.disconnect(websocket)
|
|
|
|
|
|
@websocket_router.post("/{item_id}")
|
|
async def websocket_update_post(item_id: str, data: str):
|
|
try:
|
|
await websocketUpdater(item_id, data)
|
|
return {"sent": True, "data": data}
|
|
except Exception:
|
|
return {"sent": False, "data": data}
|
|
|
|
|
|
@websocket_router.get("/{item_id}/{data}")
|
|
async def websocket_update_get(item_id: str, data: str):
|
|
try:
|
|
await websocketUpdater(item_id, data)
|
|
return {"sent": True, "data": data}
|
|
except Exception:
|
|
return {"sent": False, "data": data}
|