From c418efe007729c80d41e8e9f0cfb7850fffd03a6 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Fri, 9 Sep 2022 15:27:42 +0300 Subject: [PATCH] fix fallback to / in disk resource widget --- src/pages/api/widgets/resources.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pages/api/widgets/resources.js b/src/pages/api/widgets/resources.js index ceb3ff532..baa507a4e 100644 --- a/src/pages/api/widgets/resources.js +++ b/src/pages/api/widgets/resources.js @@ -1,3 +1,5 @@ +import { existsSync } from "fs"; + import { cpu, drive, mem } from "node-os-utils"; export default async function handler(req, res) { @@ -13,6 +15,12 @@ export default async function handler(req, res) { } if (type === "disk") { + if (!existsSync(target)) { + return res.status(404).json({ + error: "Target not found", + }); + } + return res.status(200).json({ drive: await drive.info(target || "/"), });