diff --git a/backend/config.py b/backend/config.py index 7285edf6c..33e5a25be 100644 --- a/backend/config.py +++ b/backend/config.py @@ -1,10 +1,12 @@ from dotenv import load_dotenv, find_dotenv from pymongo import MongoClient +from constants import ERROR_MESSAGES from secrets import token_bytes from base64 import b64encode import os + load_dotenv(find_dotenv()) #################################### @@ -35,23 +37,30 @@ WEBUI_VERSION = os.environ.get("WEBUI_VERSION", "v1.0.0-alpha.11") # WEBUI_AUTH #################################### + WEBUI_AUTH = True if os.environ.get("WEBUI_AUTH", "TRUE") == "TRUE" else False -if WEBUI_AUTH: - #################################### - # WEBUI_DB - #################################### +#################################### +# WEBUI_DB +#################################### - WEBUI_DB_URL = os.environ.get( - "WEBUI_DB_URL", "mongodb://root:root@localhost:27017/" - ) - DB_CLIENT = MongoClient(f"{WEBUI_DB_URL}?authSource=admin") - DB = DB_CLIENT["ollama-webui"] +WEBUI_DB_URL = os.environ.get("WEBUI_DB_URL", "mongodb://root:root@localhost:27017/") - #################################### - # WEBUI_JWT_SECRET_KEY - #################################### +if WEBUI_AUTH and WEBUI_DB_URL == "": + raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND) - WEBUI_JWT_SECRET_KEY = os.environ.get("WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t") + +DB_CLIENT = MongoClient(f"{WEBUI_DB_URL}?authSource=admin") +DB = DB_CLIENT["ollama-webui"] + + +#################################### +# WEBUI_JWT_SECRET_KEY +#################################### + +WEBUI_JWT_SECRET_KEY = os.environ.get("WEBUI_JWT_SECRET_KEY", "t0p-s3cr3t") + +if WEBUI_AUTH and WEBUI_JWT_SECRET_KEY == "": + raise ValueError(ERROR_MESSAGES.ENV_VAR_NOT_FOUND) diff --git a/backend/constants.py b/backend/constants.py index 50c767220..c0528129b 100644 --- a/backend/constants.py +++ b/backend/constants.py @@ -6,7 +6,11 @@ class MESSAGES(str, Enum): class ERROR_MESSAGES(str, Enum): + def __str__(self) -> str: + return super().__str__() + DEFAULT = lambda err="": f"Something went wrong :/\n{err if err else ''}" + ENV_VAR_NOT_FOUND = "Essential environment variable not found. Terminating now." INVALID_TOKEN = ( "Your session has expired or the token is invalid. Please sign in again." ) diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index bf681316d..fc29651af 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -330,7 +330,7 @@ /> {:else} User profile diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 53e6aa0d9..1980a552e 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -1,6 +1,9 @@