ui - avoid DB calls on static files

This commit is contained in:
florian 2024-05-25 21:06:24 +02:00
parent 9160bf8ce9
commit 662c332ffe
No known key found for this signature in database
GPG key ID: 93EE47CC3D061500

View file

@ -445,15 +445,17 @@ def handle_csrf_error(_):
@app.before_request
def before_request():
if not app.config["DB"].readonly:
try:
app.config["DB"].test_write()
except BaseException:
app.config["DB"].readonly = True
db_user = app.config["DB"].get_ui_user()
if db_user:
app.config["USER"] = User(**db_user)
if not request.path.startswith(("/css", "/images", "/js", "/json", "/webfonts")):
if not app.config["DB"].readonly:
try:
app.config["DB"].test_write()
except BaseException:
app.config["DB"].readonly = True
db_user = app.config["DB"].get_ui_user()
if db_user:
app.config["USER"] = User(**db_user)
app.config["SCRIPT_NONCE"] = sha256(urandom(32)).hexdigest()