refac: fix image router

This commit is contained in:
Jörn-Michael Miehe 2023-10-20 13:12:53 +02:00
parent 8f6243723b
commit db1cc5f707
2 changed files with 10 additions and 10 deletions

View file

@ -7,7 +7,7 @@ This file: Main API router definition.
from fastapi import APIRouter
# from . import aggregate, calendar, file, image, misc, text, ticker
from . import file, misc
from . import file, image, misc
router = APIRouter(prefix="/api/v1")
@ -15,7 +15,7 @@ router.include_router(misc.router)
# router.include_router(text.router)
# router.include_router(ticker.router)
# router.include_router(image.router)
router.include_router(image.router)
router.include_router(file.router)
# router.include_router(calendar.router)

View file

@ -15,9 +15,9 @@ from fastapi import APIRouter, Depends
from fastapi.responses import StreamingResponse
from PIL import Image
from ...config import Config, ImageUIConfig
from ...dav_common import webdav_ensure_files, webdav_ensure_path
from ...dav_file import DavFile
from ...core.config import Config, ImageUIConfig, get_config
from ...core.dav_common import webdav_ensure_files, webdav_ensure_path
from ...core.webdav import WebDAV
from ._common import FileNameLister, PrefixFinder, PrefixUnique
_logger = getLogger(__name__)
@ -80,10 +80,10 @@ async def get_image(
prefix: str,
name: str = Depends(image_unique),
) -> StreamingResponse:
cfg = await Config.get()
dav_file = DavFile(f"{await image_lister.remote_path}/{name}")
img = Image.open(BytesIO(await dav_file.as_bytes)).convert(cfg.image.mode)
cfg = await get_config()
img = Image.open(
BytesIO(await WebDAV.read_bytes(f"{await image_lister.remote_path}/{name}"))
)
img_buffer = BytesIO()
img.save(img_buffer, **cfg.image.save_params)
@ -101,6 +101,6 @@ async def get_image(
response_model=ImageUIConfig,
)
async def get_ui_config(
cfg: Config = Depends(Config.get),
cfg: Config = Depends(get_config),
) -> ImageUIConfig:
return cfg.image