advent22/api/advent22_api/routers/general.py

50 lines
974 B
Python
Raw Normal View History

2023-09-04 21:23:27 +00:00
from fastapi import APIRouter, Depends
from fastapi.responses import StreamingResponse
from PIL import Image
2023-09-07 16:44:44 +00:00
from ..config import Config, Doors, get_config, set_config
2023-09-04 21:23:27 +00:00
from ..dav_common import dav_get_file
from ._misc import api_return_image
2022-10-14 22:47:48 +00:00
router = APIRouter(prefix="/general", tags=["general"])
2023-09-04 21:23:27 +00:00
@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}"))
)
2023-09-07 16:44:44 +00:00
@router.get("/doors")
async def get_doors(
cfg: Config = Depends(get_config),
) -> Doors:
"""
Türchen lesen
"""
return cfg.doors
@router.put("/doors")
async def put_doors(
doors: Doors,
cfg: Config = Depends(get_config),
) -> None:
"""
Türchen setzen
"""
cfg.doors = doors
await set_config(cfg)