mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
✨feat: 新增启动webui attach父进程
This commit is contained in:
parent
be8c95e6fd
commit
41352ce7e0
@ -1,3 +1,4 @@
|
||||
isOpenWebUI: false # 是否开启webui
|
||||
defaultPath: './data/rcmp4/' # 保存视频的位置
|
||||
videoSizeLimit: 70 # 视频大小限制(单位MB),超过大小则转换成群文件上传
|
||||
proxyAddr: '127.0.0.1' # 魔法地址
|
||||
|
9
index.js
9
index.js
@ -1,12 +1,15 @@
|
||||
import fs from "node:fs";
|
||||
import path from "path";
|
||||
import config from "./model/config.js";
|
||||
import { startNextJs } from "./start-nextjs.js";
|
||||
if (!global.segment) {
|
||||
global.segment = (await import("oicq")).segment
|
||||
}
|
||||
|
||||
// 加载版本号
|
||||
const versionData = config.getConfig("version");
|
||||
// 加载是否使用WebUI
|
||||
const isOpenWebUI = config.getConfig("tools").isOpenWebUI;
|
||||
// 加载名称
|
||||
const packageJsonPath = path.join('./plugins', 'rconsole-plugin', 'package.json');
|
||||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
||||
@ -35,4 +38,10 @@ for (let i in files) {
|
||||
}
|
||||
apps[name] = ret[i].value[Object.keys(ret[i].value)[0]];
|
||||
}
|
||||
|
||||
// 检查是否启动 webui
|
||||
if (isOpenWebUI) {
|
||||
startNextJs();
|
||||
}
|
||||
|
||||
export { apps };
|
||||
|
@ -2,6 +2,11 @@
|
||||
"name": "rconsole-plugin",
|
||||
"description": "R-Plugin",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "cd server && next dev -p 4016",
|
||||
"start": "cd server && next start -p 4016",
|
||||
"build": "cd server && next build"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.3.4",
|
||||
"chart.js": "^4.4.6",
|
||||
|
@ -2,8 +2,9 @@ import fs from 'fs';
|
||||
import yaml from 'js-yaml';
|
||||
import path from 'path';
|
||||
|
||||
export async function GET(req, res) {
|
||||
const configPath = path.join(process.cwd(), "../", 'config', 'tools.yaml');
|
||||
|
||||
export async function GET(req, res) {
|
||||
try {
|
||||
const yamlContent = await fs.promises.readFile(configPath, 'utf8');
|
||||
const config = yaml.load(yamlContent);
|
||||
@ -21,7 +22,6 @@ export async function GET(req, res) {
|
||||
}
|
||||
|
||||
export async function POST(req, res) {
|
||||
const configPath = path.join(process.cwd(), "../", 'config', 'tools.yaml');
|
||||
try {
|
||||
const updates = await req.json();
|
||||
|
||||
|
35
start-nextjs.js
Normal file
35
start-nextjs.js
Normal file
@ -0,0 +1,35 @@
|
||||
import { spawn } from 'child_process';
|
||||
|
||||
logger.info(`[R插件][Next.js监测], 父进程 PID: ${process.pid}`);
|
||||
|
||||
let childProcess = null;
|
||||
|
||||
// 启动子进程运行 Next.js
|
||||
export const startNextJs = () => {
|
||||
logger.info(logger.yellow('[R插件][Next.js监测],启动 Next.js 进程...'));
|
||||
// 加载名称
|
||||
childProcess = spawn('pnpm', ['run', 'dev'], {
|
||||
cwd: './plugins/rconsole-plugin', // 指定工作目录
|
||||
stdio: 'inherit' // 继承父进程的标准输入输出
|
||||
});
|
||||
|
||||
// 子进程异常退出时捕获信号
|
||||
childProcess.on('close', (code) => {
|
||||
logger.error(`[R插件][Next.js监测],Next.js 进程发生异常 ${code}`);
|
||||
childProcess = null;
|
||||
});
|
||||
};
|
||||
|
||||
// 捕获父进程退出信号
|
||||
const cleanup = () => {
|
||||
logger.info(logger.yellow('[R插件][Next.js监测] 父进程退出,终止子进程...'));
|
||||
if (childProcess) {
|
||||
childProcess.kill(); // 终止子进程
|
||||
}
|
||||
process.exit();
|
||||
};
|
||||
|
||||
// 绑定父进程的退出信号
|
||||
process.on('SIGINT', cleanup); // Ctrl+C 信号
|
||||
process.on('SIGTERM', cleanup); // kill 命令信号
|
||||
process.on('exit', cleanup); // 正常退出
|
Loading…
x
Reference in New Issue
Block a user