Skip to content

Commit 663639a

Browse files
authored
feat: add web UI components and frontend functionality (#95)
1 parent 0270c0d commit 663639a

File tree

3 files changed

+204
-380
lines changed

3 files changed

+204
-380
lines changed

byte_bot/server/domain/web/controllers/web.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
from __future__ import annotations
44

5+
from typing import TYPE_CHECKING
6+
57
from litestar import Controller, get
68
from litestar.response import Template
79
from litestar.status_codes import HTTP_200_OK
810

911
from byte_bot.server.domain import urls
12+
from byte_bot.server.domain.guilds.helpers import get_byte_server_count
13+
from byte_bot.server.domain.system.helpers import check_byte_status, check_database_status
14+
15+
if TYPE_CHECKING:
16+
from sqlalchemy.ext.asyncio import AsyncSession
1017

11-
__all__ = ["WebController"]
18+
__all__ = ("WebController",)
1219

1320

1421
class WebController(Controller):
@@ -24,9 +31,23 @@ class WebController(Controller):
2431
include_in_schema=False,
2532
opt={"exclude_from_auth": True},
2633
)
27-
async def index(self) -> Template:
34+
async def index(self, db_session: AsyncSession) -> Template:
2835
"""Serve site root."""
29-
return Template(template_name="index.html")
36+
server_count = await get_byte_server_count()
37+
byte_status = await check_byte_status()
38+
database_status = await check_database_status(db_session)
39+
statuses = [database_status, byte_status]
40+
41+
if all(status == "offline" for status in statuses):
42+
overall_status = "offline"
43+
elif "offline" in statuses or "degraded" in statuses:
44+
overall_status = "degraded"
45+
else:
46+
overall_status = "healthy"
47+
48+
return Template(
49+
template_name="index.html", context={"server_count": server_count, "overall_status": overall_status}
50+
)
3051

3152
# add dashboard
3253
@get(

0 commit comments

Comments
 (0)