mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-02 01:08:05 +00:00
fix(web): address CodeRabbit review — validation, a11y, perf, and privacy fixes
Verified each finding against current code. Fixed: - api_v3: plugin_rotation_order is now strictly validated (JSON list of strings, 400 with a descriptive message otherwise) and popped from the payload before any further handling. - display_controller: _apply_plugin_rotation_order defensively ignores a non-list value (keeps the existing rotation, logs a warning) and drops non-string entries; new logs carry the [DisplayController] prefix. Unit-tested both defensive paths. - app.py: snapshot-read handler narrowed to OSError with debug logging; flask-compress ImportError now emits one structured warning with the install remedy. - htmx-config: the response-error logger prints form FIELD NAMES only - values (API keys, passwords) never reach the console. - plugin-order-list: saved order/exclusions normalized with Array.isArray (a saved "null" previously crashed .forEach); each row gained keyboard/touch-accessible move-up/move-down buttons (HTML5 drag events don't fire on most mobile browsers) that reorder and syncInputs() immediately alongside native drag. - app-shell: window.installedPlugins setter always takes the new list (same-ID metadata/enabled updates were silently dropped); tab rebuild stays gated on ID changes. LED dot renderer reads the frame with ONE getImageData call instead of one per pixel (~9,200/frame at 192x48). - plugins_manager: togglePlugin returns its request promise resolving the API outcome; the install flow now shows the "installed and enabled" toast (with Restart Now) only after enablement succeeds, and a warning without a restart offer when it fails. - a11y: hamburger aria-label flips Open/Close with drawer state; both Advanced-section toggle buttons declare aria-controls/aria-expanded and the shared toggleSection() keeps aria-expanded in sync; move buttons have per-plugin aria-labels. - Rotation/Vegas order-list bootstraps cap their retries (~5s) and show a reload hint instead of spinning forever; Alpine app-state lookups prefer [x-data="app()"] with a generic fallback. Skipped, with reasons: - executePluginAction arg order: caller (plugin_config.html) already passes (actionId, index, pluginId) matching the signature exactly. - generateFieldHtml XSS, entity-unescape blocks, dotToNested pollution, and "app.loadInstalledPlugins" in app-shell: all inside the legacy client-side config cluster whose entry points are shadowed by plugins_manager.js / replaced by server-rendered forms (zero live callers, verified) - queued for wholesale deletion in the follow-up rather than patching dead code. - custom-feeds-helpers.js findings (3): file was deleted in a prior commit. - console.error/warn override removal and afterSwap script re-execution removal: deliberate pre-existing workarounds every partial's inline init currently depends on; reworking them safely needs isolated testing (follow-up), and the error suppression is already double-gated (insertBefore AND htmx match). - "move durations bootstrap into a bundle": inline partial-scoped init is the established pattern for HTMX partials in this codebase. Validation: all 40 web tests pass; py_compile on all touched Python; all touched templates parse; rotation-order defensive paths unit-tested. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KEZK1P1Q1fu5pcuVrkrCFZ
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
aec1368d63
commit
8044084280
@@ -361,12 +361,15 @@
|
||||
const newPlugins = value || [];
|
||||
const oldIds = (_installedPluginsValue || []).map(p => p.id).sort().join(',');
|
||||
const newIds = newPlugins.map(p => p.id).sort().join(',');
|
||||
|
||||
// Only update if plugin list actually changed
|
||||
|
||||
// Always take the new list — same-ID updates
|
||||
// still carry changed metadata/enabled state.
|
||||
_installedPluginsValue = newPlugins;
|
||||
this.installedPlugins = newPlugins;
|
||||
// Only rebuild the tab row when the ID set
|
||||
// actually changed.
|
||||
if (oldIds !== newIds) {
|
||||
debugLog('window.installedPlugins changed:', newPlugins.length, 'plugins');
|
||||
_installedPluginsValue = newPlugins;
|
||||
this.installedPlugins = newPlugins;
|
||||
this.updatePluginTabs();
|
||||
}
|
||||
},
|
||||
@@ -1983,12 +1986,23 @@
|
||||
ctx.fillStyle = 'rgb(0, 0, 0)';
|
||||
ctx.fillRect(0, 0, ledCanvas.width, ledCanvas.height);
|
||||
|
||||
// Read the whole frame once instead of one getImageData call per
|
||||
// pixel (a 192x48 panel would otherwise issue ~9,200 calls per
|
||||
// frame — noticeably heavy on phones).
|
||||
let frame;
|
||||
try {
|
||||
frame = offCtx.getImageData(0, 0, logicalWidth, logicalHeight).data;
|
||||
} catch (e) {
|
||||
console.error('Failed to read offscreen canvas pixels:', e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Draw circular dots for each LED pixel
|
||||
let drawn = 0;
|
||||
for (let y = 0; y < logicalHeight; y++) {
|
||||
for (let x = 0; x < logicalWidth; x++) {
|
||||
const pixel = offCtx.getImageData(x, y, 1, 1).data;
|
||||
const r = pixel[0], g = pixel[1], b = pixel[2], a = pixel[3];
|
||||
const i = (y * logicalWidth + x) * 4;
|
||||
const r = frame[i], g = frame[i + 1], b = frame[i + 2], a = frame[i + 3];
|
||||
|
||||
// Skip fully transparent or black pixels to reduce overdraw
|
||||
if (a === 0 || (r|g|b) === 0) continue;
|
||||
|
||||
Reference in New Issue
Block a user