mirror of
https://github.com/gethomepage/homepage.git
synced 2025-12-07 09:35:54 -08:00
refactor information widgets
This commit is contained in:
@@ -1,14 +1,26 @@
|
||||
import { cpu, drive, mem, netstat } from "node-os-utils";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { disk } = req.query;
|
||||
const { type, target } = req.query;
|
||||
|
||||
res.send({
|
||||
cpu: {
|
||||
usage: await cpu.usage(),
|
||||
load: cpu.loadavgTime(5),
|
||||
},
|
||||
drive: await drive.info(disk || "/"),
|
||||
memory: await mem.info(),
|
||||
});
|
||||
if (type == "cpu") {
|
||||
return res.status(200).json({
|
||||
cpu: {
|
||||
usage: await cpu.usage(1000),
|
||||
load: cpu.loadavgTime(5),
|
||||
},
|
||||
});
|
||||
} else if (type == "disk") {
|
||||
return res.status(200).json({
|
||||
drive: await drive.info(target || "/"),
|
||||
});
|
||||
} else if (type == "memory") {
|
||||
return res.status(200).json({
|
||||
memory: await mem.info(),
|
||||
});
|
||||
} else {
|
||||
return res.status(400).json({
|
||||
error: "invalid type",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user