Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af8005dd6f | ||
|
|
6e8adad7ca | ||
|
|
0f8584b8e1 | ||
|
|
37f40a2635 | ||
|
|
1b4d604e32 | ||
|
|
81a0c07922 | ||
|
|
a8cb6b5865 | ||
|
|
d25bd65b2d | ||
|
|
e510a75f0c | ||
|
|
e3c6048a7f | ||
|
|
789c72d4cf | ||
|
|
711a060dd9 | ||
|
|
6268923f01 | ||
|
|
f6b9017429 | ||
|
|
178e51bbb8 | ||
|
|
8a232d8c68 | ||
|
|
7216755430 | ||
|
|
0c91f9c66b |
No files matched your search
@@ -80,4 +80,17 @@ jobs:
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: Bearer $GH_TOKEN" \
|
||||
https://api.github.com/repos/NapNeko/NapCatLinuxNodeLoader/actions/workflows/release.yml/dispatches \
|
||||
-d "{\"ref\":\"main\",\"inputs\":{\"napcat_version\":\"${NAPCAT_VERSION}\",\"qq_url_amd64\":\"${QQ_VERSION_X86_64}\",\"qq_url_arm64\":\"${QQ_VERSION_ARM64}\"}}"
|
||||
- name: Trigger Release NapCat AppImage Workflow
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.NAPCAT_BUILD }}
|
||||
NAPCAT_VERSION: ${{ env.latest_tag }}
|
||||
QQ_VERSION_X86_64: 'https://dldir1v6.qq.com/qqfile/qq/QQNT/94704804/linuxqq_3.2.23-44343_x86_64.AppImage' # 写死 QQ 版本
|
||||
QQ_VERSION_ARM64: 'https://dldir1v6.qq.com/qqfile/qq/QQNT/94704804/linuxqq_3.2.23-44343_arm64.AppImage' # 写死 QQ 版本
|
||||
run: |
|
||||
echo "Debug: Triggering Release NapCat AppImage with napcat_version=${NAPCAT_VERSION}, qq_url_amd64=${QQ_VERSION_X86_64}, qq_url_arm64=${QQ_VERSION_ARM64}"
|
||||
curl -X POST \
|
||||
-H "Accept: application/vnd.github+json" \
|
||||
-H "Authorization: Bearer $GH_TOKEN" \
|
||||
https://api.github.com/repos/NapNeko/NapCatLinuxNodeLoader/actions/workflows/docker-publish.yml/dispatches \
|
||||
-d "{\"ref\":\"main\",\"inputs\":{\"napcat_version\":\"${NAPCAT_VERSION}\",\"qq_url_amd64\":\"${QQ_VERSION_X86_64}\",\"qq_url_arm64\":\"${QQ_VERSION_ARM64}\"}}"
|
||||
@@ -133,7 +133,7 @@ const defaultConfig: MirrorConfig = {
|
||||
apiMirrors: GITHUB_API_MIRRORS,
|
||||
rawMirrors: GITHUB_RAW_MIRRORS,
|
||||
nightlyLinkMirrors: NIGHTLY_LINK_MIRRORS,
|
||||
timeout: 10000, // 10秒超时,平衡速度和可靠性
|
||||
timeout: 5000, // 5秒超时,平衡速度和可靠性
|
||||
enabled: true,
|
||||
customMirror: undefined,
|
||||
};
|
||||
@@ -257,7 +257,7 @@ export async function getFastMirrors (forceRefresh: boolean = false): Promise<st
|
||||
async function performMirrorTest (): Promise<string[]> {
|
||||
// 开始镜像测速
|
||||
|
||||
const timeout = 8000; // 测速超时 8 秒
|
||||
const timeout = 3000; // 测速超时 3 秒
|
||||
|
||||
// 并行测试所有镜像
|
||||
const mirrors = currentConfig.fileMirrors.filter(m => m);
|
||||
@@ -821,8 +821,8 @@ export async function getAllGitHubTags (owner: string, repo: string, mirror?: st
|
||||
// 如果指定了镜像,只使用该镜像
|
||||
mirrors = [mirror];
|
||||
} else {
|
||||
// 否则使用 auto 逻辑
|
||||
mirrors = ['', ...currentConfig.fileMirrors.filter(m => m)];
|
||||
// 否则使用 auto 逻辑,利用缓存的快速镜像列表
|
||||
mirrors = await getFastMirrors();
|
||||
}
|
||||
|
||||
// 并行请求
|
||||
@@ -907,7 +907,8 @@ async function getWorkflowRunsFromHtml (
|
||||
if (mirror) {
|
||||
mirrors = [mirror];
|
||||
} else {
|
||||
mirrors = ['', ...currentConfig.fileMirrors.filter(m => m)];
|
||||
// 使用缓存的快速镜像列表
|
||||
mirrors = await getFastMirrors();
|
||||
}
|
||||
|
||||
for (const mirrorItem of mirrors) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -587,15 +587,33 @@ export class OneBotMsgApi {
|
||||
return at(atQQ, uid, NTMsgAtType.ATTYPEONE, info.nick || '');
|
||||
},
|
||||
|
||||
[OB11MessageDataType.reply]: async ({ data: { id } }) => {
|
||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||
if (!replyMsgM) {
|
||||
this.core.context.logger.logWarn('回复消息不存在', id);
|
||||
[OB11MessageDataType.reply]: async ({ data: { id, seq } }, context) => {
|
||||
let replyMsg: RawMessage | undefined;
|
||||
let replyMsgPeer: Peer | undefined;
|
||||
|
||||
// 优先使用 seq
|
||||
if (seq) {
|
||||
const msgList = (await this.core.apis.MsgApi.getMsgsBySeqAndCount(
|
||||
context.peer, seq.toString(), 1, true, true
|
||||
)).msgList;
|
||||
replyMsg = msgList[0];
|
||||
replyMsgPeer = context.peer;
|
||||
} else if (id) {
|
||||
// 降级使用 id
|
||||
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
|
||||
if (!replyMsgM) {
|
||||
this.core.context.logger.logWarn('回复消息不存在', id);
|
||||
return undefined;
|
||||
}
|
||||
replyMsg = (await this.core.apis.MsgApi.getMsgsByMsgId(
|
||||
replyMsgM.Peer, [replyMsgM.MsgId])).msgList[0];
|
||||
replyMsgPeer = replyMsgM.Peer;
|
||||
} else {
|
||||
this.core.context.logger.logWarn('回复消息缺少id或seq参数');
|
||||
return undefined;
|
||||
}
|
||||
const replyMsg = (await this.core.apis.MsgApi.getMsgsByMsgId(
|
||||
replyMsgM.Peer, [replyMsgM.MsgId])).msgList[0];
|
||||
return replyMsg
|
||||
|
||||
return replyMsg && replyMsgPeer
|
||||
? {
|
||||
elementType: ElementType.REPLY,
|
||||
elementId: '',
|
||||
@@ -605,7 +623,7 @@ export class OneBotMsgApi {
|
||||
senderUin: replyMsg.senderUin,
|
||||
senderUinStr: replyMsg.senderUin,
|
||||
replyMsgClientSeq: replyMsg.clientSeq,
|
||||
_replyMsgPeer: replyMsgM.Peer,
|
||||
_replyMsgPeer: replyMsgPeer,
|
||||
},
|
||||
}
|
||||
: undefined;
|
||||
|
||||
@@ -103,7 +103,7 @@ export interface OB11MessageText {
|
||||
}
|
||||
|
||||
// 联系人消息接口定义
|
||||
export interface OB11MessageContext {
|
||||
export interface OB11MessageContact {
|
||||
type: OB11MessageDataType.contact;
|
||||
data: {
|
||||
type: 'qq' | 'group';
|
||||
@@ -159,7 +159,8 @@ export interface OB11MessageAt {
|
||||
export interface OB11MessageReply {
|
||||
type: OB11MessageDataType.reply;
|
||||
data: {
|
||||
id: string;
|
||||
id?: string; // msg_id 的短ID映射
|
||||
seq?: number; // msg_seq,优先使用
|
||||
};
|
||||
}
|
||||
|
||||
@@ -260,7 +261,7 @@ export type OB11MessageData =
|
||||
OB11MessageAt | OB11MessageReply |
|
||||
OB11MessageImage | OB11MessageRecord | OB11MessageFile | OB11MessageVideo |
|
||||
OB11MessageNode | OB11MessageIdMusic | OB11MessageCustomMusic | OB11MessageJson |
|
||||
OB11MessageDice | OB11MessageRPS | OB11MessageMarkdown | OB11MessageForward | OB11MessageContext | OB11MessagePoke;
|
||||
OB11MessageDice | OB11MessageRPS | OB11MessageMarkdown | OB11MessageForward | OB11MessageContact | OB11MessagePoke;
|
||||
|
||||
// 发送消息接口定义
|
||||
export interface OB11PostSendMsg {
|
||||
|
||||
@@ -35,6 +35,7 @@ import { proxiedListenerOf } from '@/napcat-core/helper/proxy-handler';
|
||||
import { QQBasicInfoWrapper } from '@/napcat-core/helper/qq-basic-info';
|
||||
import { statusHelperSubscription } from '@/napcat-core/helper/status';
|
||||
import { applyPendingUpdates } from '@/napcat-webui-backend/src/api/UpdateNapCat';
|
||||
import { connectToNamedPipe } from './pipe';
|
||||
// NapCat Shell App ES 入口文件
|
||||
async function handleUncaughtExceptions (logger: LogWrapper) {
|
||||
process.on('uncaughtException', (err) => {
|
||||
@@ -342,9 +343,9 @@ export async function NCoreInitShell () {
|
||||
// 初始化 FFmpeg 服务
|
||||
await FFmpegService.init(pathWrapper.binaryPath, logger);
|
||||
|
||||
// if (process.env['NAPCAT_DISABLE_PIPE'] !== '1') {
|
||||
// await connectToNamedPipe(logger).catch(e => logger.logError('命名管道连接失败', e));
|
||||
// }
|
||||
if (!(process.env['NAPCAT_DISABLE_PIPE'] == '1' || process.env['NAPCAT_WORKER_PROCESS'] == '1')) {
|
||||
await connectToNamedPipe(logger).catch(e => logger.logError('命名管道连接失败', e));
|
||||
}
|
||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVersion());
|
||||
const nativePacketHandler = new NativePacketHandler({ logger }); // 初始化 NativePacketHandler 用于后续使用
|
||||
|
||||
@@ -4,6 +4,7 @@ import { LogWrapper } from '@/napcat-core/helper/log';
|
||||
import { connectToNamedPipe } from './pipe';
|
||||
import { WebUiDataRuntime } from '@/napcat-webui-backend/src/helper/Data';
|
||||
import { AuthHelper } from '@/napcat-webui-backend/src/helper/SignToken';
|
||||
import { webUiRuntimePort } from '@/napcat-webui-backend/index';
|
||||
import { createProcessManager, type IProcessManager, type IWorkerProcess } from './process-api';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
@@ -19,6 +20,13 @@ const ENV = {
|
||||
isPipeDisabled: process.env['NAPCAT_DISABLE_PIPE'] === '1',
|
||||
} as const;
|
||||
|
||||
// Worker 消息类型
|
||||
interface WorkerMessage {
|
||||
type: 'restart' | 'restart-prepare' | 'shutdown';
|
||||
secretKey?: string;
|
||||
port?: number;
|
||||
}
|
||||
|
||||
// 初始化日志
|
||||
const pathWrapper = new NapCatPathWrapper();
|
||||
const logger = new LogWrapper(pathWrapper.logsPath);
|
||||
@@ -28,6 +36,7 @@ let processManager: IProcessManager | null = null;
|
||||
let currentWorker: IWorkerProcess | null = null;
|
||||
let isElectron = false;
|
||||
let isRestarting = false;
|
||||
let isShuttingDown = false;
|
||||
|
||||
/**
|
||||
* 获取进程类型名称(用于日志)
|
||||
@@ -63,17 +72,24 @@ function isProcessAlive (pid: number): boolean {
|
||||
function forceKillProcess (pid: number): void {
|
||||
try {
|
||||
process.kill(pid, 'SIGKILL');
|
||||
logger.log(`[NapCat] [Process] 已强制终止进程 ${pid}`);
|
||||
} catch (error) {
|
||||
logger.logError(`[NapCat] [Process] 强制终止进程失败:`, error);
|
||||
// SIGKILL 失败,在 Windows 上使用 taskkill 兜底
|
||||
if (process.platform === 'win32') {
|
||||
try {
|
||||
require('child_process').execSync(`taskkill /F /PID ${pid}`, { stdio: 'ignore' });
|
||||
} catch {
|
||||
logger.logError(`[NapCat] [Process] 强制终止进程失败: PID ${pid}`);
|
||||
}
|
||||
} else {
|
||||
logger.logError(`[NapCat] [Process] 强制终止进程失败:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重启 Worker 进程
|
||||
*/
|
||||
export async function restartWorker (secretKey?: string): Promise<void> {
|
||||
logger.log('[NapCat] [Process] 正在重启Worker进程...');
|
||||
export async function restartWorker (secretKey?: string, port?: number): Promise<void> {
|
||||
isRestarting = true;
|
||||
|
||||
if (!currentWorker) {
|
||||
@@ -84,7 +100,6 @@ export async function restartWorker (secretKey?: string): Promise<void> {
|
||||
}
|
||||
|
||||
const workerPid = currentWorker.pid;
|
||||
logger.log(`[NapCat] [Process] 准备关闭Worker进程,PID: ${workerPid}`);
|
||||
|
||||
// 1. 通知旧进程准备重启(旧进程会自行退出)
|
||||
currentWorker.postMessage({ type: 'restart-prepare' });
|
||||
@@ -105,47 +120,35 @@ export async function restartWorker (secretKey?: string): Promise<void> {
|
||||
|
||||
currentWorker?.once('exit', () => {
|
||||
clearTimeout(timeout);
|
||||
logger.log('[NapCat] [Process] Worker进程已正常退出');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
// 3. 二次确认进程是否真的被终止(兜底检查)
|
||||
if (workerPid) {
|
||||
logger.log(`[NapCat] [Process] 检查进程 ${workerPid} 是否已终止...`);
|
||||
|
||||
if (workerPid && isProcessAlive(workerPid)) {
|
||||
logger.logWarn(`[NapCat] [Process] 进程 ${workerPid} 仍在运行,尝试强制杀掉`);
|
||||
forceKillProcess(workerPid);
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
if (isProcessAlive(workerPid)) {
|
||||
logger.logWarn(`[NapCat] [Process] 进程 ${workerPid} 仍在运行,尝试强制杀掉(兜底)`);
|
||||
forceKillProcess(workerPid);
|
||||
|
||||
// 等待 1 秒后再次检查
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
if (isProcessAlive(workerPid)) {
|
||||
logger.logError(`[NapCat] [Process] 进程 ${workerPid} 无法终止,可能需要手动处理`);
|
||||
} else {
|
||||
logger.log(`[NapCat] [Process] 进程 ${workerPid} 已被强制终止`);
|
||||
}
|
||||
} else {
|
||||
logger.log(`[NapCat] [Process] 进程 ${workerPid} 已确认终止`);
|
||||
logger.logError(`[NapCat] [Process] 进程 ${workerPid} 无法终止,可能需要手动处理`);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 等待 3 秒后启动新进程
|
||||
logger.log('[NapCat] [Process] Worker进程已关闭,等待 3 秒后启动新进程...');
|
||||
// 4. 等待后启动新进程
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
|
||||
// 5. 启动新进程(重启模式不传递快速登录参数,传递密钥)
|
||||
await startWorker(false, secretKey);
|
||||
// 5. 启动新进程(重启模式不传递快速登录参数,传递密钥和端口)
|
||||
await startWorker(false, secretKey, port);
|
||||
isRestarting = false;
|
||||
logger.log('[NapCat] [Process] Worker进程重启完成');
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动 Worker 进程
|
||||
* @param passQuickLogin 是否传递快速登录参数,默认为 true,重启时为 false
|
||||
* @param secretKey WebUI JWT 密钥
|
||||
* @param preferredPort 优先使用的 WebUI 端口
|
||||
*/
|
||||
async function startWorker (passQuickLogin: boolean = true, secretKey?: string): Promise<void> {
|
||||
async function startWorker (passQuickLogin: boolean = true, secretKey?: string, preferredPort?: number): Promise<void> {
|
||||
if (!processManager) {
|
||||
throw new Error('进程管理器未初始化');
|
||||
}
|
||||
@@ -172,6 +175,7 @@ async function startWorker (passQuickLogin: boolean = true, secretKey?: string):
|
||||
...process.env,
|
||||
NAPCAT_WORKER_PROCESS: '1',
|
||||
...(secretKey ? { NAPCAT_WEBUI_JWT_SECRET_KEY: secretKey } : {}),
|
||||
...(preferredPort ? { NAPCAT_WEBUI_PREFERRED_PORT: String(preferredPort) } : {}),
|
||||
},
|
||||
stdio: isElectron ? 'pipe' : ['inherit', 'pipe', 'pipe', 'ipc'],
|
||||
});
|
||||
@@ -194,15 +198,14 @@ async function startWorker (passQuickLogin: boolean = true, secretKey?: string):
|
||||
|
||||
// 监听子进程消息
|
||||
child.on('message', (msg: unknown) => {
|
||||
logger.log(`[NapCat] [${processType}] 收到Worker消息:`, msg);
|
||||
|
||||
// 处理重启请求
|
||||
if (typeof msg === 'object' && msg !== null && 'type' in msg && msg.type === 'restart') {
|
||||
logger.log(`[NapCat] [${processType}] 收到重启请求,正在重启Worker进程...`);
|
||||
const secretKey = 'secretKey' in msg ? (msg as any).secretKey : undefined;
|
||||
restartWorker(secretKey).catch(e => {
|
||||
logger.logError(`[NapCat] [${processType}] 重启Worker进程失败:`, e);
|
||||
});
|
||||
if (typeof msg === 'object' && msg !== null && 'type' in msg) {
|
||||
const message = msg as WorkerMessage;
|
||||
if (message.type === 'restart') {
|
||||
restartWorker(message.secretKey, message.port).catch(e => {
|
||||
logger.logError(`[NapCat] [${processType}] 重启Worker进程失败:`, e);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -211,11 +214,9 @@ async function startWorker (passQuickLogin: boolean = true, secretKey?: string):
|
||||
const exitCode = typeof code === 'number' ? code : 0;
|
||||
if (exitCode !== 0) {
|
||||
logger.logError(`[NapCat] [${processType}] Worker进程退出,退出码: ${exitCode}`);
|
||||
} else {
|
||||
logger.log(`[NapCat] [${processType}] Worker进程正常退出`);
|
||||
}
|
||||
// 如果不是由于主动重启引起的退出,尝试自动重新拉起(保留快速登录参数)
|
||||
if (!isRestarting) {
|
||||
// 如果不是由于主动重启或关闭引起的退出,尝试自动重新拉起
|
||||
if (!isRestarting && !isShuttingDown) {
|
||||
logger.logWarn(`[NapCat] [${processType}] Worker进程意外退出,正在尝试重新拉起...`);
|
||||
startWorker(true).catch(e => {
|
||||
logger.logError(`[NapCat] [${processType}] 重新拉起Worker进程失败:`, e);
|
||||
@@ -223,8 +224,20 @@ async function startWorker (passQuickLogin: boolean = true, secretKey?: string):
|
||||
}
|
||||
});
|
||||
|
||||
child.on('spawn', () => {
|
||||
logger.log(`[NapCat] [${processType}] Worker进程已生成`);
|
||||
// 等待进程成功 spawn
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const onSpawn = () => {
|
||||
child.off('error', onError);
|
||||
resolve();
|
||||
};
|
||||
const onError = (...args: unknown[]) => {
|
||||
const err = args[0] as Error;
|
||||
logger.logError(`[NapCat] [${processType}] Worker进程启动失败:`, err);
|
||||
child.off('spawn', onSpawn);
|
||||
reject(err);
|
||||
};
|
||||
child.once('spawn', onSpawn);
|
||||
child.once('error', onError);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -232,25 +245,19 @@ async function startWorker (passQuickLogin: boolean = true, secretKey?: string):
|
||||
* 启动 Master 进程
|
||||
*/
|
||||
async function startMasterProcess (): Promise<void> {
|
||||
const processType = getProcessTypeName();
|
||||
logger.log(`[NapCat] [${processType}] Master进程启动,PID: ${process.pid}`);
|
||||
|
||||
// 连接命名管道(可通过环境变量禁用)
|
||||
if (!ENV.isPipeDisabled) {
|
||||
await connectToNamedPipe(logger).catch(e =>
|
||||
logger.logError('命名管道连接失败', e)
|
||||
);
|
||||
} else {
|
||||
logger.log(`[NapCat] [${processType}] 命名管道已禁用 (NAPCAT_DISABLE_PIPE=1)`);
|
||||
}
|
||||
|
||||
// 启动 Worker 进程
|
||||
await startWorker();
|
||||
|
||||
// 优雅关闭处理
|
||||
const shutdown = (signal: string) => {
|
||||
logger.log(`[NapCat] [Process] 收到${signal}信号,正在关闭...`);
|
||||
|
||||
const shutdown = () => {
|
||||
isShuttingDown = true;
|
||||
if (currentWorker) {
|
||||
currentWorker.postMessage({ type: 'shutdown' });
|
||||
setTimeout(() => {
|
||||
@@ -262,8 +269,8 @@ async function startMasterProcess (): Promise<void> {
|
||||
}
|
||||
};
|
||||
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
process.on('SIGINT', () => shutdown());
|
||||
process.on('SIGTERM', () => shutdown());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,20 +281,25 @@ async function startWorkerProcess (): Promise<void> {
|
||||
throw new Error('进程管理器未初始化');
|
||||
}
|
||||
|
||||
const processType = getProcessTypeName();
|
||||
logger.log(`[NapCat] [${processType}] Worker进程启动,PID: ${process.pid}`);
|
||||
// 预加载 Node Addon(如果设置了环境变量)
|
||||
const preloadAddonPath = process.env['NAPCAT_PRELOAD_NODE_ADDON_PATH'];
|
||||
if (preloadAddonPath) {
|
||||
try {
|
||||
const os = await import('os');
|
||||
process.dlopen({ exports: {} }, preloadAddonPath, os.constants.dlopen.RTLD_NOW | os.constants.dlopen.RTLD_GLOBAL);
|
||||
logger.log(`[NapCat] [Worker] 已预加载 Node Addon: ${preloadAddonPath}`);
|
||||
} catch (error) {
|
||||
logger.logError(`[NapCat] [Worker] 预加载 Node Addon 失败: ${preloadAddonPath}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// 监听来自父进程的消息
|
||||
processManager.onParentMessage((msg: unknown) => {
|
||||
if (typeof msg === 'object' && msg !== null && 'type' in msg) {
|
||||
if (msg.type === 'restart-prepare') {
|
||||
logger.log(`[NapCat] [${processType}] 收到重启准备信号,正在主动退出...`);
|
||||
if (msg.type === 'restart-prepare' || msg.type === 'shutdown') {
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 100);
|
||||
} else if (msg.type === 'shutdown') {
|
||||
logger.log(`[NapCat] [${processType}] 收到关闭信号,正在退出...`);
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -295,8 +307,11 @@ async function startWorkerProcess (): Promise<void> {
|
||||
// 注册重启进程函数到 WebUI
|
||||
WebUiDataRuntime.setRestartProcessCall(async () => {
|
||||
try {
|
||||
const success = processManager!.sendToParent({ type: 'restart', secretKey: AuthHelper.getSecretKey() });
|
||||
|
||||
const success = processManager!.sendToParent({
|
||||
type: 'restart',
|
||||
secretKey: AuthHelper.getSecretKey(),
|
||||
port: webUiRuntimePort,
|
||||
});
|
||||
|
||||
if (success) {
|
||||
return { result: true, message: '进程重启请求已发送' };
|
||||
@@ -322,7 +337,6 @@ async function startWorkerProcess (): Promise<void> {
|
||||
async function main (): Promise<void> {
|
||||
// 单进程模式:直接启动核心
|
||||
if (ENV.isMultiProcessDisabled) {
|
||||
logger.log('[NapCat] [SingleProcess] 多进程模式已禁用,直接启动核心');
|
||||
await NCoreInitShell();
|
||||
return;
|
||||
}
|
||||
@@ -332,8 +346,6 @@ async function main (): Promise<void> {
|
||||
processManager = result.manager;
|
||||
isElectron = result.isElectron;
|
||||
|
||||
logger.log(`[NapCat] [Process] 检测到 ${isElectron ? 'Electron' : 'Node.js'} 环境`);
|
||||
|
||||
// 根据进程类型启动
|
||||
if (ENV.isWorkerProcess) {
|
||||
await startWorkerProcess();
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface IWorkerProcess {
|
||||
kill (): boolean;
|
||||
on (event: string, listener: (...args: unknown[]) => void): void;
|
||||
once (event: string, listener: (...args: unknown[]) => void): void;
|
||||
off (event: string, listener: (...args: unknown[]) => void): void;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,6 +80,10 @@ class ElectronProcessManager implements IProcessManager {
|
||||
once (event: string, listener: (...args: unknown[]) => void): void {
|
||||
child.once(event, listener);
|
||||
},
|
||||
|
||||
off (event: string, listener: (...args: unknown[]) => void): void {
|
||||
child.off(event, listener);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -134,6 +139,10 @@ class NodeProcessManager implements IProcessManager {
|
||||
once (event: string, listener: (...args: unknown[]) => void): void {
|
||||
child.once(event, listener);
|
||||
},
|
||||
|
||||
off (event: string, listener: (...args: unknown[]) => void): void {
|
||||
child.off(event, listener);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,19 @@ export function setPendingTokenToSend (token: string | null) {
|
||||
export async function InitPort (parsedConfig: WebUiConfigType): Promise<[string, number, string]> {
|
||||
try {
|
||||
await tryUseHost(parsedConfig.host);
|
||||
const port = await tryUsePort(parsedConfig.port, parsedConfig.host, 0, 5);
|
||||
const preferredPort = parseInt(process.env['NAPCAT_WEBUI_PREFERRED_PORT'] || '', 10);
|
||||
|
||||
let port: number;
|
||||
if (preferredPort > 0) {
|
||||
try {
|
||||
port = await tryUsePort(preferredPort, parsedConfig.host, 0, true);
|
||||
} catch {
|
||||
port = await tryUsePort(parsedConfig.port, parsedConfig.host);
|
||||
}
|
||||
} else {
|
||||
port = await tryUsePort(parsedConfig.port, parsedConfig.host);
|
||||
}
|
||||
|
||||
return [parsedConfig.host, port, parsedConfig.token];
|
||||
} catch (error) {
|
||||
console.log('host或port不可用', error);
|
||||
@@ -356,7 +368,7 @@ async function tryUseHost (host: string): Promise<string> {
|
||||
});
|
||||
}
|
||||
|
||||
async function tryUsePort (port: number, host: string, tryCount: number = 0, retryCurrentCount: number = 0): Promise<number> {
|
||||
async function tryUsePort (port: number, host: string, tryCount: number = 0, singleTry: boolean = false): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const server = net.createServer();
|
||||
@@ -367,17 +379,12 @@ async function tryUsePort (port: number, host: string, tryCount: number = 0, ret
|
||||
|
||||
server.on('error', (err: any) => {
|
||||
if (err.code === 'EADDRINUSE') {
|
||||
if (retryCurrentCount > 0) {
|
||||
console.log(`[NapCat] [WebUi] 端口 ${port} 被占用,1秒后重试... (剩余重试次数: ${retryCurrentCount})`);
|
||||
setTimeout(() => {
|
||||
resolve(tryUsePort(port, host, tryCount, retryCurrentCount - 1));
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (tryCount < MAX_PORT_TRY) {
|
||||
// 使用循环代替递归
|
||||
resolve(tryUsePort(port + 1, host, tryCount + 1, 0));
|
||||
if (singleTry) {
|
||||
// 只尝试一次,端口被占用则直接失败
|
||||
reject(new Error(`端口 ${port} 已被占用`));
|
||||
} else if (tryCount < MAX_PORT_TRY) {
|
||||
// 递归尝试下一个端口
|
||||
resolve(tryUsePort(port + 1, host, tryCount + 1, false));
|
||||
} else {
|
||||
reject(new Error(`端口尝试失败,达到最大尝试次数: ${MAX_PORT_TRY}`));
|
||||
}
|
||||
@@ -394,4 +401,3 @@ async function tryUsePort (port: number, host: string, tryCount: number = 0, ret
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ const NetworkDisplayCard = <T extends keyof NetworkType> ({
|
||||
onPress={handleEnableDebug}
|
||||
isDisabled={editing}
|
||||
>
|
||||
{debug ? '关闭调试' : '开启调试'}
|
||||
{debug ? '默认' : '调试'}
|
||||
</Button>
|
||||
<Button
|
||||
fullWidth
|
||||
|
||||
@@ -253,17 +253,17 @@ const NewVersionTip = (props: NewVersionTipProps) => {
|
||||
|
||||
return (
|
||||
<Tooltip content='有新版本可用'>
|
||||
<div className="cursor-pointer" onClick={updateStatus === 'updating' ? undefined : showUpdateDialog}>
|
||||
<div className="cursor-pointer flex items-center justify-center" onClick={updateStatus === 'updating' ? undefined : showUpdateDialog}>
|
||||
<Chip
|
||||
size="sm"
|
||||
color="danger"
|
||||
variant="flat"
|
||||
classNames={{
|
||||
content: "font-bold text-[10px] px-1",
|
||||
base: "h-5 min-h-5"
|
||||
content: "font-bold text-[10px] px-1 flex items-center justify-center",
|
||||
base: "h-5 min-h-5 min-w-[42px]"
|
||||
}}
|
||||
>
|
||||
{updateStatus === 'updating' ? <Spinner size="sm" color="danger" /> : 'New'}
|
||||
{updateStatus === 'updating' ? <Spinner size="sm" color="danger" classNames={{ wrapper: "w-3 h-3" }} /> : 'New'}
|
||||
</Chip>
|
||||
</div>
|
||||
</Tooltip>
|
||||
|
||||
@@ -61,7 +61,8 @@ const messageNode = z.union([
|
||||
.object({
|
||||
type: z.literal('reply'),
|
||||
data: z.object({
|
||||
id: z.number(),
|
||||
id: z.number().optional(),
|
||||
seq: z.number().optional(),
|
||||
}),
|
||||
})
|
||||
.describe('回复消息'),
|
||||
|
||||
@@ -24,196 +24,197 @@ export type OB11SegmentType =
|
||||
| 'file';
|
||||
|
||||
export interface Segment {
|
||||
type: OB11SegmentType
|
||||
type: OB11SegmentType;
|
||||
}
|
||||
|
||||
/** 纯文本 */
|
||||
export interface TextSegment extends Segment {
|
||||
type: 'text'
|
||||
type: 'text';
|
||||
data: {
|
||||
text: string
|
||||
}
|
||||
text: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** QQ表情 */
|
||||
export interface FaceSegment extends Segment {
|
||||
type: 'face'
|
||||
type: 'face';
|
||||
data: {
|
||||
id: string
|
||||
}
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 图片消息段 */
|
||||
export interface ImageSegment extends Segment {
|
||||
type: 'image'
|
||||
type: 'image';
|
||||
data: {
|
||||
file: string
|
||||
type?: 'flash'
|
||||
url?: string
|
||||
cache?: 0 | 1
|
||||
proxy?: 0 | 1
|
||||
timeout?: number
|
||||
}
|
||||
file: string;
|
||||
type?: 'flash';
|
||||
url?: string;
|
||||
cache?: 0 | 1;
|
||||
proxy?: 0 | 1;
|
||||
timeout?: number;
|
||||
};
|
||||
}
|
||||
|
||||
/** 语音消息段 */
|
||||
export interface RecordSegment extends Segment {
|
||||
type: 'record'
|
||||
type: 'record';
|
||||
data: {
|
||||
file: string
|
||||
magic?: 0 | 1
|
||||
url?: string
|
||||
cache?: 0 | 1
|
||||
proxy?: 0 | 1
|
||||
timeout?: number
|
||||
}
|
||||
file: string;
|
||||
magic?: 0 | 1;
|
||||
url?: string;
|
||||
cache?: 0 | 1;
|
||||
proxy?: 0 | 1;
|
||||
timeout?: number;
|
||||
};
|
||||
}
|
||||
|
||||
/** 短视频消息段 */
|
||||
export interface VideoSegment extends Segment {
|
||||
type: 'video'
|
||||
type: 'video';
|
||||
data: {
|
||||
file: string
|
||||
url?: string
|
||||
cache?: 0 | 1
|
||||
proxy?: 0 | 1
|
||||
timeout?: number
|
||||
}
|
||||
file: string;
|
||||
url?: string;
|
||||
cache?: 0 | 1;
|
||||
proxy?: 0 | 1;
|
||||
timeout?: number;
|
||||
};
|
||||
}
|
||||
|
||||
/** @某人消息段 */
|
||||
export interface AtSegment extends Segment {
|
||||
type: 'at'
|
||||
type: 'at';
|
||||
data: {
|
||||
qq: string | 'all'
|
||||
name?: string
|
||||
}
|
||||
qq: string | 'all';
|
||||
name?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 猜拳魔法表情消息段 */
|
||||
export interface RpsSegment extends Segment {
|
||||
type: 'rps'
|
||||
type: 'rps';
|
||||
}
|
||||
|
||||
/** 掷骰子魔法表情消息段 */
|
||||
export interface DiceSegment extends Segment {
|
||||
type: 'dice'
|
||||
type: 'dice';
|
||||
}
|
||||
|
||||
/** 窗口抖动(戳一戳)消息段 */
|
||||
export interface ShakeSegment extends Segment {
|
||||
type: 'shake'
|
||||
data: object
|
||||
type: 'shake';
|
||||
data: object;
|
||||
}
|
||||
|
||||
/** 戳一戳消息段 */
|
||||
export interface PokeSegment extends Segment {
|
||||
type: 'poke'
|
||||
type: 'poke';
|
||||
data: {
|
||||
type: string
|
||||
id: string
|
||||
name?: string
|
||||
}
|
||||
type: string;
|
||||
id: string;
|
||||
name?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 匿名发消息消息段 */
|
||||
export interface AnonymousSegment extends Segment {
|
||||
type: 'anonymous'
|
||||
type: 'anonymous';
|
||||
data: {
|
||||
ignore?: 0 | 1
|
||||
}
|
||||
ignore?: 0 | 1;
|
||||
};
|
||||
}
|
||||
|
||||
/** 链接分享消息段 */
|
||||
export interface ShareSegment extends Segment {
|
||||
type: 'share'
|
||||
type: 'share';
|
||||
data: {
|
||||
url: string
|
||||
title: string
|
||||
content?: string
|
||||
image?: string
|
||||
}
|
||||
url: string;
|
||||
title: string;
|
||||
content?: string;
|
||||
image?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 推荐好友/群消息段 */
|
||||
export interface ContactSegment extends Segment {
|
||||
type: 'contact'
|
||||
type: 'contact';
|
||||
data: {
|
||||
type: 'qq' | 'group'
|
||||
id: string
|
||||
}
|
||||
type: 'qq' | 'group';
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 位置消息段 */
|
||||
export interface LocationSegment extends Segment {
|
||||
type: 'location'
|
||||
type: 'location';
|
||||
data: {
|
||||
lat: string
|
||||
lon: string
|
||||
title?: string
|
||||
content?: string
|
||||
}
|
||||
lat: string;
|
||||
lon: string;
|
||||
title?: string;
|
||||
content?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 音乐分享消息段 */
|
||||
export interface MusicSegment extends Segment {
|
||||
type: 'music'
|
||||
type: 'music';
|
||||
data: {
|
||||
type: 'qq' | '163' | 'xm'
|
||||
id: string
|
||||
}
|
||||
type: 'qq' | '163' | 'xm';
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 音乐自定义分享消息段 */
|
||||
export interface CustomMusicSegment extends Segment {
|
||||
type: 'music'
|
||||
type: 'music';
|
||||
data: {
|
||||
type: 'custom'
|
||||
url: string
|
||||
audio: string
|
||||
title: string
|
||||
content?: string
|
||||
image?: string
|
||||
}
|
||||
type: 'custom';
|
||||
url: string;
|
||||
audio: string;
|
||||
title: string;
|
||||
content?: string;
|
||||
image?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 回复消息段 */
|
||||
export interface ReplySegment extends Segment {
|
||||
type: 'reply'
|
||||
type: 'reply';
|
||||
data: {
|
||||
id: string
|
||||
}
|
||||
id?: string; // msg_id 的短ID映射
|
||||
seq?: number; // msg_seq,优先使用
|
||||
};
|
||||
}
|
||||
|
||||
export interface FileSegment extends Segment {
|
||||
type: 'file'
|
||||
type: 'file';
|
||||
data: {
|
||||
file: string
|
||||
}
|
||||
file: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 合并转发消息段 */
|
||||
export interface ForwardSegment extends Segment {
|
||||
type: 'forward'
|
||||
type: 'forward';
|
||||
data: {
|
||||
id: string
|
||||
}
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** XML消息段 */
|
||||
export interface XmlSegment extends Segment {
|
||||
type: 'xml'
|
||||
type: 'xml';
|
||||
data: {
|
||||
data: string
|
||||
}
|
||||
data: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** JSON消息段 */
|
||||
export interface JsonSegment extends Segment {
|
||||
type: 'json'
|
||||
type: 'json';
|
||||
data: {
|
||||
data: string
|
||||
}
|
||||
data: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** OneBot11消息段 */
|
||||
@@ -242,23 +243,23 @@ export type OB11SegmentBase =
|
||||
|
||||
/** 合并转发已有消息节点消息段 */
|
||||
export interface DirectNodeSegment extends Segment {
|
||||
type: 'node'
|
||||
type: 'node';
|
||||
data: {
|
||||
id: string
|
||||
}
|
||||
id: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 合并转发自定义节点消息段 */
|
||||
export interface CustomNodeSegments extends Segment {
|
||||
type: 'node'
|
||||
type: 'node';
|
||||
data: {
|
||||
user_id: string
|
||||
nickname: string
|
||||
content: OB11Segment[]
|
||||
prompt?: string
|
||||
summary?: string
|
||||
source?: string
|
||||
}
|
||||
user_id: string;
|
||||
nickname: string;
|
||||
content: OB11Segment[];
|
||||
prompt?: string;
|
||||
summary?: string;
|
||||
source?: string;
|
||||
};
|
||||
}
|
||||
|
||||
/** 合并转发消息段 */
|
||||
|
||||
Reference in new issue
Block a user