From cffe67d43b9bc851b0422cbd8028dc958780154b Mon Sep 17 00:00:00 2001 From: CyberMind-FR Date: Fri, 26 Dec 2025 13:55:57 +0100 Subject: [PATCH] fix: system-hub API using baseclass.extend() for proper LuCI compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed TypeError: "factory yields invalid constructor" by: - Adding 'require baseclass' directive - Using baseclass.extend() to return proper constructor - Added formatUptime() helper function - Added formatBytes() helper function This matches the pattern used in luci-app-secubox and other LuCI modules. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../luci-static/resources/system-hub/api.js | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/luci-app-system-hub/htdocs/luci-static/resources/system-hub/api.js b/luci-app-system-hub/htdocs/luci-static/resources/system-hub/api.js index 0392b53c..a6c628ca 100644 --- a/luci-app-system-hub/htdocs/luci-static/resources/system-hub/api.js +++ b/luci-app-system-hub/htdocs/luci-static/resources/system-hub/api.js @@ -1,6 +1,13 @@ 'use strict'; +'require baseclass'; 'require rpc'; +/** + * System Hub API + * Package: luci-app-system-hub + * RPCD object: luci.system-hub + */ + var callStatus = rpc.declare({ object: 'luci.system-hub', method: 'status', @@ -64,7 +71,25 @@ var callGetStorage = rpc.declare({ expect: { storage: [] } }); -return { +function formatUptime(seconds) { + if (!seconds) return '0s'; + var d = Math.floor(seconds / 86400); + var h = Math.floor((seconds % 86400) / 3600); + var m = Math.floor((seconds % 3600) / 60); + if (d > 0) return d + 'd ' + h + 'h'; + if (h > 0) return h + 'h ' + m + 'm'; + return m + 'm'; +} + +function formatBytes(bytes) { + if (!bytes) return '0 B'; + var k = 1024; + var sizes = ['B', 'KB', 'MB', 'GB', 'TB']; + var i = Math.floor(Math.log(bytes) / Math.log(k)); + return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i]; +} + +return baseclass.extend({ getStatus: callStatus, getSystemInfo: callGetSystemInfo, getHealth: callGetHealth, @@ -74,5 +99,7 @@ return { backupConfig: callBackupConfig, restoreConfig: callRestoreConfig, reboot: callReboot, - getStorage: callGetStorage -}; + getStorage: callGetStorage, + formatUptime: formatUptime, + formatBytes: formatBytes +});