Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
304bf9d9
Commit
304bf9d9
authored
Apr 09, 2024
by
shivaraj-bh
Browse files
feat: configurable `STATIC_DIR`; fix: mount `CACHE_DIR` to the `/cache` endpoint
parent
331fe04d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
20 deletions
+25
-20
backend/config.py
backend/config.py
+21
-15
backend/main.py
backend/main.py
+4
-5
No files found.
backend/config.py
View file @
304bf9d9
...
@@ -28,8 +28,6 @@ except ImportError:
...
@@ -28,8 +28,6 @@ except ImportError:
WEBUI_NAME
=
os
.
environ
.
get
(
"WEBUI_NAME"
,
"Open WebUI"
)
WEBUI_NAME
=
os
.
environ
.
get
(
"WEBUI_NAME"
,
"Open WebUI"
)
WEBUI_FAVICON_URL
=
"https://openwebui.com/favicon.png"
WEBUI_FAVICON_URL
=
"https://openwebui.com/favicon.png"
shutil
.
copyfile
(
"../build/favicon.png"
,
"./static/favicon.png"
)
####################################
####################################
# ENV (dev,test,prod)
# ENV (dev,test,prod)
####################################
####################################
...
@@ -103,6 +101,26 @@ for version in soup.find_all("h2"):
...
@@ -103,6 +101,26 @@ for version in soup.find_all("h2"):
CHANGELOG
=
changelog_json
CHANGELOG
=
changelog_json
####################################
# DATA/FRONTEND BUILD DIR
####################################
DATA_DIR
=
str
(
Path
(
os
.
getenv
(
"DATA_DIR"
,
"./data"
)).
resolve
())
FRONTEND_BUILD_DIR
=
str
(
Path
(
os
.
getenv
(
"FRONTEND_BUILD_DIR"
,
"../build"
)))
try
:
with
open
(
f
"
{
DATA_DIR
}
/config.json"
,
"r"
)
as
f
:
CONFIG_DATA
=
json
.
load
(
f
)
except
:
CONFIG_DATA
=
{}
####################################
# Static DIR
####################################
STATIC_DIR
=
str
(
Path
(
os
.
getenv
(
"STATIC_DIR"
,
"./static"
)).
resolve
())
shutil
.
copyfile
(
f
"
{
FRONTEND_BUILD_DIR
}
/favicon.png"
,
f
"
{
STATIC_DIR
}
/favicon.png"
)
####################################
####################################
# LOGGING
# LOGGING
...
@@ -165,7 +183,7 @@ if CUSTOM_NAME:
...
@@ -165,7 +183,7 @@ if CUSTOM_NAME:
r
=
requests
.
get
(
url
,
stream
=
True
)
r
=
requests
.
get
(
url
,
stream
=
True
)
if
r
.
status_code
==
200
:
if
r
.
status_code
==
200
:
with
open
(
"./static
/favicon.png"
,
"wb"
)
as
f
:
with
open
(
f
"
{
STATIC_DIR
}
/favicon.png"
,
"wb"
)
as
f
:
r
.
raw
.
decode_content
=
True
r
.
raw
.
decode_content
=
True
shutil
.
copyfileobj
(
r
.
raw
,
f
)
shutil
.
copyfileobj
(
r
.
raw
,
f
)
...
@@ -177,18 +195,6 @@ else:
...
@@ -177,18 +195,6 @@ else:
if
WEBUI_NAME
!=
"Open WebUI"
:
if
WEBUI_NAME
!=
"Open WebUI"
:
WEBUI_NAME
+=
" (Open WebUI)"
WEBUI_NAME
+=
" (Open WebUI)"
####################################
# DATA/FRONTEND BUILD DIR
####################################
DATA_DIR
=
str
(
Path
(
os
.
getenv
(
"DATA_DIR"
,
"./data"
)).
resolve
())
FRONTEND_BUILD_DIR
=
str
(
Path
(
os
.
getenv
(
"FRONTEND_BUILD_DIR"
,
"../build"
)))
try
:
with
open
(
f
"
{
DATA_DIR
}
/config.json"
,
"r"
)
as
f
:
CONFIG_DATA
=
json
.
load
(
f
)
except
:
CONFIG_DATA
=
{}
####################################
####################################
# File Upload DIR
# File Upload DIR
...
...
backend/main.py
View file @
304bf9d9
...
@@ -38,6 +38,8 @@ from config import (
...
@@ -38,6 +38,8 @@ from config import (
VERSION
,
VERSION
,
CHANGELOG
,
CHANGELOG
,
FRONTEND_BUILD_DIR
,
FRONTEND_BUILD_DIR
,
CACHE_DIR
,
STATIC_DIR
,
MODEL_FILTER_ENABLED
,
MODEL_FILTER_ENABLED
,
MODEL_FILTER_LIST
,
MODEL_FILTER_LIST
,
GLOBAL_LOG_LEVEL
,
GLOBAL_LOG_LEVEL
,
...
@@ -282,7 +284,6 @@ async def get_app_latest_release_version():
...
@@ -282,7 +284,6 @@ async def get_app_latest_release_version():
detail
=
ERROR_MESSAGES
.
RATE_LIMIT_EXCEEDED
,
detail
=
ERROR_MESSAGES
.
RATE_LIMIT_EXCEEDED
,
)
)
@
app
.
get
(
"/manifest.json"
)
@
app
.
get
(
"/manifest.json"
)
async
def
get_manifest_json
():
async
def
get_manifest_json
():
return
{
return
{
...
@@ -296,10 +297,8 @@ async def get_manifest_json():
...
@@ -296,10 +297,8 @@ async def get_manifest_json():
"icons"
:
[{
"src"
:
"/favicon.png"
,
"type"
:
"image/png"
,
"sizes"
:
"844x884"
}],
"icons"
:
[{
"src"
:
"/favicon.png"
,
"type"
:
"image/png"
,
"sizes"
:
"844x884"
}],
}
}
app
.
mount
(
"/static"
,
StaticFiles
(
directory
=
STATIC_DIR
),
name
=
"static"
)
app
.
mount
(
"/static"
,
StaticFiles
(
directory
=
"static"
),
name
=
"static"
)
app
.
mount
(
"/cache"
,
StaticFiles
(
directory
=
CACHE_DIR
),
name
=
"cache"
)
app
.
mount
(
"/cache"
,
StaticFiles
(
directory
=
"data/cache"
),
name
=
"cache"
)
app
.
mount
(
app
.
mount
(
"/"
,
"/"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment