22
33from __future__ import annotations
44
5+ from typing import TYPE_CHECKING
6+
57from litestar import Controller , get
68from litestar .response import Template
79from litestar .status_codes import HTTP_200_OK
810
911from 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
1421class 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