""" Static Files Controller Serves static files for widgets and other frontend assets. """ from fastapi import APIRouter from fastapi.responses import FileResponse, HTMLResponse from pathlib import Path import os from src.controllers.base import BaseController from src.logging_config import get_logger logger = get_logger(__name__) class StaticController(BaseController): """ Controller for serving static files Provides endpoints for: - Organizr widgets - Other static assets """ def __init__(self): super().__init__(prefix="/static", tags=["Static"]) self.static_dir = Path(__file__).parent.parent.parent / "static" def create_router(self) -> APIRouter: """Create and configure the router""" router = APIRouter(prefix=self.prefix, tags=self.tags) @router.get( "/widgets/{filename}", response_class=HTMLResponse, summary="Get widget file" ) async def get_widget(filename: str): """ Serve widget HTML files Args: filename: Widget filename (e.g., service-control.html) Returns: HTML file content """ widget_path = self.static_dir / "widgets" / filename if not widget_path.exists(): return HTMLResponse( content=f"
{filename}
", status_code=404 ) if not widget_path.is_file(): return HTMLResponse( content=f"