fix: system-hub API using baseclass.extend() for proper LuCI compatibility

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 <noreply@anthropic.com>
This commit is contained in:
CyberMind-FR 2025-12-26 13:55:57 +01:00
parent b78431ff19
commit cffe67d43b

View File

@ -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
});