50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
from typing import Any
|
|
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
from app import journal
|
|
from app.render import render
|
|
|
|
router = APIRouter(prefix="/api", tags=["journal"])
|
|
|
|
|
|
@router.get("/journal")
|
|
async def journal_view(
|
|
_request: Request,
|
|
level: str = "all",
|
|
unit: str = "",
|
|
search: str = "",
|
|
cursor: str = "",
|
|
hide_sudo: str = "",
|
|
):
|
|
if level not in journal.LEVELS:
|
|
level = "all"
|
|
lines = 200 if cursor else 100
|
|
error = None
|
|
entries: list[dict[str, Any]] = []
|
|
next_cursor = ""
|
|
try:
|
|
entries, nc = await journal.tail(
|
|
cursor or None,
|
|
level,
|
|
unit or None,
|
|
search or None,
|
|
lines,
|
|
hide_sudo=(hide_sudo == "on"),
|
|
)
|
|
next_cursor = nc or ""
|
|
entries = entries[-400:]
|
|
except (RuntimeError, OSError) as e:
|
|
error = str(e)[:300]
|
|
return HTMLResponse(
|
|
render(
|
|
"journal.html",
|
|
entries=entries,
|
|
next_cursor=next_cursor,
|
|
level=level,
|
|
unit=unit,
|
|
search=search,
|
|
error=error,
|
|
)
|
|
)
|