Less dodgy debug/version handling

This commit is contained in:
2023-10-03 23:48:52 +00:00
parent c87abb506d
commit 9d1bab6a07
4 changed files with 24 additions and 16 deletions

View File

@ -16,9 +16,9 @@ accept_entries = True
@app.route("/") @app.route("/")
def home(): def home():
if basic_auth.authenticate(): 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: 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") @app.route("/favicon.ico")
@ -67,14 +67,14 @@ def enqueue():
@app.route("/list") @app.route("/list")
def songlist(): 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") @app.route("/settings")
@nocache @nocache
@basic_auth.required @basic_auth.required
def settings(): 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']) @app.route("/settings", methods=['POST'])
@ -109,7 +109,7 @@ def settings_post():
if changed_credentials: if changed_credentials:
return redirect("/") return redirect("/")
else: 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") @app.route("/api/queue")
@ -123,7 +123,7 @@ def queue_json():
@nocache @nocache
@basic_auth.required @basic_auth.required
def played_list(): 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") @app.route("/api/songs")

View File

@ -1,5 +1,6 @@
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
import subprocess
import os import os
import uuid import uuid
from flask import make_response, Flask from flask import make_response, Flask
@ -34,17 +35,14 @@ def check_config_exists():
def load_version(app: Flask): 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"): if os.environ.get("SOURCE_VERSION"):
app.config['VERSION'] = os.environ.get("SOURCE_VERSION")[0:7] # type: ignore # noqa: E501 app.config['VERSION'] = os.environ.get("SOURCE_VERSION")[0:7] # type: ignore # noqa: E501
elif os.path.isfile(".version"): return
with open('.version', 'r') as file:
data = file.read().replace('\n', '')
if data:
app.config['VERSION'] = data
else:
app.config['VERSION'] = ""
else: else:
app.config['VERSION'] = "" app.config['VERSION'] = "Unknown"
def load_dbconfig(app: Flask): def load_dbconfig(app: Flask):

View File

@ -178,6 +178,16 @@ pre {
height: 1.5rem; height: 1.5rem;
} }
.construction_bg {
background: repeating-linear-gradient(
45deg,
#222200,
#222200 10px,
#000000 10px,
#000000 20px
);
}
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
:root { :root {
/* Navbar */ /* Navbar */

View File

@ -40,7 +40,7 @@
<body> <body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top"> <nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top {% if debug %} construction_bg {% endif %}">
<a class="navbar-brand" href="/">KaraoQueue</a> <a class="navbar-brand" href="/">KaraoQueue</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault"
aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation"> aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
@ -76,7 +76,7 @@
</main><!-- /.container --> </main><!-- /.container -->
</div> </div>
<!-- Footer --> <!-- Footer -->
<footer class="footer"> <footer class="footer {% if debug %} construction_bg {% endif %}">
<div class="container text-center py-3"> <div class="container text-center py-3">
{% if not auth %} {% if not auth %}
<a href="/login" class="ml-1 mr-1"><i class="fas fa-sign-in-alt mr-1"></i><span>Login</span></a> <a href="/login" class="ml-1 mr-1"><i class="fas fa-sign-in-alt mr-1"></i><span>Login</span></a>