Bläddra i källkod

docker部署 网络唤醒主机

kindring 1 år sedan
förälder
incheckning
9903a11d9a

+ 2 - 0
.dockerignore

@@ -0,0 +1,2 @@
+node_modules
+npm-debug.log

+ 10 - 0
Dockerfile

@@ -0,0 +1,10 @@
+FROM node:16
+WORKDIR /home/fc
+COPY package*.json ./
+RUN npm install
+COPY build ./build
+COPY config ./config
+# 容器对外暴露的端口号
+EXPOSE 8090
+# 容器启动时执行的命令,类似npm run start
+CMD ["npm", "start"]

+ 27 - 12
build/app.js

@@ -4,18 +4,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
 };
 Object.defineProperty(exports, "__esModule", { value: true });
 var express_1 = __importDefault(require("express"));
+var body_parser_1 = __importDefault(require("body-parser"));
 var loadConfig_1 = require("./until/loadConfig");
-var serverConfig = (0, loadConfig_1.loadServerConfig)('./config/Server.json');
-if (serverConfig === null) {
-    console.log('无法找到路径');
+var logger_1 = __importDefault(require("./lib/logger"));
+var morganMiddleware_1 = __importDefault(require("./middleware/morganMiddleware"));
+var apiIndex_1 = __importDefault(require("./webRouter/apiIndex"));
+main();
+function main() {
+    var serverConfig = (0, loadConfig_1.loadServerConfig)('./config/Server.json');
+    if (serverConfig === null) {
+        logger_1.default.error("无法加载服务器配置文件");
+        throw new Error("无法加载服务器配置文件");
+    }
+    var app = (0, express_1.default)();
+    app.use(morganMiddleware_1.default);
+    app.use(body_parser_1.default.urlencoded({ limit: '10mb', extended: true }));
+    app.use(body_parser_1.default.json({ limit: '10mb' }));
+    app.get('/', function (req, res, next) {
+        res.send('Hello this website is a FC');
+    });
+    app.use('/api', apiIndex_1.default);
+    app.use(function (req, res) {
+        res.sendStatus(404);
+        // res.send("404");
+    });
+    app.listen(serverConfig.webPort, function () {
+        logger_1.default.info("web\u670D\u52A1\u4EE5\u542F\u52A8,\u76D1\u542C\u7AEF\u53E3\u4E3A: 0.0.0.0:".concat(serverConfig.webPort));
+        // console.log(`Example app listening on port ${serverConfig.webPort}!`);
+    });
 }
-else {
-}
-var app = (0, express_1.default)();
-app.get('/', function (req, res, next) {
-    res.send('Hello World!');
-});
-app.listen(serverConfig.webPort, function () {
-    console.log("Example app listening on port ".concat(serverConfig.webPort, "!"));
-});
 //# sourceMappingURL=app.js.map

+ 1 - 1
build/app.js.map

@@ -1 +1 @@
-{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;AAAA,oDAA+E;AAE/E,iDAAmD;AACnD,IAAI,YAAY,GAAG,IAAA,6BAAgB,EAAC,sBAAsB,CAAC,CAAA;AAC3D,IAAG,YAAY,KAAK,IAAI,EAAC;IACrB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;CACxB;KAAI;CAEJ;AACD,IAAM,GAAG,GAAe,IAAA,iBAAO,GAAE,CAAC;AAClC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,UAAC,GAAW,EAAE,GAAY,EAAE,IAAiB;IACtD,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAC7B,CAAC,CAAC,CAAC;AACH,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE;IAC7B,OAAO,CAAC,GAAG,CAAC,wCAAiC,YAAY,CAAC,OAAO,MAAG,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC"}
+{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;;AAAA,oDAA+E;AAC/E,4DAAqC;AACrC,iDAAmD;AACnD,wDAAiC;AACjC,mFAA4D;AAE5D,kEAA4C;AAC5C,IAAI,EAAE,CAAC;AACP,SAAS,IAAI;IACT,IAAI,YAAY,GAAG,IAAA,6BAAgB,EAAC,sBAAsB,CAAC,CAAA;IAC3D,IAAG,YAAY,KAAK,IAAI,EAAC;QACrB,gBAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;KAClC;IACD,IAAM,GAAG,GAAe,IAAA,iBAAO,GAAE,CAAC;IAClC,GAAG,CAAC,GAAG,CAAC,0BAAgB,CAAC,CAAC;IAC1B,GAAG,CAAC,GAAG,CAAC,qBAAU,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAClE,GAAG,CAAC,GAAG,CAAC,qBAAU,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IAC5C,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,UAAC,GAAW,EAAE,GAAY,EAAE,IAAiB;QACtD,GAAG,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;IACH,GAAG,CAAC,GAAG,CAAC,MAAM,EAAC,kBAAQ,CAAC,CAAC;IACzB,GAAG,CAAC,GAAG,CAAC,UAAC,GAAG,EAAC,GAAG;QACZ,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACpB,mBAAmB;IACvB,CAAC,CAAC,CAAA;IACF,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE;QAC7B,gBAAM,CAAC,IAAI,CAAC,oFAA2B,YAAY,CAAC,OAAO,CAAE,CAAC,CAAA;QAC9D,yEAAyE;IAC7E,CAAC,CAAC,CAAC;AACP,CAAC"}

+ 25 - 2
build/until/loadConfig.js

@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
     return result;
 };
 Object.defineProperty(exports, "__esModule", { value: true });
-exports.loadServerConfig = void 0;
+exports.loadCustomConfig = exports.loadFileConfig = exports.loadServerConfig = void 0;
 var fs = __importStar(require("fs"));
 function loadServerConfig(configPath) {
     if (fs.existsSync(configPath)) //判断是否存在此文件
@@ -37,5 +37,28 @@ function loadServerConfig(configPath) {
     }
 }
 exports.loadServerConfig = loadServerConfig;
-exports.default = loadServerConfig;
+function loadFileConfig(configPath) {
+    if (fs.existsSync(configPath)) //判断是否存在此文件
+     {
+        //读取文件内容,并转化为Json对象
+        return JSON.parse(fs.readFileSync(configPath, "utf8"));
+    }
+    else {
+        // 无法找到该路径文件
+        return null;
+    }
+}
+exports.loadFileConfig = loadFileConfig;
+function loadCustomConfig(configPath) {
+    if (fs.existsSync(configPath)) //判断是否存在此文件
+     {
+        //读取文件内容,并转化为Json对象
+        return JSON.parse(fs.readFileSync(configPath, "utf8"));
+    }
+    else {
+        // 无法找到该路径文件
+        return null;
+    }
+}
+exports.loadCustomConfig = loadCustomConfig;
 //# sourceMappingURL=loadConfig.js.map

+ 1 - 1
build/until/loadConfig.js.map

@@ -1 +1 @@
-{"version":3,"file":"loadConfig.js","sourceRoot":"","sources":["../../src/until/loadConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AAMzB,SAAgB,gBAAgB,CAAC,UAAiB;IAC9C,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,WAAW;KAC1C;QACI,mBAAmB;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;KAC1D;SAAI;QACD,YAAY;QACZ,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AATD,4CASC;AAED,kBAAe,gBAAgB,CAAC"}
+{"version":3,"file":"loadConfig.js","sourceRoot":"","sources":["../../src/until/loadConfig.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AAKzB,SAAgB,gBAAgB,CAAC,UAAiB;IAC9C,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,WAAW;KAC1C;QACI,mBAAmB;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;KAC1D;SAAI;QACD,YAAY;QACZ,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AATD,4CASC;AAKD,SAAgB,cAAc,CAAC,UAAiB;IAC5C,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,WAAW;KAC1C;QACI,mBAAmB;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;KAC1D;SAAI;QACD,YAAY;QACZ,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AATD,wCASC;AAOD,SAAgB,gBAAgB,CAAC,UAAiB;IAC9C,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,WAAW;KAC1C;QACI,mBAAmB;QACnB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;KAC1D;SAAI;QACD,YAAY;QACZ,OAAO,IAAI,CAAC;KACf;AACL,CAAC;AATD,4CASC"}

+ 5 - 0
config/Custom.json

@@ -0,0 +1,5 @@
+{
+  "mainPc": {
+    "mac": "00E269589A9E"
+  }
+}

+ 139 - 17
package-lock.json

@@ -10,16 +10,19 @@
       "license": "ISC",
       "dependencies": {
         "@types/morgan": "^1.9.4",
+        "body-parser": "^1.20.2",
         "express": "^4.18.2",
         "morgan": "^1.10.0",
         "nodemon": "^2.0.22",
         "ts-node": "^10.9.1",
         "typescript": "^5.0.3",
+        "wake_on_lan": "^1.0.0",
         "winston": "^3.8.2"
       },
       "devDependencies": {
         "@types/express": "^4.17.17",
-        "@types/node": "^18.15.11"
+        "@types/node": "^18.15.11",
+        "@types/wake_on_lan": "^0.0.30"
       }
     },
     "node_modules/@colors/colors": {
@@ -181,6 +184,15 @@
       "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.2.tgz",
       "integrity": "sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g=="
     },
+    "node_modules/@types/wake_on_lan": {
+      "version": "0.0.30",
+      "resolved": "https://registry.npmjs.org/@types/wake_on_lan/-/wake_on_lan-0.0.30.tgz",
+      "integrity": "sha512-r6Ia5Ej3F61Zaq2oiap4syDsl1KTfsKVqJKkuMuEIxaVBHnZ9P98IFmcUGA+GiFvXZ+ETCEp/tKhKxmwsOnxig==",
+      "dev": true,
+      "dependencies": {
+        "@types/node": "*"
+      }
+    },
     "node_modules/abbrev": {
       "version": "1.1.1",
       "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@@ -274,12 +286,12 @@
       }
     },
     "node_modules/body-parser": {
-      "version": "1.20.1",
-      "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
-      "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
+      "version": "1.20.2",
+      "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
+      "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
       "dependencies": {
         "bytes": "3.1.2",
-        "content-type": "~1.0.4",
+        "content-type": "~1.0.5",
         "debug": "2.6.9",
         "depd": "2.0.0",
         "destroy": "1.2.0",
@@ -287,7 +299,7 @@
         "iconv-lite": "0.4.24",
         "on-finished": "2.4.1",
         "qs": "6.11.0",
-        "raw-body": "2.5.1",
+        "raw-body": "2.5.2",
         "type-is": "~1.6.18",
         "unpipe": "1.0.0"
       },
@@ -549,6 +561,43 @@
         "node": ">= 0.10.0"
       }
     },
+    "node_modules/express/node_modules/body-parser": {
+      "version": "1.20.1",
+      "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
+      "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
+      "dependencies": {
+        "bytes": "3.1.2",
+        "content-type": "~1.0.4",
+        "debug": "2.6.9",
+        "depd": "2.0.0",
+        "destroy": "1.2.0",
+        "http-errors": "2.0.0",
+        "iconv-lite": "0.4.24",
+        "on-finished": "2.4.1",
+        "qs": "6.11.0",
+        "raw-body": "2.5.1",
+        "type-is": "~1.6.18",
+        "unpipe": "1.0.0"
+      },
+      "engines": {
+        "node": ">= 0.8",
+        "npm": "1.2.8000 || >= 1.4.16"
+      }
+    },
+    "node_modules/express/node_modules/raw-body": {
+      "version": "2.5.1",
+      "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
+      "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
+      "dependencies": {
+        "bytes": "3.1.2",
+        "http-errors": "2.0.0",
+        "iconv-lite": "0.4.24",
+        "unpipe": "1.0.0"
+      },
+      "engines": {
+        "node": ">= 0.8"
+      }
+    },
     "node_modules/fecha": {
       "version": "4.2.3",
       "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz",
@@ -863,6 +912,14 @@
         "node": "*"
       }
     },
+    "node_modules/minimist": {
+      "version": "1.2.8",
+      "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
+      "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
+      "funding": {
+        "url": "https://github.com/sponsors/ljharb"
+      }
+    },
     "node_modules/morgan": {
       "version": "1.10.0",
       "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz",
@@ -1063,9 +1120,9 @@
       }
     },
     "node_modules/raw-body": {
-      "version": "2.5.1",
-      "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
-      "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
+      "version": "2.5.2",
+      "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
+      "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
       "dependencies": {
         "bytes": "3.1.2",
         "http-errors": "2.0.0",
@@ -1407,6 +1464,17 @@
         "node": ">= 0.8"
       }
     },
+    "node_modules/wake_on_lan": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/wake_on_lan/-/wake_on_lan-1.0.0.tgz",
+      "integrity": "sha512-0QSpxny0QmsssshI6kePj6cobQPK+i8r5shfj58ZfQIUH9fUTyAaYPqZO3W/Ai7mN4vQVdTdsSGIr20M81UL6Q==",
+      "dependencies": {
+        "minimist": "^1.2.0"
+      },
+      "bin": {
+        "wake": "wake"
+      }
+    },
     "node_modules/winston": {
       "version": "3.8.2",
       "resolved": "https://registry.npmjs.org/winston/-/winston-3.8.2.tgz",
@@ -1601,6 +1669,15 @@
       "resolved": "https://registry.npmjs.org/@types/triple-beam/-/triple-beam-1.3.2.tgz",
       "integrity": "sha512-txGIh+0eDFzKGC25zORnswy+br1Ha7hj5cMVwKIU7+s0U2AxxJru/jZSMU6OC9MJWP6+pc/hc6ZjyZShpsyY2g=="
     },
+    "@types/wake_on_lan": {
+      "version": "0.0.30",
+      "resolved": "https://registry.npmjs.org/@types/wake_on_lan/-/wake_on_lan-0.0.30.tgz",
+      "integrity": "sha512-r6Ia5Ej3F61Zaq2oiap4syDsl1KTfsKVqJKkuMuEIxaVBHnZ9P98IFmcUGA+GiFvXZ+ETCEp/tKhKxmwsOnxig==",
+      "dev": true,
+      "requires": {
+        "@types/node": "*"
+      }
+    },
     "abbrev": {
       "version": "1.1.1",
       "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
@@ -1675,12 +1752,12 @@
       "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA=="
     },
     "body-parser": {
-      "version": "1.20.1",
-      "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
-      "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
+      "version": "1.20.2",
+      "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz",
+      "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==",
       "requires": {
         "bytes": "3.1.2",
-        "content-type": "~1.0.4",
+        "content-type": "~1.0.5",
         "debug": "2.6.9",
         "depd": "2.0.0",
         "destroy": "1.2.0",
@@ -1688,7 +1765,7 @@
         "iconv-lite": "0.4.24",
         "on-finished": "2.4.1",
         "qs": "6.11.0",
-        "raw-body": "2.5.1",
+        "raw-body": "2.5.2",
         "type-is": "~1.6.18",
         "unpipe": "1.0.0"
       }
@@ -1896,6 +1973,38 @@
         "type-is": "~1.6.18",
         "utils-merge": "1.0.1",
         "vary": "~1.1.2"
+      },
+      "dependencies": {
+        "body-parser": {
+          "version": "1.20.1",
+          "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz",
+          "integrity": "sha512-jWi7abTbYwajOytWCQc37VulmWiRae5RyTpaCyDcS5/lMdtwSz5lOpDE67srw/HYe35f1z3fDQw+3txg7gNtWw==",
+          "requires": {
+            "bytes": "3.1.2",
+            "content-type": "~1.0.4",
+            "debug": "2.6.9",
+            "depd": "2.0.0",
+            "destroy": "1.2.0",
+            "http-errors": "2.0.0",
+            "iconv-lite": "0.4.24",
+            "on-finished": "2.4.1",
+            "qs": "6.11.0",
+            "raw-body": "2.5.1",
+            "type-is": "~1.6.18",
+            "unpipe": "1.0.0"
+          }
+        },
+        "raw-body": {
+          "version": "2.5.1",
+          "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
+          "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
+          "requires": {
+            "bytes": "3.1.2",
+            "http-errors": "2.0.0",
+            "iconv-lite": "0.4.24",
+            "unpipe": "1.0.0"
+          }
+        }
       }
     },
     "fecha": {
@@ -2129,6 +2238,11 @@
         "brace-expansion": "^1.1.7"
       }
     },
+    "minimist": {
+      "version": "1.2.8",
+      "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
+      "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="
+    },
     "morgan": {
       "version": "1.10.0",
       "resolved": "https://registry.npmjs.org/morgan/-/morgan-1.10.0.tgz",
@@ -2275,9 +2389,9 @@
       "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="
     },
     "raw-body": {
-      "version": "2.5.1",
-      "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.1.tgz",
-      "integrity": "sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==",
+      "version": "2.5.2",
+      "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
+      "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
       "requires": {
         "bytes": "3.1.2",
         "http-errors": "2.0.0",
@@ -2520,6 +2634,14 @@
       "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
       "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="
     },
+    "wake_on_lan": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/wake_on_lan/-/wake_on_lan-1.0.0.tgz",
+      "integrity": "sha512-0QSpxny0QmsssshI6kePj6cobQPK+i8r5shfj58ZfQIUH9fUTyAaYPqZO3W/Ai7mN4vQVdTdsSGIr20M81UL6Q==",
+      "requires": {
+        "minimist": "^1.2.0"
+      }
+    },
     "winston": {
       "version": "3.8.2",
       "resolved": "https://registry.npmjs.org/winston/-/winston-3.8.2.tgz",

+ 3 - 1
package.json

@@ -10,11 +10,13 @@
     "nodemon": "^2.0.22",
     "ts-node": "^10.9.1",
     "typescript": "^5.0.3",
+    "wake_on_lan": "^1.0.0",
     "winston": "^3.8.2"
   },
   "devDependencies": {
     "@types/express": "^4.17.17",
-    "@types/node": "^18.15.11"
+    "@types/node": "^18.15.11",
+    "@types/wake_on_lan": "^0.0.30"
   },
   "scripts": {
     "tsc": "tsc",

+ 7 - 0
src/lib/wol.ts

@@ -0,0 +1,7 @@
+import wol from "wake_on_lan"
+
+export function openPc(mac: string){
+    wol.wake(mac);
+}
+
+

+ 0 - 0
src/types/pc/Pc.ts


+ 15 - 0
src/until/loadConfig.ts

@@ -28,3 +28,18 @@ export function loadFileConfig(configPath:string):FileConf{
     }
 }
 
+interface CustomConf{
+    mainPc: {
+        mac: string
+    }
+}
+export function loadCustomConfig(configPath:string):CustomConf{
+    if (fs.existsSync(configPath)) //判断是否存在此文件
+    {
+        //读取文件内容,并转化为Json对象
+        return JSON.parse(fs.readFileSync(configPath, "utf8"));
+    }else{
+        // 无法找到该路径文件
+        return null;
+    }
+}

+ 2 - 0
src/webRouter/apiIndex.ts

@@ -2,7 +2,9 @@
 import {Router} from "express"
 import fs from "./fs"
 import qqHook from "./qqHook";
+import pcControl from "./pcControl";
 const router = Router();
 router.use("/fs",fs);
 router.use("/iq",qqHook);
+router.use("/pcc",pcControl);
 export default router;

+ 26 - 0
src/webRouter/pcControl.ts

@@ -0,0 +1,26 @@
+import {Router} from "express"
+import logger from "../lib/logger"
+import errCode from "../types/IErrorCode";
+import {loadCustomConfig} from "../until/loadConfig";
+import {openPc} from "../lib/wol";
+
+
+const router = Router();
+const customConfig = loadCustomConfig("./config/Custom.json");
+router.get('/openMain',(req, res)=> {
+    if (!customConfig) {
+        res.json({
+            code:2,
+            msg:'loading fail'
+        });
+        return;
+    }
+    logger.info(customConfig);
+    openPc(customConfig.mainPc.mac);
+    res.json({
+        code:0,
+        msg:'ok'
+    });
+})
+
+export default router;