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__)
|
_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"
|
file_name: str = "ticker"
|
||||||
|
@ -30,30 +38,17 @@ class TickerAPIConfig(BaseModel):
|
||||||
comment_marker: str = "#"
|
comment_marker: str = "#"
|
||||||
|
|
||||||
|
|
||||||
class TickerUIConfig(BaseModel):
|
class ImageUIConfig(BaseModel):
|
||||||
"""
|
"""
|
||||||
Section "[ticker.ui]" in "config.txt".
|
Configuration for how the UI displays the image carousel.
|
||||||
|
|
||||||
Configuration for how the UI displays the ticker content.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
display: bool = True
|
height: int = 300
|
||||||
color: str = "primary"
|
contain: bool = False
|
||||||
speed: int = 30
|
speed: int = 10000
|
||||||
|
|
||||||
|
|
||||||
class TickerConfig(BaseModel):
|
class ImageConfig(ImageUIConfig):
|
||||||
"""
|
|
||||||
Section "[ticker]" in "config.txt".
|
|
||||||
|
|
||||||
Combined configuration for the ticker.
|
|
||||||
"""
|
|
||||||
|
|
||||||
api: TickerAPIConfig = TickerAPIConfig()
|
|
||||||
ui: TickerUIConfig = TickerUIConfig()
|
|
||||||
|
|
||||||
|
|
||||||
class ImageConfig(BaseModel):
|
|
||||||
"""
|
"""
|
||||||
Sections "[image*]" in "config.txt".
|
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".
|
Sections "[calendar*]" in "config.txt".
|
||||||
"""
|
"""
|
||||||
|
@ -74,6 +77,15 @@ class CalendarConfig(BaseModel):
|
||||||
aggregates: dict[str, list[str]] = {}
|
aggregates: dict[str, list[str]] = {}
|
||||||
|
|
||||||
|
|
||||||
|
class ServerUIConfig(BaseModel):
|
||||||
|
"""
|
||||||
|
Section "[server]" in "config.txt".
|
||||||
|
"""
|
||||||
|
|
||||||
|
name: str = "OEKZident"
|
||||||
|
host: str = "https://oekzident.de"
|
||||||
|
|
||||||
|
|
||||||
class Config(BaseModel):
|
class Config(BaseModel):
|
||||||
"""
|
"""
|
||||||
Main representation of "config.txt".
|
Main representation of "config.txt".
|
||||||
|
@ -82,6 +94,7 @@ class Config(BaseModel):
|
||||||
image_dir: str = "image"
|
image_dir: str = "image"
|
||||||
text_dir: str = "text"
|
text_dir: str = "text"
|
||||||
|
|
||||||
|
server: ServerUIConfig = ServerUIConfig()
|
||||||
ticker: TickerConfig = TickerConfig()
|
ticker: TickerConfig = TickerConfig()
|
||||||
image: ImageConfig = ImageConfig()
|
image: ImageConfig = ImageConfig()
|
||||||
calendar: CalendarConfig = CalendarConfig()
|
calendar: CalendarConfig = CalendarConfig()
|
||||||
|
|
|
@ -31,7 +31,7 @@ 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 Config.get()
|
||||||
file_name = await text_unique(cfg.ticker.api.file_name)
|
file_name = await text_unique(cfg.ticker.file_name)
|
||||||
|
|
||||||
ticker = await DavFile(
|
ticker = await DavFile(
|
||||||
f"{await text_lister.remote_path}/{file_name}",
|
f"{await text_lister.remote_path}/{file_name}",
|
||||||
|
@ -52,7 +52,7 @@ async def get_ticker_content_lines(
|
||||||
return (
|
return (
|
||||||
line
|
line
|
||||||
for line in ticker_lines
|
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),
|
ticker_content_lines: Iterator[str] = Depends(get_ticker_content_lines),
|
||||||
) -> str:
|
) -> str:
|
||||||
cfg = await Config.get()
|
cfg = await Config.get()
|
||||||
ticker_content = cfg.ticker.api.separator.join(
|
ticker_content = cfg.ticker.separator.join(
|
||||||
["", *ticker_content_lines, ""],
|
["", *ticker_content_lines, ""],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -88,4 +88,4 @@ async def get_raw_ticker(
|
||||||
async def get_ui_config(
|
async def get_ui_config(
|
||||||
cfg: Config = Depends(Config.get),
|
cfg: Config = Depends(Config.get),
|
||||||
) -> TickerUIConfig:
|
) -> TickerUIConfig:
|
||||||
return cfg.ticker.ui
|
return cfg.ticker
|
||||||
|
|
Loading…
Reference in a new issue