dashboard/app/routers/plugins.py

27 lines
841 B
Python

from fastapi import APIRouter
from fastapi.responses import HTMLResponse
from app.plugins import PLUGINS, Plugin
from app.render import render
router = APIRouter(prefix="/api/plugins", tags=["plugins"])
@router.get("")
async def plugins_index():
"""Render the Plugins tab: a skeleton fragment for every registered plugin.
A plugin whose skeleton() raises gets an inline error card instead of
taking down the whole page.
Returns:
The rendered plugins.html as an HTMLResponse.
"""
items: list[dict[str, Plugin | str]] = []
for p in PLUGINS:
try:
body = await p.skeleton()
except Exception as e: # noqa
body = f"<div class='alert'>plugin error: {e}</div>"
items.append({"p": p, "body": body})
return HTMLResponse(render("plugins.html", items=items))