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:
@@ -14,7 +14,9 @@ export default async function handler(req, res) {
|
||||
|
||||
try {
|
||||
const docker = new Docker(await getDockerArguments(containerServer));
|
||||
const containers = await docker.listContainers();
|
||||
const containers = await docker.listContainers({
|
||||
all: true,
|
||||
});
|
||||
|
||||
// bad docker connections can result in a <Buffer ...> object?
|
||||
// in any case, this ensures the result is the expected array
|
||||
@@ -30,7 +32,7 @@ export default async function handler(req, res) {
|
||||
const containerExists = containerNames.includes(containerName);
|
||||
|
||||
if (!containerExists) {
|
||||
return res.status(404).send({
|
||||
return res.status(200).send({
|
||||
error: "not found",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ export default async function handler(req, res) {
|
||||
|
||||
try {
|
||||
const docker = new Docker(await getDockerArguments(containerServer));
|
||||
const containers = await docker.listContainers();
|
||||
const containers = await docker.listContainers({
|
||||
all: true,
|
||||
});
|
||||
|
||||
// bad docker connections can result in a <Buffer ...> object?
|
||||
// in any case, this ensures the result is the expected array
|
||||
@@ -29,7 +31,7 @@ export default async function handler(req, res) {
|
||||
const containerExists = containerNames.includes(containerName);
|
||||
|
||||
if (!containerExists) {
|
||||
return res.status(404).send({
|
||||
return res.status(200).send({
|
||||
error: "not found",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,17 @@ export default function Home() {
|
||||
<div className="flex flex-wrap m-8 pb-4 mt-10 border-b-2 border-theme-800 dark:border-theme-200">
|
||||
{widgets && (
|
||||
<>
|
||||
{widgets.map((widget) => (
|
||||
<Widget key={widget.type} widget={widget} />
|
||||
))}
|
||||
{widgets
|
||||
.filter((widget) => widget.type !== "weather")
|
||||
.map((widget, i) => (
|
||||
<Widget key={i} widget={widget} />
|
||||
))}
|
||||
<div className="grow"></div>
|
||||
{widgets
|
||||
.filter((widget) => widget.type === "weather")
|
||||
.map((widget, i) => (
|
||||
<Widget key={i} widget={widget} />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user