added theme editor
This commit is contained in:
parent
4340a58450
commit
a027cf8c1c
@ -59,6 +59,40 @@ def admin_edit_config(filename):
|
|||||||
return render_template('admin_edit.html', filename=filename, content=content)
|
return render_template('admin_edit.html', filename=filename, content=content)
|
||||||
pass
|
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'])
|
@admin_bp.route('/delete/<filename>', methods=['POST'])
|
||||||
def admin_delete_config(filename):
|
def admin_delete_config(filename):
|
||||||
path = os.path.join(current_app.config['CONFIG_DIR'], filename)
|
path = os.path.join(current_app.config['CONFIG_DIR'], filename)
|
||||||
|
|||||||
@ -71,6 +71,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Datei</th>
|
<th>Datei</th>
|
||||||
|
<th>Aktionen</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -78,6 +79,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ sb.name }}</td>
|
<td>{{ sb.name }}</td>
|
||||||
<td><code>{{ sb.filename }}</code></td>
|
<td><code>{{ sb.filename }}</code></td>
|
||||||
|
<td>
|
||||||
|
<a href="{{ url_for('admin.admin_edit_theme', filename=sb.filename) }}"
|
||||||
|
class="btn btn-sm btn-primary">
|
||||||
|
<i class="bi bi-pencil"></i> Bearbeiten
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
48
templates/admin_edit_theme.html
Normal file
48
templates/admin_edit_theme.html
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Bearbeite Theme {{ filename }}{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container my-5">
|
||||||
|
<h1>Bearbeite Soundboard-Theme</h1>
|
||||||
|
<h4 class="text-muted mb-4">{{ filename }}</h4>
|
||||||
|
|
||||||
|
{% if error %}
|
||||||
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||||
|
{{ error }}
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="config_content" class="form-label">JSON-Inhalt (Theme):</label>
|
||||||
|
<textarea class="form-control font-monospace" id="config_content" name="config_content" rows="24">{{ content }}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="d-flex gap-3">
|
||||||
|
<button type="submit" class="btn btn-primary btn-lg px-5">Speichern</button>
|
||||||
|
<a href="{{ url_for('admin.admin') }}" class="btn btn-outline-secondary btn-lg px-5">Abbrechen</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
<h5>Beispielstruktur (Theme)</h5>
|
||||||
|
<pre class="bg-light p-3 rounded">
|
||||||
|
{
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user