fix: dynamically load theme from API endpoint (#2688)

* dynamically load theme from API endpoint

* add documentation
This commit is contained in:
Hayden
2023-10-26 22:09:22 -05:00
committed by GitHub
parent 18b7e3ac9a
commit 75e95817a3
6 changed files with 132 additions and 5 deletions

View File

@@ -3,6 +3,8 @@ from pathlib import Path
from pydantic import BaseSettings, NoneStr, validator
from mealie.core.settings.themes import Theme
from .db_providers import AbstractDBProvider, db_provider_factory
@@ -23,6 +25,8 @@ def determine_secrets(data_dir: Path, production: bool) -> str:
class AppSettings(BaseSettings):
theme: Theme = Theme()
PRODUCTION: bool
BASE_URL: str = "http://localhost:8080"
"""trailing slashes are trimmed (ex. `http://localhost:8080/` becomes ``http://localhost:8080`)"""

View File

@@ -0,0 +1,22 @@
from pydantic import BaseSettings
class Theme(BaseSettings):
light_primary: str = "#E58325"
light_accent: str = "#007A99"
light_secondary: str = "#973542"
light_success: str = "#43A047"
light_info: str = "#1976D2"
light_warning: str = "#FF6D00"
light_error: str = "#EF5350"
dark_primary: str = "#E58325"
dark_accent: str = "#007A99"
dark_secondary: str = "#973542"
dark_success: str = "#43A047"
dark_info: str = "#1976D2"
dark_warning: str = "#FF6D00"
dark_error: str = "#EF5350"
class Config:
env_prefix = "theme_"

View File

@@ -1,8 +1,8 @@
from fastapi import APIRouter
from fastapi import APIRouter, Response
from mealie.core.config import get_app_settings
from mealie.core.settings.static import APP_VERSION
from mealie.schema.admin.about import AppInfo
from mealie.schema.admin.about import AppInfo, AppTheme
router = APIRouter(prefix="/about")
@@ -18,3 +18,12 @@ def get_app_info():
production=settings.PRODUCTION,
allow_signup=settings.ALLOW_SIGNUP,
)
@router.get("/theme", response_model=AppTheme)
def get_app_theme(resp: Response):
"""Get's the current theme settings"""
settings = get_app_settings()
resp.headers["Cache-Control"] = "public, max-age=604800"
return AppTheme(**settings.theme.dict())

View File

@@ -16,6 +16,24 @@ class AppInfo(MealieModel):
allow_signup: bool
class AppTheme(MealieModel):
light_primary: str = "#E58325"
light_accent: str = "#007A99"
light_secondary: str = "#973542"
light_success: str = "#43A047"
light_info: str = "#1976D2"
light_warning: str = "#FF6D00"
light_error: str = "#EF5350"
dark_primary: str = "#E58325"
dark_accent: str = "#007A99"
dark_secondary: str = "#973542"
dark_success: str = "#43A047"
dark_info: str = "#1976D2"
dark_warning: str = "#FF6D00"
dark_error: str = "#EF5350"
class AdminAboutInfo(AppInfo):
versionLatest: str
api_port: int