From 33a0cdf94608095df953a9381f5df61cbff320b7 Mon Sep 17 00:00:00 2001 From: Jerry Date: Sun, 4 May 2025 00:00:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Drestart=E4=B8=B4=E6=97=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=9C=A8Linux=E4=B8=8A=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app.ts | 3 ++- src/main.ts | 4 +++- src/test/wsTestClient.ts | 9 ++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app.ts b/src/app.ts index 1ac25ea..f1b8ecc 100644 --- a/src/app.ts +++ b/src/app.ts @@ -74,7 +74,8 @@ const apps = { //logger.info(duration); if (duration) { logger.warn(`重启完成!耗时 ${duration} 秒..`); - fs.writeFileSync('/temp/restart_time', duration.toString()); + const restartTimePath = path.join(paths.get('temp'), 'restart_time'); + fs.writeFileSync(restartTimePath, duration.toString()); } logger.info('晶灵核心初始化完毕!'); diff --git a/src/main.ts b/src/main.ts index 9526f87..77a06ea 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,6 +3,7 @@ import logger from './utils/core/logger'; import config from './utils/core/config'; import redis from './services/redis/redis'; import autoUpdater from './utils/core/autoUpdater'; +import System from './utils/core/system'; config.check(['PORT', 'DEBUG', 'RD_PORT', 'RD_ADD', 'WS_SECRET', 'WS_PORT']); const PORT = config.get('PORT') || 3000; @@ -15,7 +16,8 @@ apps }); const isUpdated = await autoUpdater.checkForUpdates(); if (isUpdated) { - logger.warn(`检测到更新,请重启..`); + logger.warn(`检测到更新,正在重启..`); + await System.restart(); } }) .catch((err) => { diff --git a/src/test/wsTestClient.ts b/src/test/wsTestClient.ts index 8bdcbe6..8552e92 100644 --- a/src/test/wsTestClient.ts +++ b/src/test/wsTestClient.ts @@ -1,8 +1,8 @@ import WebSocket from 'ws'; import axios from 'axios'; -const WS_URL = 'ws://127.0.0.1:4001'; -const WS_SECRET = '114514'; +const WS_URL = 'ws://server.crystelf.top:4001'; +const WS_SECRET = '520520'; const CLIENT_ID = 'test'; function createWebSocketClient() { @@ -48,8 +48,8 @@ async function testGetAPI() { async function testPostAPI() { try { - const response = await axios.post('http://localhost:4000/api/system/getRestartTime', { - token: 54188, + const response = await axios.post('https://core.crystelf.top/api/system/restart', { + token: 114113, }); console.log('[HTTP][POST] Response:', response.data); } catch (err) { @@ -61,7 +61,6 @@ async function main() { createWebSocketClient(); setTimeout(() => { - testGetAPI(); testPostAPI(); }, 1000); }