diff --git a/api/advent22_api/config.py b/api/advent22_api/config.py index 3025249..b697547 100644 --- a/api/advent22_api/config.py +++ b/api/advent22_api/config.py @@ -11,6 +11,7 @@ class User(BaseModel): class Puzzle(BaseModel): + background: str solution: str diff --git a/api/advent22_api/routers/_misc.py b/api/advent22_api/routers/_misc.py index 97f6484..ffd64e2 100644 --- a/api/advent22_api/routers/_misc.py +++ b/api/advent22_api/routers/_misc.py @@ -1,10 +1,12 @@ import itertools import random import re +from io import BytesIO from typing import Any, Self, Sequence from fastapi import Depends -from PIL import ImageFont +from fastapi.responses import StreamingResponse +from PIL import Image, ImageFont from ..config import Config, get_config from ..dav_common import dav_file_exists, dav_get_file, dav_list_files @@ -122,3 +124,22 @@ async def get_image( except RuntimeError: # Erstelle automatisch generiertes Bild return await get_auto_image(index=index, letter=letter, images=images) + + +async def api_return_image( + img: Image.Image, +) -> StreamingResponse: + """ + Bild mit API zurückgeben + """ + + # Bilddaten in Puffer laden + img_buffer = BytesIO() + img.save(img_buffer, format="JPEG", quality=85) + img_buffer.seek(0) + + # zurückgeben + return StreamingResponse( + content=img_buffer, + media_type="image/jpeg", + ) diff --git a/api/advent22_api/routers/days.py b/api/advent22_api/routers/days.py index e5f7612..ef88346 100644 --- a/api/advent22_api/routers/days.py +++ b/api/advent22_api/routers/days.py @@ -1,12 +1,11 @@ from datetime import date -from io import BytesIO from fastapi import APIRouter, Depends, HTTPException, status from fastapi.responses import StreamingResponse from ..config import Config, get_config from ._image import AdventImage -from ._misc import get_image, shuffle +from ._misc import api_return_image, get_image, shuffle from .user import user_is_admin router = APIRouter(prefix="/days", tags=["days"]) @@ -67,12 +66,4 @@ async def get_image_for_day( if not (can_view or is_admin): raise HTTPException(status.HTTP_401_UNAUTHORIZED, "Wie unhöflich!!!") - # Bilddaten in Puffer laden - img_buffer = BytesIO() - image.img.save(img_buffer, format="JPEG", quality=85) - img_buffer.seek(0) - - return StreamingResponse( - content=img_buffer, - media_type="image/jpeg", - ) + return await api_return_image(image.img) diff --git a/api/advent22_api/routers/general.py b/api/advent22_api/routers/general.py index 05dcbbb..9d1059d 100644 --- a/api/advent22_api/routers/general.py +++ b/api/advent22_api/routers/general.py @@ -1,3 +1,25 @@ -from fastapi import APIRouter +from fastapi import APIRouter, Depends +from fastapi.responses import StreamingResponse +from PIL import Image + +from ..config import Config, get_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}")) + ) diff --git a/ui/src/assets/adventskalender.jpg b/ui/src/assets/adventskalender.jpg deleted file mode 100644 index 83a9a1e..0000000 --- a/ui/src/assets/adventskalender.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:3a3cecf18485db1e98980a7673d2befe3989111d3d04cb009d998bbef4df5834 -size 453516 diff --git a/ui/src/components/door_map/DoorChooser.vue b/ui/src/components/door_map/DoorChooser.vue index bdec9e7..b080f9b 100644 --- a/ui/src/components/door_map/DoorChooser.vue +++ b/ui/src/components/door_map/DoorChooser.vue @@ -11,7 +11,7 @@
- +
- +