API: config change to meet the UI needs
This commit is contained in:
parent
89a7ffe977
commit
a55bcfb9e0
2 changed files with 40 additions and 27 deletions
|
@ -18,11 +18,19 @@ from .settings import SETTINGS
|
|||
_logger = getLogger(__name__)
|
||||
|
||||
|
||||
class TickerAPIConfig(BaseModel):
|
||||
class TickerUIConfig(BaseModel):
|
||||
"""
|
||||
Configuration for how the UI displays the ticker content.
|
||||
"""
|
||||
Section "[ticker.api]" in "config.txt".
|
||||
|
||||
Configuration for how the API generates the ticker content.
|
||||
color: str = "primary"
|
||||
|
||||
|
||||
class TickerConfig(TickerUIConfig):
|
||||
"""
|
||||
Section "[ticker]" in "config.txt".
|
||||
|
||||
Combined configuration for the ticker.
|
||||
"""
|
||||
|
||||
file_name: str = "ticker"
|
||||
|
@ -30,30 +38,17 @@ class TickerAPIConfig(BaseModel):
|
|||
comment_marker: str = "#"
|
||||
|
||||
|
||||
class TickerUIConfig(BaseModel):
|
||||
class ImageUIConfig(BaseModel):
|
||||
"""
|
||||
Section "[ticker.ui]" in "config.txt".
|
||||
|
||||
Configuration for how the UI displays the ticker content.
|
||||
Configuration for how the UI displays the image carousel.
|
||||
"""
|
||||
|
||||
display: bool = True
|
||||
color: str = "primary"
|
||||
speed: int = 30
|
||||
height: int = 300
|
||||
contain: bool = False
|
||||
speed: int = 10000
|
||||
|
||||
|
||||
class TickerConfig(BaseModel):
|
||||
"""
|
||||
Section "[ticker]" in "config.txt".
|
||||
|
||||
Combined configuration for the ticker.
|
||||
"""
|
||||
|
||||
api: TickerAPIConfig = TickerAPIConfig()
|
||||
ui: TickerUIConfig = TickerUIConfig()
|
||||
|
||||
|
||||
class ImageConfig(BaseModel):
|
||||
class ImageConfig(ImageUIConfig):
|
||||
"""
|
||||
Sections "[image*]" in "config.txt".
|
||||
"""
|
||||
|
@ -65,7 +60,15 @@ class ImageConfig(BaseModel):
|
|||
}
|
||||
|
||||
|
||||
class CalendarConfig(BaseModel):
|
||||
class CalendarUIConfig(BaseModel):
|
||||
"""
|
||||
Configuration for how the UI displays the calendar carousel.
|
||||
"""
|
||||
|
||||
speed: int = 10000
|
||||
|
||||
|
||||
class CalendarConfig(CalendarUIConfig):
|
||||
"""
|
||||
Sections "[calendar*]" in "config.txt".
|
||||
"""
|
||||
|
@ -74,6 +77,15 @@ class CalendarConfig(BaseModel):
|
|||
aggregates: dict[str, list[str]] = {}
|
||||
|
||||
|
||||
class ServerUIConfig(BaseModel):
|
||||
"""
|
||||
Section "[server]" in "config.txt".
|
||||
"""
|
||||
|
||||
name: str = "OEKZident"
|
||||
host: str = "https://oekzident.de"
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
"""
|
||||
Main representation of "config.txt".
|
||||
|
@ -82,6 +94,7 @@ class Config(BaseModel):
|
|||
image_dir: str = "image"
|
||||
text_dir: str = "text"
|
||||
|
||||
server: ServerUIConfig = ServerUIConfig()
|
||||
ticker: TickerConfig = TickerConfig()
|
||||
image: ImageConfig = ImageConfig()
|
||||
calendar: CalendarConfig = CalendarConfig()
|
||||
|
|
|
@ -31,7 +31,7 @@ async def start_router() -> None:
|
|||
|
||||
async def get_ticker_lines() -> Iterator[str]:
|
||||
cfg = await Config.get()
|
||||
file_name = await text_unique(cfg.ticker.api.file_name)
|
||||
file_name = await text_unique(cfg.ticker.file_name)
|
||||
|
||||
ticker = await DavFile(
|
||||
f"{await text_lister.remote_path}/{file_name}",
|
||||
|
@ -52,7 +52,7 @@ async def get_ticker_content_lines(
|
|||
return (
|
||||
line
|
||||
for line in ticker_lines
|
||||
if not line.startswith(cfg.ticker.api.comment_marker)
|
||||
if not line.startswith(cfg.ticker.comment_marker)
|
||||
)
|
||||
|
||||
|
||||
|
@ -60,7 +60,7 @@ async def get_ticker_content(
|
|||
ticker_content_lines: Iterator[str] = Depends(get_ticker_content_lines),
|
||||
) -> str:
|
||||
cfg = await Config.get()
|
||||
ticker_content = cfg.ticker.api.separator.join(
|
||||
ticker_content = cfg.ticker.separator.join(
|
||||
["", *ticker_content_lines, ""],
|
||||
)
|
||||
|
||||
|
@ -88,4 +88,4 @@ async def get_raw_ticker(
|
|||
async def get_ui_config(
|
||||
cfg: Config = Depends(Config.get),
|
||||
) -> TickerUIConfig:
|
||||
return cfg.ticker.ui
|
||||
return cfg.ticker
|
||||
|
|
Loading…
Reference in a new issue