fixes for new config editor

This commit is contained in:
oberon 2026-02-19 11:51:49 +01:00
parent f1f2a14ccd
commit 4340a58450
3 changed files with 58 additions and 46 deletions

View File

@ -121,55 +121,63 @@ def _slugify(name: str) -> str:
@admin_bp.route('/create_config', methods=['POST'])
def admin_create_config():
data = request.get_json() or {}
name = data.get('name') or 'Neue Lok'
hub_id = int(data.get('hub_id', 0))
hub_type = data.get('hub_type', '4channel')
image = data.get('image')
try:
data = request.get_json(force=True, silent=True) or {}
name = data.get('name') or 'Neue Lok'
hub_id = int(data.get('hub_id', 0))
hub_type = data.get('hub_type', '4channel')
image = data.get('image')
filename = _slugify(name) + '.json'
path = os.path.join(current_app.config['CONFIG_DIR'], filename)
if os.path.exists(path):
return jsonify({"success": False, "message": "Datei existiert bereits"}), 400
filename = _slugify(name) + '.json'
path = os.path.join(current_app.config['CONFIG_DIR'], filename)
if os.path.exists(path):
return jsonify({"success": False, "message": "Datei existiert bereits"}), 400
template = {
"name": name,
"image": image or "",
"hub_id": hub_id,
"hub_type": hub_type,
"channels": [],
"sounds": []
}
os.makedirs(current_app.config['CONFIG_DIR'], exist_ok=True)
with open(path, 'w', encoding='utf-8') as f:
json.dump(template, f, ensure_ascii=False, indent=2)
logger.info(f"Neue Config angelegt: {filename}")
return jsonify({"success": True, "filename": filename})
template = {
"name": name,
"image": image or "",
"hub_id": hub_id,
"hub_type": hub_type,
"channels": [],
"sounds": []
}
os.makedirs(current_app.config['CONFIG_DIR'], exist_ok=True)
with open(path, 'w', encoding='utf-8') as f:
json.dump(template, f, ensure_ascii=False, indent=2)
logger.info(f"Neue Config angelegt: {filename}")
return jsonify({"success": True, "filename": filename})
except Exception as e:
logger.exception("create_config fehlgeschlagen")
return jsonify({"success": False, "message": str(e)}), 500
@admin_bp.route('/create_theme', methods=['POST'])
def admin_create_theme():
data = request.get_json() or {}
name = data.get('name') or 'Neues Theme'
folder = data.get('folder') or _slugify(name)
filename = data.get('filename') or 'theme.json'
try:
data = request.get_json(force=True, silent=True) or {}
name = data.get('name') or 'Neues Theme'
folder = data.get('folder') or _slugify(name)
filename = data.get('filename') or 'theme.json'
base_dir = current_app.config['SOUNDBOARD_CONFIG_DIR']
theme_dir = os.path.join(base_dir, folder)
os.makedirs(theme_dir, exist_ok=True)
path = os.path.join(theme_dir, filename)
if os.path.exists(path):
return jsonify({"success": False, "message": "Theme-Datei existiert bereits"}), 400
base_dir = current_app.config['SOUNDBOARD_CONFIG_DIR']
theme_dir = os.path.join(base_dir, folder)
os.makedirs(theme_dir, exist_ok=True)
path = os.path.join(theme_dir, filename)
if os.path.exists(path):
return jsonify({"success": False, "message": "Theme-Datei existiert bereits"}), 400
template = {
"name": name,
"backgrounds": [],
"sounds": [],
"random_pool": [],
"random_limit_per_hour": 2,
"random_window_minutes": 60
}
with open(path, 'w', encoding='utf-8') as f:
json.dump(template, f, ensure_ascii=False, indent=2)
logger.info(f"Neues Theme angelegt: {os.path.relpath(path, base_dir)}")
return jsonify({"success": True, "path": os.path.relpath(path, base_dir)})
template = {
"name": name,
"backgrounds": [],
"sounds": [],
"random_pool": [],
"random_limit_per_hour": 2,
"random_window_minutes": 60
}
with open(path, 'w', encoding='utf-8') as f:
json.dump(template, f, ensure_ascii=False, indent=2)
logger.info(f"Neues Theme angelegt: {os.path.relpath(path, base_dir)}")
return jsonify({"success": True, "path": os.path.relpath(path, base_dir)})
except Exception as e:
logger.exception("create_theme fehlgeschlagen")
return jsonify({"success": False, "message": str(e)}), 500

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

View File

@ -212,7 +212,9 @@
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const json = await res.json();
const text = await res.text();
let json;
try { json = JSON.parse(text); } catch (_) { throw new Error('Serverantwort ist kein JSON:\n'+text); }
if (!json.success) throw new Error(json.message || 'Fehler');
alert('Konfiguration angelegt: ' + json.filename);
location.reload();
@ -233,7 +235,9 @@
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const json = await res.json();
const text = await res.text();
let json;
try { json = JSON.parse(text); } catch (_) { throw new Error('Serverantwort ist kein JSON:\n'+text); }
if (!json.success) throw new Error(json.message || 'Fehler');
alert('Theme angelegt: ' + json.path);
location.reload();