INNER CODE UNIT · Python
load_custom_styles
ChenShuo2004/cs-board · webapp/server.py:265
def load_custom_styles() -> list[dict[str, Any]]:
if not STYLES_PATH.exists():
return []
try:
data = json.loads(STYLES_PATH.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError):
return []
if not isinstance(data, list):
return []
result: list[dict[str, Any]] = []
for item in data:
if not isinstance(item, dict):
continue
style_id = str(item.get("id") or "")
name = normalized_style_name(item.get("name"))
recipe = normalized_style_recipe(item.get("recipe"))
if not STYLE_ID_PATTERN.fullmatch(style_id) or not name or not recipe:
continue