From 9d1bab6a0773653d760954bdf46590047e407a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Phillip=20K=C3=BChne?= Date: Tue, 3 Oct 2023 23:48:52 +0000 Subject: [PATCH] Less dodgy debug/version handling --- backend/app.py | 12 ++++++------ backend/helpers.py | 14 ++++++-------- backend/static/css/style.css | 10 ++++++++++ backend/templates/base.html | 4 ++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/backend/app.py b/backend/app.py index e117ea1..263dbb4 100644 --- a/backend/app.py +++ b/backend/app.py @@ -16,9 +16,9 @@ accept_entries = True @app.route("/") def home(): if basic_auth.authenticate(): - return render_template('main_admin.html', list=database.get_list(), auth=basic_auth.authenticate()) + return render_template('main_admin.html', list=database.get_list(), auth=basic_auth.authenticate(), debug=app.config['DEBUG']) else: - return render_template('main.html', list=database.get_list(), auth=basic_auth.authenticate()) + return render_template('main.html', list=database.get_list(), auth=basic_auth.authenticate(), debug=app.config['DEBUG']) @app.route("/favicon.ico") @@ -67,14 +67,14 @@ def enqueue(): @app.route("/list") def songlist(): - return render_template('songlist.html', list=database.get_song_list(), auth=basic_auth.authenticate()) + return render_template('songlist.html', list=database.get_song_list(), auth=basic_auth.authenticate(), debug=app.config['DEBUG']) @app.route("/settings") @nocache @basic_auth.required def settings(): - return render_template('settings.html', app=app, auth=basic_auth.authenticate(), themes=helpers.get_themes()) + return render_template('settings.html', app=app, auth=basic_auth.authenticate(), themes=helpers.get_themes(), debug=app.config['DEBUG']) @app.route("/settings", methods=['POST']) @@ -109,7 +109,7 @@ def settings_post(): if changed_credentials: return redirect("/") else: - return render_template('settings.html', app=app, auth=basic_auth.authenticate(), themes=helpers.get_themes()) + return render_template('settings.html', app=app, auth=basic_auth.authenticate(), themes=helpers.get_themes(), debug=app.config['DEBUG']) @app.route("/api/queue") @@ -123,7 +123,7 @@ def queue_json(): @nocache @basic_auth.required def played_list(): - return render_template('played_list.html', list=database.get_played_list(), auth=basic_auth.authenticate()) + return render_template('played_list.html', list=database.get_played_list(), auth=basic_auth.authenticate(), debug=app.config['DEBUG']) @app.route("/api/songs") diff --git a/backend/helpers.py b/backend/helpers.py index 9e3cde4..408785a 100644 --- a/backend/helpers.py +++ b/backend/helpers.py @@ -1,5 +1,6 @@ import requests from bs4 import BeautifulSoup +import subprocess import os import uuid from flask import make_response, Flask @@ -34,17 +35,14 @@ def check_config_exists(): def load_version(app: Flask): + if app.config['DEBUG'] is True: + app.config['VERSION'] = subprocess.Popen("echo \"$(git rev-parse --abbrev-ref HEAD)-$(git describe)\"", shell=True, stdout=subprocess.PIPE).stdout.read().decode('utf-8').strip() + " (debug)" # noqa: E501 # type: ignore + return if os.environ.get("SOURCE_VERSION"): app.config['VERSION'] = os.environ.get("SOURCE_VERSION")[0:7] # type: ignore # noqa: E501 - elif os.path.isfile(".version"): - with open('.version', 'r') as file: - data = file.read().replace('\n', '') - if data: - app.config['VERSION'] = data - else: - app.config['VERSION'] = "" + return else: - app.config['VERSION'] = "" + app.config['VERSION'] = "Unknown" def load_dbconfig(app: Flask): diff --git a/backend/static/css/style.css b/backend/static/css/style.css index fc4db29..b58490d 100644 --- a/backend/static/css/style.css +++ b/backend/static/css/style.css @@ -178,6 +178,16 @@ pre { height: 1.5rem; } +.construction_bg { + background: repeating-linear-gradient( + 45deg, + #222200, + #222200 10px, + #000000 10px, + #000000 20px +); +} + @media (prefers-color-scheme: dark) { :root { /* Navbar */ diff --git a/backend/templates/base.html b/backend/templates/base.html index 58c2bda..20a115c 100644 --- a/backend/templates/base.html +++ b/backend/templates/base.html @@ -40,7 +40,7 @@ -