2023-09-08 19:08:13 +00:00
|
|
|
import tomllib
|
2023-09-08 18:17:18 +00:00
|
|
|
from typing import TypeAlias
|
|
|
|
|
2023-09-08 19:08:13 +00:00
|
|
|
import tomli_w
|
|
|
|
from fastapi import Depends
|
2023-09-08 18:17:18 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2023-09-08 19:53:35 +00:00
|
|
|
from .config import Config, get_config
|
2023-09-08 19:08:13 +00:00
|
|
|
from .webdav import WebDAV
|
|
|
|
|
2023-09-08 18:17:18 +00:00
|
|
|
|
|
|
|
class DoorSaved(BaseModel):
|
|
|
|
# Tag, an dem die Tür aufgeht
|
|
|
|
day: int
|
|
|
|
|
|
|
|
# Koordinaten für zwei Eckpunkte
|
|
|
|
x1: int
|
|
|
|
y1: int
|
|
|
|
x2: int
|
|
|
|
y2: int
|
|
|
|
|
|
|
|
|
|
|
|
DoorsSaved: TypeAlias = list[DoorSaved]
|
|
|
|
|
|
|
|
|
|
|
|
class CalendarConfig(BaseModel):
|
|
|
|
# Dateiname Hintergrundbild
|
|
|
|
background: str = "adventskalender.jpg"
|
|
|
|
|
|
|
|
# Türen für die UI
|
|
|
|
doors: DoorsSaved = []
|
2023-09-08 19:08:13 +00:00
|
|
|
|
2023-09-08 19:53:35 +00:00
|
|
|
async def change(self, cfg: Config) -> None:
|
2023-09-08 19:08:13 +00:00
|
|
|
"""
|
|
|
|
Kalender Konfiguration ändern
|
|
|
|
"""
|
|
|
|
|
|
|
|
await WebDAV.write_str(
|
|
|
|
path=f"files/{cfg.puzzle.calendar}",
|
2023-09-21 11:26:33 +00:00
|
|
|
content=tomli_w.dumps(self.model_dump()),
|
2023-09-08 19:08:13 +00:00
|
|
|
)
|
2023-09-08 19:53:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def get_calendar_config(
|
|
|
|
cfg: Config = Depends(get_config),
|
|
|
|
) -> CalendarConfig:
|
|
|
|
"""
|
|
|
|
Kalender Konfiguration lesen
|
|
|
|
"""
|
|
|
|
|
|
|
|
txt = await WebDAV.read_str(path=f"files/{cfg.puzzle.calendar}")
|
|
|
|
return CalendarConfig.model_validate(tomllib.loads(txt))
|