From 1b5b9d7f9ad89928cef93475064a7701f2b35ef1 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 11 Jun 2024 01:06:24 +0200 Subject: [PATCH] very basic diva frontend --- example_config/core.yaml | 6 +-- titles/diva/__init__.py | 2 + titles/diva/frontend.py | 52 ++++++++++++++++++++++++ titles/diva/templates/css/diva_style.css | 0 titles/diva/templates/diva_index.jinja | 15 +++++++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 titles/diva/frontend.py create mode 100644 titles/diva/templates/css/diva_style.css create mode 100644 titles/diva/templates/diva_index.jinja diff --git a/example_config/core.yaml b/example_config/core.yaml index 758a089..8f1ae3c 100644 --- a/example_config/core.yaml +++ b/example_config/core.yaml @@ -21,7 +21,7 @@ title: reboot_end_time: "05:00" database: - host: "localhost" + host: "192.168.192.12" username: "aime" password: "aime" name: "aime" @@ -33,7 +33,7 @@ database: memcached_host: "localhost" frontend: - enable: False + enable: True port: 8080 loglevel: "info" secret: "" @@ -58,7 +58,7 @@ aimedb: listen_address: "" loglevel: "info" port: 22345 - key: "" + key: "Copyright(C)SEGA" id_secret: "" id_lifetime_seconds: 86400 diff --git a/titles/diva/__init__.py b/titles/diva/__init__.py index d298ba2..7bfa2cc 100644 --- a/titles/diva/__init__.py +++ b/titles/diva/__init__.py @@ -2,8 +2,10 @@ from titles.diva.index import DivaServlet from titles.diva.const import DivaConstants from titles.diva.database import DivaData from titles.diva.read import DivaReader +from .frontend import DivaFrontend index = DivaServlet database = DivaData reader = DivaReader +frontend = DivaFrontend game_codes = [DivaConstants.GAME_CODE] diff --git a/titles/diva/frontend.py b/titles/diva/frontend.py new file mode 100644 index 0000000..ca93ca0 --- /dev/null +++ b/titles/diva/frontend.py @@ -0,0 +1,52 @@ +from typing import List +from starlette.routing import Route, Mount +from starlette.requests import Request +from starlette.responses import Response, RedirectResponse +from os import path +import yaml +import jinja2 + +from core.frontend import FE_Base, UserSession +from core.config import CoreConfig +from .database import DivaData +from .config import DivaConfig +from .const import DivaConstants + +class DivaFrontend(FE_Base): + def __init__( + self, cfg: CoreConfig, environment: jinja2.Environment, cfg_dir: str + ) -> None: + super().__init__(cfg, environment) + self.data = DivaData(cfg) + self.game_cfg = DivaConfig() + if path.exists(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}"): + self.game_cfg.update( + yaml.safe_load(open(f"{cfg_dir}/{DivaConstants.CONFIG_NAME}")) + ) + self.nav_name = "diva" + + def get_routes(self) -> List[Route]: + return [ + Route("/", self.render_GET, methods=['GET']) + ] + + async def render_GET(self, request: Request) -> bytes: + template = self.environment.get_template( + "titles/diva/templates/diva_index.jinja" + ) + usr_sesh = self.validate_session(request) + if not usr_sesh: + usr_sesh = UserSession() + + if usr_sesh.user_id > 0: + profile = self.data.profile + + resp = Response(template.render( + title=f"{self.core_config.server.name} | {self.nav_name}", + game_list=self.environment.globals["game_list"], + sesh=vars(usr_sesh), + profile=profile + )) + return resp + else: + return RedirectResponse("/login") \ No newline at end of file diff --git a/titles/diva/templates/css/diva_style.css b/titles/diva/templates/css/diva_style.css new file mode 100644 index 0000000..e69de29 diff --git a/titles/diva/templates/diva_index.jinja b/titles/diva/templates/diva_index.jinja new file mode 100644 index 0000000..aa698b4 --- /dev/null +++ b/titles/diva/templates/diva_index.jinja @@ -0,0 +1,15 @@ +{% extends "core/templates/index.jinja" %} +{% block content %} + + +
{{ description }}
+