diff --git a/api/advent22_api/routers/__init__.py b/api/advent22_api/routers/__init__.py index 69183a0..82ac838 100644 --- a/api/advent22_api/routers/__init__.py +++ b/api/advent22_api/routers/__init__.py @@ -1,9 +1,10 @@ from fastapi import APIRouter -from . import days, general, user +from . import admin, days, general, user router = APIRouter(prefix="/api") +router.include_router(admin.router) router.include_router(days.router) router.include_router(general.router) router.include_router(user.router) diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py new file mode 100644 index 0000000..87b63f0 --- /dev/null +++ b/api/advent22_api/routers/admin.py @@ -0,0 +1,90 @@ +from datetime import date + +from fastapi import APIRouter, Depends +from pydantic import BaseModel + +from ..core.calendar_config import CalendarConfig, get_calendar_config +from ..core.config import Config, get_config +from ..core.depends import shuffle_solution +from ..core.settings import SETTINGS +from ._security import require_admin + +router = APIRouter(prefix="/admin", tags=["admin"]) + + +@router.get("/check") +async def check_admin( + _: None = Depends(require_admin), +) -> bool: + return True + + +class PrivatePuzzle(BaseModel): + title: str + solution: str + shuffled: str + begin: date + end: date + closing: date + seed: str + + +class PrivateCalendar(BaseModel): + config_file: str + background: str + doors: list[int] + + +class PrivateImage(BaseModel): + size: int + border: int + fonts: list[tuple[str, int]] + + +class PrivateWebDAV(BaseModel): + url: str + cache_ttl: int + config_file: str + + +class PrivateConfig(BaseModel): + puzzle: PrivatePuzzle + calendar: PrivateCalendar + image: PrivateImage + webdav: PrivateWebDAV + + +@router.get("/private_config") +async def get_private_config( + _: None = Depends(require_admin), + cfg: Config = Depends(get_config), + cal_cfg: CalendarConfig = Depends(get_calendar_config), +) -> PrivateConfig: + shuffled_solution = await shuffle_solution(cfg) + + return PrivateConfig( + puzzle=PrivatePuzzle( + title="Adventskalender 2023", + solution=cfg.puzzle.solution, + shuffled=shuffled_solution, + begin=date.today(), + end=date.today(), + closing=date.today(), + seed=cfg.puzzle.random_pepper, + ), + calendar=PrivateCalendar( + config_file=cfg.puzzle.calendar, + background=cal_cfg.background, + doors=[door.day for door in cal_cfg.doors], + ), + image=PrivateImage( + size=500, + border=30, + fonts=[(cfg.server.font, 50)], + ), + webdav=PrivateWebDAV( + url=SETTINGS.webdav.url, + cache_ttl=SETTINGS.webdav.cache_ttl, + config_file=SETTINGS.webdav.config_filename, + ), + ) diff --git a/ui/src/components/ConfigView.vue b/ui/src/components/ConfigView.vue index 7175708..e228774 100644 --- a/ui/src/components/ConfigView.vue +++ b/ui/src/components/ConfigView.vue @@ -6,6 +6,9 @@

Rätsel

+
Titel
+
Adventskalender 2023
+
Lösung
ABCDEFGHIJKLMNOPQRSTUVWX