diff --git a/app/routes/admin.py b/app/routes/admin.py index 2689337..827bbbc 100644 --- a/app/routes/admin.py +++ b/app/routes/admin.py @@ -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/', 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/', methods=['POST']) def admin_delete_config(filename): path = os.path.join(current_app.config['CONFIG_DIR'], filename) diff --git a/templates/admin.html b/templates/admin.html index 5dc2b03..e3ba454 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -71,6 +71,7 @@ Name Datei + Aktionen @@ -78,6 +79,12 @@ {{ sb.name }} {{ sb.filename }} + + + Bearbeiten + + {% endfor %} diff --git a/templates/admin_edit_theme.html b/templates/admin_edit_theme.html new file mode 100644 index 0000000..840274b --- /dev/null +++ b/templates/admin_edit_theme.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} + +{% block title %}Bearbeite Theme {{ filename }}{% endblock %} + +{% block content %} +
+

Bearbeite Soundboard-Theme

+

{{ filename }}

+ + {% if error %} + + {% endif %} + +
+
+ + +
+
+ + Abbrechen +
+
+ +
+
Beispielstruktur (Theme)
+
+{
+  "name": "Wilder Westen",
+  "backgrounds": [
+    {"id": "wind", "file": "wind.mp3", "loop": true, "channel": 0}
+  ],
+  "sounds": [
+    {"id": "pfeife", "file": "pfeife.mp3", "channel": 2}
+  ],
+  "random_pool": [
+    {"id": "durchsage1", "file": "durchsage1.mp3"}
+  ],
+  "random_limit_per_hour": 2,
+  "random_window_minutes": 60
+}
+    
+
+
+{% endblock %}