From 7f54aba4afa760b1b7a12334ff3ecfe81ed6036c Mon Sep 17 00:00:00 2001 From: lelo Date: Mon, 14 Apr 2025 21:46:31 +0000 Subject: [PATCH] extend customisation of app --- app.py | 24 ++++++++++++------------ auth.py | 19 +++++++++++++++++-- templates/app.html | 7 +++---- templates/error.html | 24 ++++++++++++++++-------- templates/index.html | 24 ++++++++++++++++-------- 5 files changed, 64 insertions(+), 34 deletions(-) diff --git a/app.py b/app.py index e5721a0..c204fc3 100755 --- a/app.py +++ b/app.py @@ -21,17 +21,17 @@ import auth import analytics as a with open("app_config.json", 'r') as file: - config = json.load(file) + app_config = json.load(file) -cache_audio = diskcache.Cache('./filecache_audio', size_limit= config['filecache_size_limit_audio'] * 1024**3) -cache_image = diskcache.Cache('./filecache_image', size_limit= config['filecache_size_limit_image'] * 1024**3) -cache_video = diskcache.Cache('./filecache_video', size_limit= config['filecache_size_limit_video'] * 1024**3) -cache_other = diskcache.Cache('./filecache_other', size_limit= config['filecache_size_limit_other'] * 1024**3) +cache_audio = diskcache.Cache('./filecache_audio', size_limit= app_config['filecache_size_limit_audio'] * 1024**3) +cache_image = diskcache.Cache('./filecache_image', size_limit= app_config['filecache_size_limit_image'] * 1024**3) +cache_video = diskcache.Cache('./filecache_video', size_limit= app_config['filecache_size_limit_video'] * 1024**3) +cache_other = diskcache.Cache('./filecache_other', size_limit= app_config['filecache_size_limit_other'] * 1024**3) app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1) -app.config['SECRET_KEY'] = config['SECRET_KEY'] +app.config['SECRET_KEY'] = app_config['SECRET_KEY'] app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=90) if os.environ.get('FLASK_ENV') == 'production': app.config['SESSION_COOKIE_SAMESITE'] = 'None' @@ -464,12 +464,12 @@ def handle_request_initial_data(): @app.route('/') @auth.require_secret def index(path): - title_short = config.get('TITLE_SHORT', 'Default Title') - title_long = config.get('TITLE_LONG' , 'Default Title') - header_color = config.get('header_color' , '#000') - header_text_color = config.get('header_text_color', '#fff') - background_color = config.get('background_color', '#fff') - main_text_color = config.get('main_text_color', '#000') + title_short = app_config.get('TITLE_SHORT', 'Default Title') + title_long = app_config.get('TITLE_LONG' , 'Default Title') + header_color = app_config.get('header_color' , '#000') + header_text_color = app_config.get('header_text_color', '#fff') + background_color = app_config.get('background_color', '#fff') + main_text_color = app_config.get('main_text_color', '#000') return render_template("app.html", title_short=title_short, title_long=title_long, diff --git a/auth.py b/auth.py index 3fa9ee6..e3ba65c 100644 --- a/auth.py +++ b/auth.py @@ -9,6 +9,9 @@ import base64 folder_config = {} +with open("app_config.json", 'r') as file: + app_config = json.load(file) + def require_secret(f): @wraps(f) def decorated_function(*args, **kwargs): @@ -79,8 +82,20 @@ def require_secret(f): session['device_id'] = os.urandom(32).hex() return f(*args, **kwargs) else: - return render_template('index.html') - + title_short = app_config.get('TITLE_SHORT', 'Default Title') + title_long = app_config.get('TITLE_LONG' , 'Default Title') + header_color = app_config.get('header_color' , '#000') + header_text_color = app_config.get('header_text_color', '#fff') + background_color = app_config.get('background_color', '#fff') + main_text_color = app_config.get('main_text_color', '#000') + return render_template('index.html', + title_short=title_short, + title_long=title_long, + header_color=header_color, + header_text_color=header_text_color, + main_text_color=main_text_color, + background_color=background_color, + ) return decorated_function @require_secret diff --git a/templates/app.html b/templates/app.html index 66c24f5..3181e86 100644 --- a/templates/app.html +++ b/templates/app.html @@ -3,15 +3,14 @@ - + - - + {{ title_short }} - + diff --git a/templates/error.html b/templates/error.html index 659cbcf..fa71daa 100644 --- a/templates/error.html +++ b/templates/error.html @@ -3,25 +3,33 @@ - + - - - + - Gottesdienste Speyer und Schwegenheim + {{ title_long }} +
-
Etwas ist schief gelaufen. Entweder ein Link ist veraltet oder die App ist gerade gestört.
Versuche den Link aus der Telegram-Gruppe erneut anklicken um dies zu beheben.
+
Etwas ist schief gelaufen. Entweder ein Link ist veraltet oder die App ist gerade gestört.
Versuche den Freigabelink erneut anzuklicken.
diff --git a/templates/index.html b/templates/index.html index 2f2accf..39197d7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,25 +3,33 @@ - + - - - + - Gottesdienste Speyer und Schwegenheim + {{ title_long }} +
-
Du hast keine gültigen Links im Speicher.
Bitte den Link aus der Telegram-Gruppe erneut anklicken.
+
Du hast keine Links die noch gültig sind.
Bitte den Freigabelink erneut anklicken.