From 83ad488e314dff5c0eceb700221c4374229b31e9 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Tue, 2 Apr 2024 15:55:00 -0300 Subject: [PATCH 1/4] Do not use hardcoded manifest.json Generate manifest.json dynamically, using MANIFEST_NAME and MANIFEST_SHORT_NAME from the environment. --- .env.example | 5 ++++- Dockerfile | 3 +++ backend/config.py | 8 ++++++++ backend/main.py | 24 ++++++++++++++++++++++++ static/manifest.json | 16 ---------------- 5 files changed, 39 insertions(+), 17 deletions(-) delete mode 100644 static/manifest.json diff --git a/.env.example b/.env.example index 3d2aafc09..689d5a19a 100644 --- a/.env.example +++ b/.env.example @@ -9,4 +9,7 @@ OPENAI_API_KEY='' # DO NOT TRACK SCARF_NO_ANALYTICS=true -DO_NOT_TRACK=true \ No newline at end of file +DO_NOT_TRACK=true + +MANIFEST_NAME='Open WebUI' +MANIFEST_SHORT_NAME='Open WebUI' diff --git a/Dockerfile b/Dockerfile index de501838f..87820311b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,9 @@ ENV WEBUI_SECRET_KEY "" ENV SCARF_NO_ANALYTICS true ENV DO_NOT_TRACK true +ENV MANIFEST_NAME "Open WebUI" +ENV MANIFEST_SHORT_NAME "Open WebUI" + ######## Preloaded models ######## # whisper TTS Settings ENV WHISPER_MODEL="base" diff --git a/backend/config.py b/backend/config.py index 04778f9f0..df1d024cf 100644 --- a/backend/config.py +++ b/backend/config.py @@ -424,3 +424,11 @@ WHISPER_MODEL_DIR = os.getenv("WHISPER_MODEL_DIR", f"{CACHE_DIR}/whisper/models" AUTOMATIC1111_BASE_URL = os.getenv("AUTOMATIC1111_BASE_URL", "") COMFYUI_BASE_URL = os.getenv("COMFYUI_BASE_URL", "") + + +#################################### +# Manifest +#################################### + +MANIFEST_NAME = os.getenv("MANIFEST_NAME", "Open WebUI") +MANIFEST_SHORT_NAME = os.getenv("MANIFEST_SHORT_NAME", "Open WebUI") diff --git a/backend/main.py b/backend/main.py index 8cc704a26..7307b54ff 100644 --- a/backend/main.py +++ b/backend/main.py @@ -43,6 +43,8 @@ from config import ( GLOBAL_LOG_LEVEL, SRC_LOG_LEVELS, WEBHOOK_URL, + MANIFEST_NAME, + MANIFEST_SHORT_NAME ) from constants import ERROR_MESSAGES @@ -69,6 +71,8 @@ app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST app.state.WEBHOOK_URL = WEBHOOK_URL +app.state.MANIFEST_NAME = MANIFEST_NAME +app.state.MANIFEST_SHORT_NAME = MANIFEST_SHORT_NAME origins = ["*"] @@ -268,6 +272,26 @@ async def get_app_latest_release_version(): ) +@app.get("/manifest.json") +async def get_manifest_json(): + return { + "name": app.state.MANIFEST_NAME, + "short_name": app.state.MANIFEST_SHORT_NAME, + "start_url": "/", + "display": "standalone", + "background_color": "#343541", + "theme_color": "#343541", + "orientation": "portrait-primary", + "icons": [ + { + "src": "/favicon.png", + "type": "image/png", + "sizes": "844x884" + } + ] + } + + app.mount("/static", StaticFiles(directory="static"), name="static") app.mount("/cache", StaticFiles(directory="data/cache"), name="cache") diff --git a/static/manifest.json b/static/manifest.json deleted file mode 100644 index ee019bd90..000000000 --- a/static/manifest.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "Open WebUI", - "short_name": "Open WebUI", - "start_url": "/", - "display": "standalone", - "background_color": "#343541", - "theme_color": "#343541", - "orientation": "portrait-primary", - "icons": [ - { - "src": "/favicon.png", - "type": "image/png", - "sizes": "844x884" - } - ] -} From c89070797c1883761aa0e1b41853a9924535b436 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 3 Apr 2024 20:43:55 -0700 Subject: [PATCH 2/4] refac --- .env.example | 5 +---- backend/config.py | 8 -------- backend/main.py | 17 +++-------------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/.env.example b/.env.example index 689d5a19a..3d2aafc09 100644 --- a/.env.example +++ b/.env.example @@ -9,7 +9,4 @@ OPENAI_API_KEY='' # DO NOT TRACK SCARF_NO_ANALYTICS=true -DO_NOT_TRACK=true - -MANIFEST_NAME='Open WebUI' -MANIFEST_SHORT_NAME='Open WebUI' +DO_NOT_TRACK=true \ No newline at end of file diff --git a/backend/config.py b/backend/config.py index df1d024cf..04778f9f0 100644 --- a/backend/config.py +++ b/backend/config.py @@ -424,11 +424,3 @@ WHISPER_MODEL_DIR = os.getenv("WHISPER_MODEL_DIR", f"{CACHE_DIR}/whisper/models" AUTOMATIC1111_BASE_URL = os.getenv("AUTOMATIC1111_BASE_URL", "") COMFYUI_BASE_URL = os.getenv("COMFYUI_BASE_URL", "") - - -#################################### -# Manifest -#################################### - -MANIFEST_NAME = os.getenv("MANIFEST_NAME", "Open WebUI") -MANIFEST_SHORT_NAME = os.getenv("MANIFEST_SHORT_NAME", "Open WebUI") diff --git a/backend/main.py b/backend/main.py index 7307b54ff..9494a112f 100644 --- a/backend/main.py +++ b/backend/main.py @@ -43,8 +43,6 @@ from config import ( GLOBAL_LOG_LEVEL, SRC_LOG_LEVELS, WEBHOOK_URL, - MANIFEST_NAME, - MANIFEST_SHORT_NAME ) from constants import ERROR_MESSAGES @@ -71,9 +69,6 @@ app.state.MODEL_FILTER_LIST = MODEL_FILTER_LIST app.state.WEBHOOK_URL = WEBHOOK_URL -app.state.MANIFEST_NAME = MANIFEST_NAME -app.state.MANIFEST_SHORT_NAME = MANIFEST_SHORT_NAME - origins = ["*"] @@ -275,20 +270,14 @@ async def get_app_latest_release_version(): @app.get("/manifest.json") async def get_manifest_json(): return { - "name": app.state.MANIFEST_NAME, - "short_name": app.state.MANIFEST_SHORT_NAME, + "name": WEBUI_NAME, + "short_name": WEBUI_NAME, "start_url": "/", "display": "standalone", "background_color": "#343541", "theme_color": "#343541", "orientation": "portrait-primary", - "icons": [ - { - "src": "/favicon.png", - "type": "image/png", - "sizes": "844x884" - } - ] + "icons": [{"src": "/favicon.png", "type": "image/png", "sizes": "844x884"}], } From 21132420d89a2f9d060a485b7985f64ee55fd3ac Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 3 Apr 2024 20:44:18 -0700 Subject: [PATCH 3/4] Update Dockerfile --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87820311b..de501838f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,9 +30,6 @@ ENV WEBUI_SECRET_KEY "" ENV SCARF_NO_ANALYTICS true ENV DO_NOT_TRACK true -ENV MANIFEST_NAME "Open WebUI" -ENV MANIFEST_SHORT_NAME "Open WebUI" - ######## Preloaded models ######## # whisper TTS Settings ENV WHISPER_MODEL="base" From 8caad59cb4f38b5e75ac496aa0c3a83bed7d884e Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 3 Apr 2024 20:45:23 -0700 Subject: [PATCH 4/4] feat: allow webui name customisation --- backend/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/config.py b/backend/config.py index 04778f9f0..dfbbad2a8 100644 --- a/backend/config.py +++ b/backend/config.py @@ -25,7 +25,7 @@ try: except ImportError: log.warning("dotenv not installed, skipping...") -WEBUI_NAME = "Open WebUI" +WEBUI_NAME = os.environ.get("WEBUI_NAME", "Open WebUI") WEBUI_FAVICON_URL = "https://openwebui.com/favicon.png" shutil.copyfile("../build/favicon.png", "./static/favicon.png")