"""Prism Console Static File Serving Router"""
from fastapi import APIRouter
from fastapi.responses import FileResponse, HTMLResponse
from pathlib import Path
router = APIRouter(tags=["prism"])
# Get the static prism directory path
STATIC_DIR = Path(__file__).parent.parent.parent / "static"
PRISM_DIR = STATIC_DIR / "prism"
@router.get("/prism", response_class=HTMLResponse)
async def serve_prism_console():
"""
Serve the Prism Console UI entry point
Prism Console is the administrative interface for BlackRoad OS,
providing job queue management, event logging, and system metrics.
"""
prism_index = PRISM_DIR / "index.html"
if not prism_index.exists():
# Fallback: serve a placeholder page
return HTMLResponse(content="""
Prism Console - Coming Soon
🌌
Prism Console
The Administrative Interface for BlackRoad OS
Coming soon in Phase 2...
← Back to OS
""", status_code=200)
# Serve the actual Prism Console index.html
return FileResponse(prism_index)
@router.get("/prism/health")
async def prism_health():
"""Health endpoint for Prism Console assets."""
return {
"service": "prism-console",
"status": "healthy",
}
@router.get("/prism/{file_path:path}")
async def serve_prism_static_files(file_path: str):
"""
Serve static files for Prism Console (JS, CSS, images, etc.)
This endpoint handles all asset requests for the Prism Console UI.
"""
# Security: Prevent directory traversal
requested_file = PRISM_DIR / file_path
# Ensure the requested file is within the prism directory
try:
resolved = requested_file.resolve()
if not str(resolved).startswith(str(PRISM_DIR.resolve())):
return HTMLResponse(content="Access denied", status_code=403)
except Exception:
return HTMLResponse(content="File not found", status_code=404)
if not requested_file.exists() or not requested_file.is_file():
return HTMLResponse(content="File not found", status_code=404)
# Serve the file with appropriate MIME type
return FileResponse(requested_file)