from datetime import date from fastapi import APIRouter, Depends, HTTPException, status from fastapi.responses import StreamingResponse from PIL import Image from ..core import depends from ..core.config import get_config from ..core.image_helpers import api_return_image from ._security import user_can_view_door, user_is_admin, user_visible_doors router = APIRouter(prefix="/days", tags=["days"]) @router.on_event("startup") async def startup() -> None: cfg = await get_config() print(cfg.puzzle.solution) @router.get("/date") async def get_date() -> str: """ Aktuelles Server-Datum """ return date.today().isoformat() @router.get("/visible_days") async def get_visible_days( visible_doors: int = Depends(user_visible_doors), ) -> int: """ Sichtbare Türchen """ return visible_doors @router.get("/part/{day}") async def get_part_for_day( part: str = Depends(depends.get_part_for_day), ) -> str: """ Heutiger Lösungsteil """ return part @router.get( "/image/{day}", response_class=StreamingResponse, ) async def get_image_for_day( image: Image.Image = Depends(depends.get_image_for_day), can_view: bool = Depends(user_can_view_door), is_admin: bool = Depends(user_is_admin), ) -> StreamingResponse: """ Bild für einen Tag erstellen """ if not (can_view or is_admin): raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Wie unhöflich!!!") return await api_return_image(image)