refac: fix routers text and ticker; issue with prefix does not work with directory

This commit is contained in:
Jörn-Michael Miehe 2023-10-20 13:40:15 +02:00
parent db1cc5f707
commit d2e77b9ae5
3 changed files with 14 additions and 18 deletions

View file

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

View file

@ -14,8 +14,8 @@ from typing import Iterator
from fastapi import APIRouter, Depends
from markdown import markdown
from ...dav_common import webdav_ensure_files, webdav_ensure_path
from ...dav_file import DavFile
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__)
@ -73,9 +73,7 @@ async def find_texts(
async def get_text_content(
name: str = Depends(text_unique),
) -> str:
return await DavFile(
f"{await text_lister.remote_path}/{name}",
).as_string
return await WebDAV.read_str(f"{await text_lister.remote_path}/{name}")
@router.get(

View file

@ -12,9 +12,9 @@ from typing import Iterator
from fastapi import APIRouter, Depends
from markdown import markdown
from ...config import Config, TickerUIConfig
from ...dav_common import webdav_ensure_files, webdav_ensure_path
from ...dav_file import DavFile
from ...core.config import Config, TickerUIConfig, get_config
from ...core.dav_common import webdav_ensure_files, webdav_ensure_path
from ...core.webdav import WebDAV
from .text import text_lister, text_unique
_logger = getLogger(__name__)
@ -35,12 +35,10 @@ async def start_router() -> None:
async def get_ticker_lines() -> Iterator[str]:
cfg = await Config.get()
cfg = await get_config()
file_name = await text_unique(cfg.ticker.file_name)
ticker = await DavFile(
f"{await text_lister.remote_path}/{file_name}",
).as_string
ticker = await WebDAV.read_str(f"{await text_lister.remote_path}/{file_name}")
return (line.strip() for line in ticker.split("\n") if line.strip())
@ -48,7 +46,7 @@ async def get_ticker_lines() -> Iterator[str]:
async def get_ticker_content_lines(
ticker_lines: Iterator[str] = Depends(get_ticker_lines),
) -> Iterator[str]:
cfg = await Config.get()
cfg = await get_config()
return (
line for line in ticker_lines if not line.startswith(cfg.ticker.comment_marker)
@ -62,7 +60,7 @@ async def get_ticker_content(
if len(ticker_content_padded) == 2:
return ""
cfg = await Config.get()
cfg = await get_config()
ticker_content = cfg.ticker.separator.join(
ticker_content_padded,
)
@ -89,6 +87,6 @@ async def get_raw_ticker(
response_model=TickerUIConfig,
)
async def get_ui_config(
cfg: Config = Depends(Config.get),
cfg: Config = Depends(get_config),
) -> TickerUIConfig:
return cfg.ticker