mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-06-29 23:38:38 +00:00
fix(tools,api): address three additional review findings
- api_v3.py install_plugin_requirements: replace hardcoded plugin-repos fallback with config-driven resolution (plugin_system.plugins_directory), matching the pattern used elsewhere in the module - api_v3.py _fix_json_arrays: recurse into converted and existing array elements when items.type is object, so nested numeric-keyed dicts inside array items are also normalized - tools.html toolsAction: check r.ok before r.json() and recover gracefully from non-JSON error bodies (HTML 500 pages), consistent with the existing loadGitInfo guard Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1682,7 +1682,13 @@ def execute_system_action():
|
|||||||
})
|
})
|
||||||
elif action == 'install_plugin_requirements':
|
elif action == 'install_plugin_requirements':
|
||||||
active_pm = getattr(api_v3, 'plugin_manager', None)
|
active_pm = getattr(api_v3, 'plugin_manager', None)
|
||||||
plugins_dir = Path(active_pm.plugins_dir) if active_pm else PROJECT_ROOT / 'plugin-repos'
|
if active_pm:
|
||||||
|
plugins_dir = Path(active_pm.plugins_dir)
|
||||||
|
else:
|
||||||
|
_cm = getattr(api_v3, 'config_manager', None)
|
||||||
|
_cfg = _cm.load_config() if _cm else {}
|
||||||
|
_dir_name = _cfg.get('plugin_system', {}).get('plugins_directory', 'plugin-repos')
|
||||||
|
plugins_dir = Path(_dir_name) if os.path.isabs(_dir_name) else PROJECT_ROOT / _dir_name
|
||||||
results = []
|
results = []
|
||||||
if plugins_dir.exists():
|
if plugins_dir.exists():
|
||||||
for p in sorted(plugins_dir.iterdir()):
|
for p in sorted(plugins_dir.iterdir()):
|
||||||
@@ -4630,12 +4636,13 @@ def save_plugin_config():
|
|||||||
continue
|
continue
|
||||||
pt = ps.get('type')
|
pt = ps.get('type')
|
||||||
val = cfg[k]
|
val = cfg[k]
|
||||||
if pt == 'array' and isinstance(val, dict):
|
if pt == 'array':
|
||||||
|
items_schema = ps.get('items', {})
|
||||||
|
item_type = items_schema.get('type')
|
||||||
|
if isinstance(val, dict):
|
||||||
keys = list(val.keys())
|
keys = list(val.keys())
|
||||||
if keys and all(str(x).isdigit() for x in keys):
|
if keys and all(str(x).isdigit() for x in keys):
|
||||||
sorted_keys = sorted(keys, key=lambda x: int(str(x)))
|
sorted_keys = sorted(keys, key=lambda x: int(str(x)))
|
||||||
items_schema = ps.get('items', {})
|
|
||||||
item_type = items_schema.get('type')
|
|
||||||
arr = [val[sk] for sk in sorted_keys]
|
arr = [val[sk] for sk in sorted_keys]
|
||||||
if item_type in ('integer', 'number'):
|
if item_type in ('integer', 'number'):
|
||||||
converted = []
|
converted = []
|
||||||
@@ -4651,6 +4658,12 @@ def save_plugin_config():
|
|||||||
cfg[k] = arr
|
cfg[k] = arr
|
||||||
elif not keys:
|
elif not keys:
|
||||||
cfg[k] = []
|
cfg[k] = []
|
||||||
|
# Recurse into each element when items are objects with properties,
|
||||||
|
# covering both freshly-converted and already-list values.
|
||||||
|
if item_type == 'object' and 'properties' in items_schema:
|
||||||
|
for elem in (cfg[k] if isinstance(cfg[k], list) else []):
|
||||||
|
if isinstance(elem, dict):
|
||||||
|
_fix_json_arrays(elem, items_schema['properties'])
|
||||||
elif pt == 'object' and 'properties' in ps and isinstance(val, dict):
|
elif pt == 'object' and 'properties' in ps and isinstance(val, dict):
|
||||||
_fix_json_arrays(val, ps['properties'])
|
_fix_json_arrays(val, ps['properties'])
|
||||||
_fix_json_arrays(plugin_config, schema['properties'])
|
_fix_json_arrays(plugin_config, schema['properties'])
|
||||||
|
|||||||
@@ -229,7 +229,14 @@
|
|||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({action})
|
body: JSON.stringify({action})
|
||||||
})
|
})
|
||||||
.then(r => r.json())
|
.then(r => {
|
||||||
|
if (!r.ok) {
|
||||||
|
return r.json()
|
||||||
|
.then(d => Promise.reject(new Error(d.message || `HTTP ${r.status}`)))
|
||||||
|
.catch(() => Promise.reject(new Error(`HTTP ${r.status}`)));
|
||||||
|
}
|
||||||
|
return r.json();
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
const ok = data.status === 'success';
|
const ok = data.status === 'success';
|
||||||
showResult(
|
showResult(
|
||||||
|
|||||||
Reference in New Issue
Block a user