actually use config.image and config.calendar

This commit is contained in:
Jörn-Michael Miehe 2022-09-06 00:16:24 +00:00
parent 1e9efd9cf3
commit d09fe0f0e2
2 changed files with 15 additions and 3 deletions

View file

@ -15,6 +15,8 @@ from caldav.lib.error import ReportError
from pydantic import BaseModel, validator from pydantic import BaseModel, validator
from vobject.icalendar import VEvent 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 .async_helpers import get_ttl_hash, run_in_executor, timed_alru_cache
from .dav_common import caldav_principal from .dav_common import caldav_principal
from .settings import SETTINGS from .settings import SETTINGS
@ -118,6 +120,9 @@ async def _get_calendar_events(
an iterator would get consumed. an iterator would get consumed.
""" """
cfg = await Config.get()
search_span = timedelta(days=cfg.calendar.future_days)
@run_in_executor @run_in_executor
def _inner() -> Iterator[VEvent]: def _inner() -> Iterator[VEvent]:
""" """
@ -133,7 +138,7 @@ async def _get_calendar_events(
date_start = datetime.utcnow().date() date_start = datetime.utcnow().date()
time_min = datetime.min.time() time_min = datetime.min.time()
dt_start = datetime.combine(date_start, time_min) dt_start = datetime.combine(date_start, time_min)
dt_end = dt_start + timedelta(days=365) dt_end = dt_start + search_span
try: try:
search_result = calendar.date_search( search_result = calendar.date_search(

View file

@ -14,6 +14,7 @@ from fastapi import APIRouter, Depends
from fastapi.responses import StreamingResponse from fastapi.responses import StreamingResponse
from PIL import Image from PIL import Image
from ..config import Config
from ..dav_file import DavFile from ..dav_file import DavFile
from ._common import FileNameLister, PrefixFinder, PrefixUnique from ._common import FileNameLister, PrefixFinder, PrefixUnique
@ -62,11 +63,17 @@ async def get_image(
prefix: str, prefix: str,
name: str = Depends(_unique), name: str = Depends(_unique),
) -> str: ) -> str:
cfg = await Config.get()
dav_file = DavFile(f"{_lister.remote_path}/{name}") 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_buffer = BytesIO()
img.save(img_buffer, format="JPEG", quality=85) img.save(img_buffer, **cfg.image.save_params)
img_buffer.seek(0) img_buffer.seek(0)
return StreamingResponse( return StreamingResponse(