2023-09-11 19:39:02 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2023-09-11 22:24:01 +00:00
|
|
|
class ConfigModel(BaseModel):
|
|
|
|
class __Puzzle(BaseModel):
|
|
|
|
solution: str
|
|
|
|
shuffled: str
|
|
|
|
begin: date
|
|
|
|
end: date
|
|
|
|
closing: date
|
|
|
|
seed: str
|
|
|
|
|
|
|
|
class __Calendar(BaseModel):
|
|
|
|
config_file: str
|
|
|
|
background: str
|
|
|
|
doors: list[int]
|
|
|
|
|
|
|
|
class __Image(BaseModel):
|
|
|
|
size: int
|
|
|
|
border: int
|
|
|
|
fonts: list[tuple[str, int]]
|
|
|
|
|
|
|
|
class __WebDAV(BaseModel):
|
|
|
|
url: str
|
|
|
|
cache_ttl: int
|
|
|
|
config_file: str
|
|
|
|
|
|
|
|
puzzle: __Puzzle
|
|
|
|
calendar: __Calendar
|
|
|
|
image: __Image
|
|
|
|
webdav: __WebDAV
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/config_model")
|
|
|
|
async def get_config_model(
|
2023-09-11 19:39:02 +00:00
|
|
|
_: None = Depends(require_admin),
|
|
|
|
cfg: Config = Depends(get_config),
|
|
|
|
cal_cfg: CalendarConfig = Depends(get_calendar_config),
|
2023-09-11 19:40:36 +00:00
|
|
|
shuffled_solution: str = Depends(shuffle_solution),
|
2023-09-11 22:24:01 +00:00
|
|
|
) -> ConfigModel:
|
|
|
|
return ConfigModel.model_validate(
|
|
|
|
{
|
|
|
|
"puzzle": {
|
|
|
|
"solution": cfg.puzzle.solution,
|
|
|
|
"shuffled": shuffled_solution,
|
|
|
|
"begin": date.today(),
|
|
|
|
"end": date.today(),
|
|
|
|
"closing": date.today(),
|
|
|
|
"seed": cfg.puzzle.random_seed,
|
|
|
|
},
|
|
|
|
"calendar": {
|
|
|
|
"config_file": cfg.puzzle.calendar,
|
|
|
|
"background": cal_cfg.background,
|
|
|
|
"doors": [door.day for door in cal_cfg.doors],
|
|
|
|
},
|
|
|
|
"image": {
|
|
|
|
"size": 500,
|
|
|
|
"border": 30,
|
|
|
|
"fonts": [(cfg.server.font, 50)],
|
|
|
|
},
|
|
|
|
"webdav": {
|
|
|
|
"url": SETTINGS.webdav.url,
|
|
|
|
"cache_ttl": SETTINGS.webdav.cache_ttl,
|
|
|
|
"config_file": SETTINGS.webdav.config_filename,
|
|
|
|
},
|
|
|
|
}
|
2023-09-11 19:39:02 +00:00
|
|
|
)
|