updated editors + new parameter in service file
This commit is contained in:
+41
-11
@@ -11,6 +11,21 @@ from app.utils.helpers import load_configs, load_default_sounds, load_soundboard
|
||||
admin_bp = Blueprint('admin', __name__)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _list_sound_files(subdir=None):
|
||||
sound_dir = current_app.config['SOUNDS_DIR']
|
||||
search_dir = os.path.join(sound_dir, subdir) if subdir else sound_dir
|
||||
extensions = {'.mp3', '.ogg', '.wav', '.flac'}
|
||||
files = []
|
||||
if not os.path.isdir(search_dir):
|
||||
return files
|
||||
for root, _, filenames in os.walk(search_dir):
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1].lower() in extensions:
|
||||
full_path = os.path.join(root, filename)
|
||||
files.append(os.path.relpath(full_path, search_dir))
|
||||
return sorted(files, key=str.lower)
|
||||
|
||||
@admin_bp.route('/')
|
||||
def admin():
|
||||
configs = load_configs()
|
||||
@@ -33,7 +48,7 @@ def admin_edit_config(filename):
|
||||
raise ValueError("Kein Inhalt übermittelt")
|
||||
|
||||
# Validierung: versuche zu parsen
|
||||
json.loads(new_content)
|
||||
config_data = json.loads(new_content)
|
||||
|
||||
with open(path, 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
@@ -49,9 +64,14 @@ def admin_edit_config(filename):
|
||||
error_msg = f"Fehler beim Speichern: {str(e)}"
|
||||
|
||||
# Bei Fehler: zurück zum Formular mit Fehlermeldung
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
return render_template('admin_edit.html', filename=filename, content=content, error=error_msg)
|
||||
content = request.form.get('config_content', '')
|
||||
try:
|
||||
config_data = json.loads(content)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
config_data = {}
|
||||
return render_template('admin_edit.html', filename=filename, content=content,
|
||||
config_data=config_data, sound_files=_list_sound_files(),
|
||||
error=error_msg)
|
||||
|
||||
# GET: Formular laden
|
||||
if not os.path.exists(path):
|
||||
@@ -59,9 +79,9 @@ def admin_edit_config(filename):
|
||||
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
return render_template('admin_edit.html', filename=filename, content=content)
|
||||
pass
|
||||
config_data = json.loads(content)
|
||||
return render_template('admin_edit.html', filename=filename, content=content,
|
||||
config_data=config_data, sound_files=_list_sound_files())
|
||||
|
||||
|
||||
@admin_bp.route('/theme/edit/<path:filename>', methods=['GET', 'POST'])
|
||||
@@ -87,15 +107,25 @@ def admin_edit_theme(filename):
|
||||
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)
|
||||
content = request.form.get('config_content', '')
|
||||
try:
|
||||
theme_data = json.loads(content)
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
theme_data = {}
|
||||
theme_sound_dir = os.path.dirname(filename)
|
||||
return render_template('admin_edit_theme.html', filename=filename, content=content,
|
||||
theme_data=theme_data, sound_files=_list_sound_files(theme_sound_dir),
|
||||
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)
|
||||
theme_data = json.loads(content)
|
||||
theme_sound_dir = os.path.dirname(filename)
|
||||
return render_template('admin_edit_theme.html', filename=filename, content=content,
|
||||
theme_data=theme_data, sound_files=_list_sound_files(theme_sound_dir),
|
||||
theme_sound_dir=theme_sound_dir)
|
||||
|
||||
@admin_bp.route('/delete/<filename>', methods=['POST'])
|
||||
def admin_delete_config(filename):
|
||||
|
||||
Reference in New Issue
Block a user