added restapi
This commit is contained in:
@@ -7,6 +7,7 @@ Defaults here must stay in sync with ConfigManager::ensureDefaults() in C++.
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import secrets
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
@@ -55,6 +56,7 @@ def _defaults():
|
||||
"iconsDir": "./icons",
|
||||
"webPort": 8080,
|
||||
"brightness": 60,
|
||||
"collectorEnabled": True,
|
||||
},
|
||||
"buttons": [],
|
||||
}
|
||||
@@ -76,6 +78,10 @@ def ensure_defaults(cfg):
|
||||
if not isinstance(cfg.get("buttons"), list):
|
||||
cfg["buttons"] = []
|
||||
cfg.setdefault("settings", {})["darkMode"] = True
|
||||
settings = cfg.setdefault("settings", {})
|
||||
key = settings.get("apiKey")
|
||||
if not isinstance(key, str) or not key.strip():
|
||||
settings["apiKey"] = secrets.token_urlsafe(24)
|
||||
return cfg
|
||||
|
||||
|
||||
@@ -85,6 +91,7 @@ def load_config():
|
||||
cfg = ensure_defaults(_defaults())
|
||||
# point iconsDir at a sensible absolute default for the web side
|
||||
cfg["settings"]["iconsDir"] = str((p.parent.parent / "icons"))
|
||||
save_config(cfg)
|
||||
return cfg
|
||||
with p.open("r", encoding="utf-8") as f:
|
||||
raw = json.load(f)
|
||||
|
||||
Reference in New Issue
Block a user