mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 08:13:01 +00:00
49 lines
1,003 B
Python
49 lines
1,003 B
Python
from fastapi import APIRouter, Depends
|
|
from fastapi.responses import StreamingResponse
|
|
from PIL import Image
|
|
|
|
from ..config import Config, DoorsSaved, get_config, set_config
|
|
from ..dav_common import dav_get_file
|
|
from ._misc import api_return_image
|
|
|
|
router = APIRouter(prefix="/general", tags=["general"])
|
|
|
|
|
|
@router.get(
|
|
"/background",
|
|
response_class=StreamingResponse,
|
|
)
|
|
async def get_image_for_day(
|
|
cfg: Config = Depends(get_config),
|
|
) -> StreamingResponse:
|
|
"""
|
|
Hintergrundbild laden
|
|
"""
|
|
|
|
return await api_return_image(
|
|
Image.open(await dav_get_file(f"files/{cfg.puzzle.background}"))
|
|
)
|
|
|
|
|
|
@router.get("/doors")
|
|
async def get_doors(
|
|
cfg: Config = Depends(get_config),
|
|
) -> DoorsSaved:
|
|
"""
|
|
Türchen lesen
|
|
"""
|
|
|
|
return cfg.puzzle.doors
|
|
|
|
|
|
@router.put("/doors")
|
|
async def put_doors(
|
|
doors: DoorsSaved,
|
|
cfg: Config = Depends(get_config),
|
|
) -> None:
|
|
"""
|
|
Türchen setzen
|
|
"""
|
|
|
|
cfg.puzzle.doors = doors
|
|
await set_config(cfg)
|