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:
parent
b78431ff19
commit
cffe67d43b
@ -1,6 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
'require baseclass';
|
||||||
'require rpc';
|
'require rpc';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* System Hub API
|
||||||
|
* Package: luci-app-system-hub
|
||||||
|
* RPCD object: luci.system-hub
|
||||||
|
*/
|
||||||
|
|
||||||
var callStatus = rpc.declare({
|
var callStatus = rpc.declare({
|
||||||
object: 'luci.system-hub',
|
object: 'luci.system-hub',
|
||||||
method: 'status',
|
method: 'status',
|
||||||
@ -64,7 +71,25 @@ var callGetStorage = rpc.declare({
|
|||||||
expect: { storage: [] }
|
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,
|
getStatus: callStatus,
|
||||||
getSystemInfo: callGetSystemInfo,
|
getSystemInfo: callGetSystemInfo,
|
||||||
getHealth: callGetHealth,
|
getHealth: callGetHealth,
|
||||||
@ -74,5 +99,7 @@ return {
|
|||||||
backupConfig: callBackupConfig,
|
backupConfig: callBackupConfig,
|
||||||
restoreConfig: callRestoreConfig,
|
restoreConfig: callRestoreConfig,
|
||||||
reboot: callReboot,
|
reboot: callReboot,
|
||||||
getStorage: callGetStorage
|
getStorage: callGetStorage,
|
||||||
};
|
formatUptime: formatUptime,
|
||||||
|
formatBytes: formatBytes
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user