27 lines
844 B
Python
27 lines
844 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():
|
|
items: list[dict[str, Plugin | str]] = []
|
|
for p in PLUGINS:
|
|
try:
|
|
frag = await p.fragment()
|
|
except Exception as e: # noqa
|
|
frag = f"<div class='alert'>plugin error: {e}</div>"
|
|
items.append({"p": p, "frag": frag})
|
|
return HTMLResponse(render("plugins.html", items=items))
|
|
|
|
|
|
@router.get("/{pid}/fragment")
|
|
async def plugin_fragment(pid: str):
|
|
plugin = next((p for p in PLUGINS if p.id == pid), None)
|
|
if plugin is None:
|
|
return HTMLResponse("unknown plugin", status_code=404)
|
|
return HTMLResponse(await plugin.fragment())
|