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
32 lines
861 B
Python
32 lines
861 B
Python
import hashlib
|
|
from fastapi import APIRouter, HTTPException, Depends
|
|
from fastapi.responses import JSONResponse
|
|
from config import settings
|
|
|
|
router = APIRouter(prefix="/api/auth", tags=["auth"])
|
|
|
|
_tokens: set[str] = set()
|
|
|
|
|
|
def hash_password(pw: str) -> str:
|
|
return hashlib.sha256(f"{pw}:livestream-salt".encode()).hexdigest()
|
|
|
|
|
|
ADMIN_HASH = hash_password(settings.admin_password)
|
|
|
|
|
|
@router.post("/login")
|
|
async def login(password: str):
|
|
if hash_password(password) != ADMIN_HASH:
|
|
raise HTTPException(status_code=401, detail="Invalid password")
|
|
token = hashlib.sha256(f"{password}:token".encode()).hexdigest()
|
|
_tokens.add(token)
|
|
return {"token": token}
|
|
|
|
|
|
@router.post("/verify")
|
|
async def verify(token: str):
|
|
if token not in _tokens:
|
|
raise HTTPException(status_code=401, detail="Invalid token")
|
|
return {"valid": True}
|