Add process restart feature via WebUI
Introduces backend and frontend support for restarting the worker process from the WebUI. Adds API endpoint, controller, and UI button for process management. Refactors napcat-shell to support master/worker process lifecycle and restart logic.
This commit is contained in:
1 parent
7c22170e1e
commit
3e8b575015
10 files changed
+338
-5
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import type { Request, Response } from 'express';
|
||||
import { WebUiDataRuntime } from '../helper/Data';
|
||||
import { sendError, sendSuccess } from '../utils/response';
|
||||
|
||||
/**
|
||||
* 重启进程处理器
|
||||
* POST /api/Process/Restart
|
||||
*/
|
||||
export async function RestartProcessHandler (_req: Request, res: Response) {
|
||||
try {
|
||||
const result = await WebUiDataRuntime.requestRestartProcess();
|
||||
|
||||
if (result.result) {
|
||||
return sendSuccess(res, { message: result.message || '进程重启请求已发送' });
|
||||
} else {
|
||||
return sendError(res, result.message || '进程重启失败', 500);
|
||||
}
|
||||
} catch (e) {
|
||||
return sendError(res, '重启进程时发生错误: ' + (e as Error).message, 500);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,9 @@ const LoginRuntime: LoginRuntimeType = {
|
||||
onQuickLoginRequested: async () => {
|
||||
return { result: false, message: '' };
|
||||
},
|
||||
onRestartProcessRequested: async () => {
|
||||
return { result: false, message: '重启功能未初始化' };
|
||||
},
|
||||
QQLoginList: [],
|
||||
NewQQLoginList: [],
|
||||
},
|
||||
@@ -163,4 +166,12 @@ export const WebUiDataRuntime = {
|
||||
getOneBotContext (): any | null {
|
||||
return LoginRuntime.OneBotContext;
|
||||
},
|
||||
|
||||
setRestartProcessCall (func: () => Promise<{ result: boolean; message: string; }>): void {
|
||||
LoginRuntime.NapCatHelper.onRestartProcessRequested = func;
|
||||
},
|
||||
|
||||
requestRestartProcess: async function () {
|
||||
return await LoginRuntime.NapCatHelper.onRestartProcessRequested();
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Router } from 'express';
|
||||
import { RestartProcessHandler } from '../api/Process';
|
||||
|
||||
const router = Router();
|
||||
|
||||
// POST /api/Process/Restart - 重启进程
|
||||
router.post('/Restart', RestartProcessHandler);
|
||||
|
||||
export { router as ProcessRouter };
|
||||
@@ -16,6 +16,7 @@ import { FileRouter } from './File';
|
||||
import { WebUIConfigRouter } from './WebUIConfig';
|
||||
import { UpdateNapCatRouter } from './UpdateNapCat';
|
||||
import DebugRouter from '@/napcat-webui-backend/src/api/Debug';
|
||||
import { ProcessRouter } from './Process';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -44,5 +45,7 @@ router.use('/WebUIConfig', WebUIConfigRouter);
|
||||
router.use('/UpdateNapCat', UpdateNapCatRouter);
|
||||
// router:调试相关路由
|
||||
router.use('/Debug', DebugRouter);
|
||||
// router:进程管理相关路由
|
||||
router.use('/Process', ProcessRouter);
|
||||
|
||||
export { router as ALLRouter };
|
||||
@@ -51,6 +51,7 @@ export interface LoginRuntimeType {
|
||||
NapCatHelper: {
|
||||
onQuickLoginRequested: (uin: string) => Promise<{ result: boolean; message: string; }>;
|
||||
onOB11ConfigChanged: (ob11: OneBotConfig) => Promise<void>;
|
||||
onRestartProcessRequested: () => Promise<{ result: boolean; message: string; }>;
|
||||
QQLoginList: string[];
|
||||
NewQQLoginList: LoginListItem[];
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user