text router raw

This commit is contained in:
Jörn-Michael Miehe 2022-09-05 12:58:10 +00:00
parent bf92eadf3f
commit 4da69740ae

View file

@ -3,7 +3,10 @@ Router "text" provides:
- listing text files - listing text files
- finding text files by name prefix - finding text files by name prefix
- getting image file content as converted Markdown by name prefix - getting text file raw content by name prefix
- getting text file HTML content by name prefix (using Markdown)
- getting the "ticker" raw content
- getting the "ticker" HTML content (using Markdown)
""" """
import re import re
@ -50,7 +53,6 @@ async def get_ticker_content_lines(
) )
@router.get("/get/ticker")
async def get_ticker_content( async def get_ticker_content(
ticker_content_lines: Iterator[str] = Depends(get_ticker_content_lines), ticker_content_lines: Iterator[str] = Depends(get_ticker_content_lines),
) -> str: ) -> str:
@ -58,9 +60,21 @@ async def get_ticker_content(
ticker_content_lines = ["", *ticker_content_lines, ""] ticker_content_lines = ["", *ticker_content_lines, ""]
ticker_content = cfg.ticker_separator.join(ticker_content_lines) ticker_content = cfg.ticker_separator.join(ticker_content_lines)
return markdown( return ticker_content.strip()
ticker_content.strip()
)
@ router.get("/get/html/ticker")
async def get_ticker(
ticker_content: str = Depends(get_ticker_content),
) -> str:
return markdown(ticker_content)
@ router.get("/get/raw/ticker")
async def get_raw_ticker(
ticker_content: str = Depends(get_ticker_content),
) -> str:
return ticker_content
@router.get( @router.get(
@ -85,16 +99,29 @@ async def find_texts(
return list(names) return list(names)
async def get_text_content(
name: str = Depends(_unique),
) -> str:
return await DavFile(f"{_lister.remote_path}/{name}").string
@router.get( @router.get(
"/get/{prefix}", "/get/html/{prefix}",
response_model=str, response_model=str,
responses=_unique.responses, responses=_unique.responses,
) )
async def get_text( async def get_text(
name: str = Depends(_unique), text: str = Depends(get_text_content),
) -> str: ) -> str:
text = await DavFile(f"{_lister.remote_path}/{name}").string return markdown(text)
return markdown(
text @router.get(
"/get/raw/{prefix}",
response_model=str,
responses=_unique.responses,
) )
async def get_raw_text(
text: str = Depends(get_text_content),
) -> str:
return text