diff --git a/api/advent22_api/core/calendar_config.py b/api/advent22_api/core/calendar_config.py index 5ff844f..6760f09 100644 --- a/api/advent22_api/core/calendar_config.py +++ b/api/advent22_api/core/calendar_config.py @@ -27,6 +27,9 @@ class CalendarConfig(BaseModel): # Dateiname Hintergrundbild background: str = "adventskalender.jpg" + # Dateiname Favicon + favicon: str = "favicon.png" + # Türen für die UI doors: DoorsSaved = [] diff --git a/api/advent22_api/core/helpers.py b/api/advent22_api/core/helpers.py index 7bd3f2f..e33db43 100644 --- a/api/advent22_api/core/helpers.py +++ b/api/advent22_api/core/helpers.py @@ -114,9 +114,27 @@ async def load_image(file_name: str) -> Image.Image: return Image.open(BytesIO(await WebDAV.read_bytes(file_name))) -async def api_return_image(img: Image.Image) -> StreamingResponse: +async def api_return_ico(img: Image.Image) -> StreamingResponse: """ - Bild mit API zurückgeben + ICO-Bild mit API zurückgeben + """ + + # JPEG-Daten in Puffer speichern + img_buffer = BytesIO() + img.resize(size=(256, 256), resample=Image.LANCZOS) + img.save(img_buffer, format="ICO") + img_buffer.seek(0) + + # zurückgeben + return StreamingResponse( + media_type="image/x-icon", + content=img_buffer, + ) + + +async def api_return_jpeg(img: Image.Image) -> StreamingResponse: + """ + JPEG-Bild mit API zurückgeben """ # JPEG-Daten in Puffer speichern diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index 979f66b..31fb3da 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -44,6 +44,7 @@ class ConfigModel(BaseModel): class __Calendar(BaseModel): config_file: str background: str + favicon: str class __Font(BaseModel): file: str @@ -93,6 +94,7 @@ async def get_config_model( "calendar": { "config_file": cfg.calendar, "background": cal_cfg.background, + "favicon": cal_cfg.favicon, }, "image": cfg.image, "fonts": [ diff --git a/api/advent22_api/routers/user.py b/api/advent22_api/routers/user.py index 673c5c1..e6c19c0 100644 --- a/api/advent22_api/routers/user.py +++ b/api/advent22_api/routers/user.py @@ -7,7 +7,7 @@ from PIL import Image from ..core.calendar_config import CalendarConfig, DoorsSaved, get_calendar_config from ..core.config import Config, get_config from ..core.depends import get_all_event_dates, get_day_image -from ..core.helpers import EventDates, api_return_image, load_image +from ..core.helpers import EventDates, api_return_ico, api_return_jpeg, load_image from ._security import user_can_view_day, user_is_admin, user_visible_days router = APIRouter(prefix="/user", tags=["user"]) @@ -24,7 +24,29 @@ async def get_background_image( Hintergrundbild laden """ - return await api_return_image(await load_image(f"files/{cal_cfg.background}")) + return await api_return_jpeg(await load_image(f"files/{cal_cfg.background}")) + + +@router.get( + "/favicon", + response_class=StreamingResponse, +) +async def get_favicon( + cal_cfg: CalendarConfig = Depends(get_calendar_config), +) -> StreamingResponse: + """ + Favicon laden + """ + + try: + return await api_return_ico(await load_image(f"files/{cal_cfg.favicon}")) + + except RuntimeError: + raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) + + +# - favicon +# - "user-config-model" @router.get("/title") @@ -82,7 +104,7 @@ async def get_image_for_day( status.HTTP_404_NOT_FOUND, "Ich habe heute leider kein Foto für dich." ) - return await api_return_image(image) + return await api_return_jpeg(image) @router.get("/next_door") diff --git a/ui/public/favicon.ico b/ui/public/favicon.ico index df36fcf..c7ab788 100644 Binary files a/ui/public/favicon.ico and b/ui/public/favicon.ico differ diff --git a/ui/src/components/admin/ConfigView.vue b/ui/src/components/admin/ConfigView.vue index 86be5bc..4468da2 100644 --- a/ui/src/components/admin/ConfigView.vue +++ b/ui/src/components/admin/ConfigView.vue @@ -79,6 +79,9 @@