浏览代码

fix fallback to / in disk resource widget

Ben Phelps 2 年之前
父节点
当前提交
c418efe007
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/pages/api/widgets/resources.js

+ 8 - 0
src/pages/api/widgets/resources.js

@@ -1,3 +1,5 @@
+import { existsSync } from "fs";
+
 import { cpu, drive, mem } from "node-os-utils";
 import { cpu, drive, mem } from "node-os-utils";
 
 
 export default async function handler(req, res) {
 export default async function handler(req, res) {
@@ -13,6 +15,12 @@ export default async function handler(req, res) {
   }
   }
 
 
   if (type === "disk") {
   if (type === "disk") {
+    if (!existsSync(target)) {
+      return res.status(404).json({
+        error: "Target not found",
+      });
+    }
+
     return res.status(200).json({
     return res.status(200).json({
       drive: await drive.info(target || "/"),
       drive: await drive.info(target || "/"),
     });
     });