mirror of
https://github.com/DI0IK/homepage-plus.git
synced 2025-07-10 15:28:47 +00:00
Enhancement: resources network widget (#4327)
This commit is contained in:
parent
a06964dd17
commit
897309a47c
6 changed files with 86 additions and 4 deletions
|
@ -7,7 +7,7 @@ const logger = createLogger("resources");
|
|||
const si = require("systeminformation");
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { type, target } = req.query;
|
||||
const { type, target, interfaceName = "default" } = req.query;
|
||||
|
||||
if (type === "cpu") {
|
||||
const load = await si.currentLoad();
|
||||
|
@ -57,6 +57,32 @@ export default async function handler(req, res) {
|
|||
});
|
||||
}
|
||||
|
||||
if (type === "network") {
|
||||
let networkData = await si.networkStats();
|
||||
let interfaceDefault;
|
||||
logger.debug("networkData:", JSON.stringify(networkData));
|
||||
if (interfaceName && interfaceName !== "default") {
|
||||
networkData = networkData.filter((network) => network.iface === interfaceName).at(0);
|
||||
if (!networkData) {
|
||||
return res.status(404).json({
|
||||
error: "Interface not found",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
interfaceDefault = await si.networkInterfaceDefault();
|
||||
networkData = networkData.filter((network) => network.iface === interfaceDefault).at(0);
|
||||
if (!networkData) {
|
||||
return res.status(404).json({
|
||||
error: "Default interface not found",
|
||||
});
|
||||
}
|
||||
}
|
||||
return res.status(200).json({
|
||||
network: networkData,
|
||||
interface: interfaceName !== "default" ? interfaceName : interfaceDefault,
|
||||
});
|
||||
}
|
||||
|
||||
return res.status(400).json({
|
||||
error: "invalid type",
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue