fixes for new config editor
This commit is contained in:
+52
-44
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user