added theme editor
This commit is contained in:
@@ -59,6 +59,40 @@ def admin_edit_config(filename):
|
||||
return render_template('admin_edit.html', filename=filename, content=content)
|
||||
pass
|
||||
|
||||
|
||||
@admin_bp.route('/theme/edit/<path:filename>', methods=['GET', 'POST'])
|
||||
def admin_edit_theme(filename):
|
||||
base = current_app.config['SOUNDBOARD_CONFIG_DIR']
|
||||
path = os.path.normpath(os.path.join(base, filename))
|
||||
if not path.startswith(os.path.abspath(base)):
|
||||
return "Ungültiger Pfad", 400
|
||||
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
new_content = request.form.get('config_content')
|
||||
if not new_content:
|
||||
raise ValueError("Kein Inhalt übermittelt")
|
||||
json.loads(new_content)
|
||||
with open(path, 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
logger.info(f"Theme {filename} erfolgreich gespeichert")
|
||||
return redirect(url_for('admin.admin'))
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"Ungültiges JSON in Theme {filename}: {e}")
|
||||
error_msg = f"Ungültiges JSON: {str(e)}"
|
||||
except Exception as e:
|
||||
logger.error(f"Speicherfehler Theme {filename}: {e}")
|
||||
error_msg = f"Fehler beim Speichern: {str(e)}"
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
return render_template('admin_edit_theme.html', filename=filename, content=content, error=error_msg)
|
||||
|
||||
if not os.path.exists(path):
|
||||
return "Theme nicht gefunden", 404
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
return render_template('admin_edit_theme.html', filename=filename, content=content)
|
||||
|
||||
@admin_bp.route('/delete/<filename>', methods=['POST'])
|
||||
def admin_delete_config(filename):
|
||||
path = os.path.join(current_app.config['CONFIG_DIR'], filename)
|
||||
|
||||
Reference in New Issue
Block a user