Backend: FastAPI + SQLAlchemy + SQLite Frontend: React + Vite + Ant Design (serif Anthropic theme) Media server: MediaMTX with edge node support Load balancing: round-robin / weighted / least-conn Multicast detection with automatic fallback Transcoding support via FFmpeg (configurable quality) hls.js player with line & quality switching Admin panel with password auth Windows compatible scripts
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
from config import settings, Settings
|
|
from services.load_balancer import lb
|
|
from services.multicast_detector import multicast_detector
|
|
|
|
router = APIRouter(prefix="/api/nodes", tags=["nodes"])
|
|
|
|
|
|
class NodeUpdate(BaseModel):
|
|
weight: int
|
|
enabled: bool | None = None
|
|
|
|
|
|
@router.get("")
|
|
async def list_nodes():
|
|
nodes = []
|
|
for n in settings.edge_nodes:
|
|
nodes.append({
|
|
"id": n["id"],
|
|
"name": n["name"],
|
|
"host": n["host"],
|
|
"hls_port": n["hls_port"],
|
|
"api_port": n["api_port"],
|
|
"weight": n["weight"],
|
|
"enabled": n.get("enabled", True),
|
|
})
|
|
return nodes
|
|
|
|
|
|
@router.put("/{node_id}")
|
|
async def update_node(node_id: str, body: NodeUpdate):
|
|
found = False
|
|
for n in settings.edge_nodes:
|
|
if n["id"] == node_id:
|
|
n["weight"] = body.weight
|
|
if body.enabled is not None:
|
|
n["enabled"] = body.enabled
|
|
found = True
|
|
break
|
|
if not found:
|
|
raise HTTPException(status_code=404, detail="Node not found")
|
|
return {"ok": True}
|
|
|
|
|
|
@router.get("/strategy")
|
|
async def get_strategy():
|
|
return {
|
|
"strategy": settings.load_balance_strategy,
|
|
"multicast_enabled": settings.multicast_enabled,
|
|
"multicast_available": multicast_detector.is_available(),
|
|
}
|
|
|
|
|
|
@router.put("/strategy")
|
|
async def update_strategy(strategy: str, multicast_enabled: bool | None = None):
|
|
global settings
|
|
if strategy in ("round-robin", "weighted", "least-conn"):
|
|
settings.load_balance_strategy = strategy
|
|
if multicast_enabled is not None:
|
|
settings.multicast_enabled = multicast_enabled
|
|
return {"ok": True}
|