refac: fix image router
This commit is contained in:
parent
8f6243723b
commit
db1cc5f707
2 changed files with 10 additions and 10 deletions
|
@ -7,7 +7,7 @@ This file: Main API router definition.
|
||||||
from fastapi import APIRouter
|
from fastapi import APIRouter
|
||||||
|
|
||||||
# from . import aggregate, calendar, file, image, misc, text, ticker
|
# from . import aggregate, calendar, file, image, misc, text, ticker
|
||||||
from . import file, misc
|
from . import file, image, misc
|
||||||
|
|
||||||
router = APIRouter(prefix="/api/v1")
|
router = APIRouter(prefix="/api/v1")
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ router.include_router(misc.router)
|
||||||
|
|
||||||
# router.include_router(text.router)
|
# router.include_router(text.router)
|
||||||
# router.include_router(ticker.router)
|
# router.include_router(ticker.router)
|
||||||
# router.include_router(image.router)
|
router.include_router(image.router)
|
||||||
router.include_router(file.router)
|
router.include_router(file.router)
|
||||||
|
|
||||||
# router.include_router(calendar.router)
|
# router.include_router(calendar.router)
|
||||||
|
|
|
@ -15,9 +15,9 @@ 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, ImageUIConfig
|
from ...core.config import Config, ImageUIConfig, get_config
|
||||||
from ...dav_common import webdav_ensure_files, webdav_ensure_path
|
from ...core.dav_common import webdav_ensure_files, webdav_ensure_path
|
||||||
from ...dav_file import DavFile
|
from ...core.webdav import WebDAV
|
||||||
from ._common import FileNameLister, PrefixFinder, PrefixUnique
|
from ._common import FileNameLister, PrefixFinder, PrefixUnique
|
||||||
|
|
||||||
_logger = getLogger(__name__)
|
_logger = getLogger(__name__)
|
||||||
|
@ -80,10 +80,10 @@ async def get_image(
|
||||||
prefix: str,
|
prefix: str,
|
||||||
name: str = Depends(image_unique),
|
name: str = Depends(image_unique),
|
||||||
) -> StreamingResponse:
|
) -> StreamingResponse:
|
||||||
cfg = await Config.get()
|
cfg = await get_config()
|
||||||
|
img = Image.open(
|
||||||
dav_file = DavFile(f"{await image_lister.remote_path}/{name}")
|
BytesIO(await WebDAV.read_bytes(f"{await image_lister.remote_path}/{name}"))
|
||||||
img = Image.open(BytesIO(await dav_file.as_bytes)).convert(cfg.image.mode)
|
)
|
||||||
|
|
||||||
img_buffer = BytesIO()
|
img_buffer = BytesIO()
|
||||||
img.save(img_buffer, **cfg.image.save_params)
|
img.save(img_buffer, **cfg.image.save_params)
|
||||||
|
@ -101,6 +101,6 @@ async def get_image(
|
||||||
response_model=ImageUIConfig,
|
response_model=ImageUIConfig,
|
||||||
)
|
)
|
||||||
async def get_ui_config(
|
async def get_ui_config(
|
||||||
cfg: Config = Depends(Config.get),
|
cfg: Config = Depends(get_config),
|
||||||
) -> ImageUIConfig:
|
) -> ImageUIConfig:
|
||||||
return cfg.image
|
return cfg.image
|
||||||
|
|
Loading…
Reference in a new issue