2026-03-31 19:19:04 +08:00
|
|
|
"""Dashboard API routers."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
|
|
|
from fastapi import APIRouter
|
2026-03-31 19:19:04 +08:00
|
|
|
from starlette.routing import BaseRoute
|
2025-12-10 20:52:44 +08:00
|
|
|
|
|
|
|
|
from .routes import router as dashboard_router
|
|
|
|
|
|
2026-03-31 19:19:04 +08:00
|
|
|
_RUST_OWNED_DASHBOARD_ROUTE_SIGNATURES = frozenset(
|
|
|
|
|
{
|
|
|
|
|
("GET", "/api/dashboard/stats"),
|
|
|
|
|
("GET", "/api/dashboard/recent-requests"),
|
|
|
|
|
("GET", "/api/dashboard/provider-status"),
|
|
|
|
|
("GET", "/api/dashboard/daily-stats"),
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _route_is_rust_owned(route: BaseRoute) -> bool:
|
|
|
|
|
path = getattr(route, "path", None)
|
|
|
|
|
methods = getattr(route, "methods", None)
|
|
|
|
|
if not isinstance(path, str) or not methods:
|
|
|
|
|
return False
|
|
|
|
|
return any(
|
|
|
|
|
(method, path) in _RUST_OWNED_DASHBOARD_ROUTE_SIGNATURES
|
|
|
|
|
for method in methods
|
|
|
|
|
if method not in {"HEAD", "OPTIONS"}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _build_python_dashboard_router() -> APIRouter:
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
router.include_router(dashboard_router)
|
|
|
|
|
router.routes = [route for route in router.routes if not _route_is_rust_owned(route)]
|
|
|
|
|
return router
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
python_dashboard_router = _build_python_dashboard_router()
|
|
|
|
|
router = python_dashboard_router
|
2025-12-10 20:52:44 +08:00
|
|
|
|
2026-03-31 19:19:04 +08:00
|
|
|
__all__ = ["python_dashboard_router", "router"]
|