refac: fix routers text and ticker; issue with prefix does not work with directory
This commit is contained in:
parent
db1cc5f707
commit
d2e77b9ae5
3 changed files with 14 additions and 18 deletions
|
@ -7,14 +7,14 @@ 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, image, misc
|
from . import file, image, misc, text, ticker
|
||||||
|
|
||||||
router = APIRouter(prefix="/api/v1")
|
router = APIRouter(prefix="/api/v1")
|
||||||
|
|
||||||
router.include_router(misc.router)
|
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)
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@ from typing import Iterator
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
|
|
||||||
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__)
|
||||||
|
@ -73,9 +73,7 @@ async def find_texts(
|
||||||
async def get_text_content(
|
async def get_text_content(
|
||||||
name: str = Depends(text_unique),
|
name: str = Depends(text_unique),
|
||||||
) -> str:
|
) -> str:
|
||||||
return await DavFile(
|
return await WebDAV.read_str(f"{await text_lister.remote_path}/{name}")
|
||||||
f"{await text_lister.remote_path}/{name}",
|
|
||||||
).as_string
|
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
|
|
|
@ -12,9 +12,9 @@ from typing import Iterator
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from markdown import markdown
|
from markdown import markdown
|
||||||
|
|
||||||
from ...config import Config, TickerUIConfig
|
from ...core.config import Config, TickerUIConfig, 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 .text import text_lister, text_unique
|
from .text import text_lister, text_unique
|
||||||
|
|
||||||
_logger = getLogger(__name__)
|
_logger = getLogger(__name__)
|
||||||
|
@ -35,12 +35,10 @@ async def start_router() -> None:
|
||||||
|
|
||||||
|
|
||||||
async def get_ticker_lines() -> Iterator[str]:
|
async def get_ticker_lines() -> Iterator[str]:
|
||||||
cfg = await Config.get()
|
cfg = await get_config()
|
||||||
file_name = await text_unique(cfg.ticker.file_name)
|
file_name = await text_unique(cfg.ticker.file_name)
|
||||||
|
|
||||||
ticker = await DavFile(
|
ticker = await WebDAV.read_str(f"{await text_lister.remote_path}/{file_name}")
|
||||||
f"{await text_lister.remote_path}/{file_name}",
|
|
||||||
).as_string
|
|
||||||
|
|
||||||
return (line.strip() for line in ticker.split("\n") if line.strip())
|
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(
|
async def get_ticker_content_lines(
|
||||||
ticker_lines: Iterator[str] = Depends(get_ticker_lines),
|
ticker_lines: Iterator[str] = Depends(get_ticker_lines),
|
||||||
) -> Iterator[str]:
|
) -> Iterator[str]:
|
||||||
cfg = await Config.get()
|
cfg = await get_config()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
line for line in ticker_lines if not line.startswith(cfg.ticker.comment_marker)
|
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:
|
if len(ticker_content_padded) == 2:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
cfg = await Config.get()
|
cfg = await get_config()
|
||||||
ticker_content = cfg.ticker.separator.join(
|
ticker_content = cfg.ticker.separator.join(
|
||||||
ticker_content_padded,
|
ticker_content_padded,
|
||||||
)
|
)
|
||||||
|
@ -89,6 +87,6 @@ async def get_raw_ticker(
|
||||||
response_model=TickerUIConfig,
|
response_model=TickerUIConfig,
|
||||||
)
|
)
|
||||||
async def get_ui_config(
|
async def get_ui_config(
|
||||||
cfg: Config = Depends(Config.get),
|
cfg: Config = Depends(get_config),
|
||||||
) -> TickerUIConfig:
|
) -> TickerUIConfig:
|
||||||
return cfg.ticker
|
return cfg.ticker
|
||||||
|
|
Loading…
Reference in a new issue