From d09fe0f0e23e4a53c02f19a22d025f7eac872c03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Tue, 6 Sep 2022 00:16:24 +0000 Subject: [PATCH] actually use config.image and config.calendar --- api/ovdashboard_api/dav_calendar.py | 7 ++++++- api/ovdashboard_api/routers/image.py | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/api/ovdashboard_api/dav_calendar.py b/api/ovdashboard_api/dav_calendar.py index 7e10dd5..cbe46b2 100644 --- a/api/ovdashboard_api/dav_calendar.py +++ b/api/ovdashboard_api/dav_calendar.py @@ -15,6 +15,8 @@ from caldav.lib.error import ReportError from pydantic import BaseModel, validator from vobject.icalendar import VEvent +from ovdashboard_api.config import Config + from .async_helpers import get_ttl_hash, run_in_executor, timed_alru_cache from .dav_common import caldav_principal from .settings import SETTINGS @@ -118,6 +120,9 @@ async def _get_calendar_events( an iterator would get consumed. """ + cfg = await Config.get() + search_span = timedelta(days=cfg.calendar.future_days) + @run_in_executor def _inner() -> Iterator[VEvent]: """ @@ -133,7 +138,7 @@ async def _get_calendar_events( date_start = datetime.utcnow().date() time_min = datetime.min.time() dt_start = datetime.combine(date_start, time_min) - dt_end = dt_start + timedelta(days=365) + dt_end = dt_start + search_span try: search_result = calendar.date_search( diff --git a/api/ovdashboard_api/routers/image.py b/api/ovdashboard_api/routers/image.py index 3e28cdf..7373f41 100644 --- a/api/ovdashboard_api/routers/image.py +++ b/api/ovdashboard_api/routers/image.py @@ -14,6 +14,7 @@ from fastapi import APIRouter, Depends from fastapi.responses import StreamingResponse from PIL import Image +from ..config import Config from ..dav_file import DavFile from ._common import FileNameLister, PrefixFinder, PrefixUnique @@ -62,11 +63,17 @@ async def get_image( prefix: str, name: str = Depends(_unique), ) -> str: + cfg = await Config.get() + dav_file = DavFile(f"{_lister.remote_path}/{name}") - img = Image.open(BytesIO(await dav_file.bytes)).convert("RGB") + img = Image.open( + BytesIO(await dav_file.bytes) + ).convert( + cfg.image.mode + ) img_buffer = BytesIO() - img.save(img_buffer, format="JPEG", quality=85) + img.save(img_buffer, **cfg.image.save_params) img_buffer.seek(0) return StreamingResponse(