From 16fa45455850a8218e0c0d63f96ff8733900318c Mon Sep 17 00:00:00 2001 From: Michael Poluektov Date: Tue, 2 Jul 2024 14:17:36 +0100 Subject: [PATCH] fix banners env --- backend/config.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/config.py b/backend/config.py index d6efde563..4a7456fd2 100644 --- a/backend/config.py +++ b/backend/config.py @@ -5,10 +5,10 @@ import importlib.metadata import pkgutil import chromadb from chromadb import Settings -from base64 import b64encode from bs4 import BeautifulSoup -from typing import TypeVar, Generic, Union +from typing import TypeVar, Generic from pydantic import BaseModel +from pydantic.error_wrappers import ValidationError from typing import Optional from pathlib import Path @@ -19,7 +19,6 @@ import markdown import requests import shutil -from secrets import token_bytes from constants import ERROR_MESSAGES #################################### @@ -768,12 +767,14 @@ class BannerModel(BaseModel): dismissible: bool timestamp: int +try: + banners = json.loads(os.environ.get("WEBUI_BANNERS", "[]")) + banners = [BannerModel(**banner) for banner in banners] +except ValidationError as e: + print(f"Error loading WEBUI_BANNERS: {e}") + banners = [] -WEBUI_BANNERS = PersistentConfig( - "WEBUI_BANNERS", - "ui.banners", - [BannerModel(**banner) for banner in json.loads("[]")], -) +WEBUI_BANNERS = PersistentConfig("WEBUI_BANNERS", "ui.banners", banners) SHOW_ADMIN_DETAILS = PersistentConfig(