- Add Free_Proxy_Website-style fpw_* plugins and register them - Per-plugin crawl timeout (crawl_timeout_seconds=120); remove global crawl_timeout setting - Validator: fix connect vs total timeout on save; SOCKS session LRU cache; drop redundant semaphore - Validation handler uses single DB connection; batch upsert after crawl; WorkerPool put_nowait - Remove unused max_retries from settings API/UI; settings maintenance SQL + init_db cleanup of deprecated keys - WebSocket dashboard stats; ProxyList pool_filter and API alignment - POST /api/proxies/delete-one for IPv6-safe deletes; task poll stops on 404 - pytest uses PROXYPOOL_DB_PATH=db/proxies.test.sqlite so tests do not wipe production DB - .gitignore: explicit proxies.test.sqlite patterns; fix plugin_service ValidationException import Made-with: Cursor
33 lines
1000 B
Python
33 lines
1000 B
Python
"""WebSocket 实时推送"""
|
|
import json
|
|
|
|
from fastapi import APIRouter, WebSocket
|
|
from starlette.websockets import WebSocketDisconnect
|
|
|
|
from app.services.dashboard_stats import get_dashboard_stats
|
|
|
|
router = APIRouter(prefix="/api", tags=["websocket"])
|
|
|
|
|
|
@router.websocket("/ws")
|
|
async def websocket_dashboard(websocket: WebSocket):
|
|
app = websocket.app
|
|
await websocket.accept()
|
|
manager = app.state.ws_manager
|
|
await manager.connect(websocket)
|
|
try:
|
|
stats = await get_dashboard_stats(app.state.scheduler.running)
|
|
await websocket.send_json({"type": "stats", "data": stats})
|
|
while True:
|
|
raw = await websocket.receive_text()
|
|
try:
|
|
msg = json.loads(raw)
|
|
except json.JSONDecodeError:
|
|
continue
|
|
if msg.get("type") == "ping":
|
|
await websocket.send_json({"type": "pong"})
|
|
except WebSocketDisconnect:
|
|
pass
|
|
finally:
|
|
await manager.disconnect(websocket)
|