Files
minerops/backend/app/system_health/frontend.py

36 lines
1.3 KiB
Python

"""Authenticated frontend routes for System Health."""
from pathlib import Path
from typing import Annotated
from fastapi import APIRouter, Depends
from fastapi.responses import HTMLResponse, Response
from app.frontend.views import render_app_page
from app.identity import require_permission, user_has_permission
router = APIRouter(tags=["frontend"])
STATIC_ROOT = Path(__file__).parents[1] / "frontend" / "static"
SystemHealthUser = Annotated[dict, Depends(require_permission("system_health.view"))]
@router.get("/assets/minerops-system-health.css", include_in_schema=False)
def system_health_styles() -> Response:
return Response((STATIC_ROOT / "system-health.css").read_text(encoding="utf-8"),
media_type="text/css", headers={"Cache-Control": "no-store"})
@router.get("/assets/minerops-system-health.js", include_in_schema=False)
def system_health_script() -> Response:
return Response((STATIC_ROOT / "system-health.js").read_text(encoding="utf-8"),
media_type="text/javascript", headers={"Cache-Control": "no-store"})
@router.get("/system-health", response_class=HTMLResponse, include_in_schema=False)
def system_health_page(current_user: SystemHealthUser) -> str:
return render_app_page(
"system_health", current_user,
lambda permission: user_has_permission(current_user, permission),
)