diff --git a/packages/napcat-webui-backend/src/api/Process.ts b/packages/napcat-webui-backend/src/api/Process.ts index b9cfd23f..9a66070d 100644 --- a/packages/napcat-webui-backend/src/api/Process.ts +++ b/packages/napcat-webui-backend/src/api/Process.ts @@ -2,30 +2,16 @@ import type { Request, Response } from 'express'; import { WebUiDataRuntime } from '../helper/Data'; import { sendError, sendSuccess } from '../utils/response'; -export interface RestartRequestBody { - /** - * 重启类型: 'manual' (用户手动触发) 或 'automatic' (系统自动触发) - * 默认为 'manual' - */ - restartType?: 'manual' | 'automatic'; -} - /** * 重启进程处理器 * POST /api/Process/Restart - * Body: { restartType?: 'manual' | 'automatic' } */ -export async function RestartProcessHandler (req: Request, res: Response) { +export async function RestartProcessHandler (_req: Request, res: Response) { try { - const { restartType = 'manual' } = (req.body as RestartRequestBody) || {}; - const result = await WebUiDataRuntime.requestRestartProcess(); if (result.result) { - return sendSuccess(res, { - message: result.message || '进程重启请求已发送', - restartType, - }); + return sendSuccess(res, { message: result.message || '进程重启请求已发送' }); } else { return sendError(res, result.message || '进程重启失败'); } diff --git a/packages/napcat-webui-backend/src/helper/Data.ts b/packages/napcat-webui-backend/src/helper/Data.ts index a9c4b51e..8fb4a615 100644 --- a/packages/napcat-webui-backend/src/helper/Data.ts +++ b/packages/napcat-webui-backend/src/helper/Data.ts @@ -196,6 +196,7 @@ export const WebUiDataRuntime = { }, refreshQRCode: async function () { + LoginRuntime.QQLoginError = ''; await LoginRuntime.onRefreshQRCode(); }, }; diff --git a/packages/napcat-webui-frontend/src/controllers/process_manager.ts b/packages/napcat-webui-frontend/src/controllers/process_manager.ts index 566302bc..a451a425 100644 --- a/packages/napcat-webui-frontend/src/controllers/process_manager.ts +++ b/packages/napcat-webui-frontend/src/controllers/process_manager.ts @@ -1,19 +1,12 @@ import { serverRequest } from '@/utils/request'; -export interface RestartProcessResponse { - message: string; - restartType?: 'manual' | 'automatic'; -} - export default class ProcessManager { /** * 重启进程 - * @param restartType 重启类型: 'manual' (用户手动触发) 或 'automatic' (系统自动触发) */ - public static async restartProcess (restartType: 'manual' | 'automatic' = 'manual') { - const data = await serverRequest.post>( - '/Process/Restart', - { restartType } + public static async restartProcess () { + const data = await serverRequest.post>( + '/Process/Restart' ); return data.data.data; diff --git a/packages/napcat-webui-frontend/src/layouts/default.tsx b/packages/napcat-webui-frontend/src/layouts/default.tsx index 5829ca80..4f394f04 100644 --- a/packages/napcat-webui-frontend/src/layouts/default.tsx +++ b/packages/napcat-webui-frontend/src/layouts/default.tsx @@ -74,7 +74,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => { onConfirm: async () => { setIsRestarting(true); try { - await ProcessManager.restartProcess('automatic'); + await ProcessManager.restartProcess(); } catch (_e) { // 忽略错误,因为后端正在重启关闭连接 } @@ -84,7 +84,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => { 15000, // 15秒超时 () => { setIsRestarting(false); - // 前端发起的重启不清除登录态,无感恢复 + window.location.reload(); }, () => { setIsRestarting(false); @@ -92,8 +92,7 @@ const Layout: React.FC<{ children: React.ReactNode; }> = ({ children }) => { title: '启动超时', content: '后端在 15 秒内未响应,请检查 NapCat 运行日志或手动重启。', }); - }, - false // 前端发起的重启不清除登录态 + } ); }, onCancel: () => { diff --git a/packages/napcat-webui-frontend/src/pages/dashboard/config/login.tsx b/packages/napcat-webui-frontend/src/pages/dashboard/config/login.tsx index 2dc3abdb..aa1e96e3 100644 --- a/packages/napcat-webui-frontend/src/pages/dashboard/config/login.tsx +++ b/packages/napcat-webui-frontend/src/pages/dashboard/config/login.tsx @@ -60,7 +60,7 @@ const LoginConfigCard = () => { const onRestartProcess = async () => { setIsRestarting(true); try { - const result = await ProcessManager.restartProcess('manual'); + const result = await ProcessManager.restartProcess(); toast.success(result.message || '进程重启请求已发送'); // 轮询探测后端是否恢复 @@ -73,8 +73,7 @@ const LoginConfigCard = () => { () => { setIsRestarting(false); toast.error('后端在 30 秒内未响应,请检查 NapCat 运行日志'); - }, - false // 前端发起的重启不清除登录态 + } ); if (!isReady) { diff --git a/packages/napcat-webui-frontend/src/utils/process_utils.ts b/packages/napcat-webui-frontend/src/utils/process_utils.ts index 376f39f5..12aa939c 100644 --- a/packages/napcat-webui-frontend/src/utils/process_utils.ts +++ b/packages/napcat-webui-frontend/src/utils/process_utils.ts @@ -5,13 +5,11 @@ import QQManager from '@/controllers/qq_manager'; * @param maxWaitTime 最大等待时间,单位毫秒 * @param onSuccess 成功回调 * @param onTimeout 超时回调 - * @param shouldLogout 是否在成功后登出用户。默认为 true (清除登录态),前端发起的重启应传 false (保留会话) */ export async function waitForBackendReady ( maxWaitTime: number = 15000, onSuccess?: () => void, - onTimeout?: () => void, - shouldLogout: boolean = true + onTimeout?: () => void ): Promise { const startTime = Date.now(); @@ -22,15 +20,7 @@ export async function waitForBackendReady ( await QQManager.getQQLoginInfo({ timeout: 500 }); // 如果能走到这一步说明请求成功了 clearInterval(timer); - - // 如果需要登出,刷新页面来清除会话 - if (shouldLogout) { - window.location.reload(); - } else { - // 否则直接调用成功回调 - onSuccess?.(); - } - + onSuccess?.(); resolve(true); } catch (_e) { // 如果请求失败(后端没起来),检查是否超时