Support passing JWT secret key on worker restart

Added the ability to pass a JWT secret key when restarting the worker process by updating environment variable handling and message passing. Improved port retry logic in the backend to allow multiple attempts on the same port before incrementing. Also refactored process API to use getter for pid property.

Ensure Electron app is ready before creating process manager

Adds a check to await electron.app.whenReady() if the Electron app is not yet ready before instantiating the ElectronProcessManager. This prevents potential issues when accessing Electron APIs before the app is fully initialized.

Add mirror selection support for version updates

Introduces the ability to specify and select GitHub mirror sources for fetching tags, releases, and action artifacts throughout the backend and frontend. Updates API endpoints, internal helper functions, and UI components to allow users to choose a mirror for version queries and updates, improving reliability in regions with limited GitHub access. Also enhances version comparison logic and improves artifact metadata display.

Refactor artifact fetching to use HTML parsing only

Removed all GitHub API dependencies for fetching workflow runs and artifacts. Now, workflow runs are parsed directly from the HTML of the Actions page, and artifact URLs are constructed using nightly.link. Also added workflow title and mirror fields to ActionArtifact, and simplified mirror list without latency comments.
This commit is contained in:
手瓜一十雪 committed 2026-01-18 11:13:08 +08:00
1 parent 96d70d07ca
commit a5a6f14cec
12 files changed
+440 -376

No files matched your search

+10 -6
View File
@@ -3,6 +3,7 @@ import { NapCatPathWrapper } from '@/napcat-common/src/path';
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 { createProcessManager, type IProcessManager, type IWorkerProcess } from './process-api';
import path from 'path';
import { fileURLToPath } from 'url';
@@ -71,7 +72,7 @@ function forceKillProcess (pid: number): void {
/**
* 重启 Worker 进程
*/
export async function restartWorker (): Promise<void> {
export async function restartWorker (secretKey?: string): Promise<void> {
logger.log('[NapCat] [Process] 正在重启Worker进程...');
isRestarting = true;
@@ -134,8 +135,8 @@ export async function restartWorker (): Promise<void> {
logger.log('[NapCat] [Process] Worker进程已关闭,等待 3 秒后启动新进程...');
await new Promise(resolve => setTimeout(resolve, 3000));
// 5. 启动新进程(重启模式不传递快速登录参数)
await startWorker(false);
// 5. 启动新进程(重启模式不传递快速登录参数,传递密钥)
await startWorker(false, secretKey);
isRestarting = false;
logger.log('[NapCat] [Process] Worker进程重启完成');
}
@@ -144,7 +145,7 @@ export async function restartWorker (): Promise<void> {
* 启动 Worker 进程
* @param passQuickLogin 是否传递快速登录参数,默认为 true,重启时为 false
*/
async function startWorker (passQuickLogin: boolean = true): Promise<void> {
async function startWorker (passQuickLogin: boolean = true, secretKey?: string): Promise<void> {
if (!processManager) {
throw new Error('进程管理器未初始化');
}
@@ -170,6 +171,7 @@ async function startWorker (passQuickLogin: boolean = true): Promise<void> {
env: {
...process.env,
NAPCAT_WORKER_PROCESS: '1',
...(secretKey ? { NAPCAT_WEBUI_JWT_SECRET_KEY: secretKey } : {}),
},
stdio: isElectron ? 'pipe' : ['inherit', 'pipe', 'pipe', 'ipc'],
});
@@ -197,7 +199,8 @@ async function startWorker (passQuickLogin: boolean = true): Promise<void> {
// 处理重启请求
if (typeof msg === 'object' && msg !== null && 'type' in msg && msg.type === 'restart') {
logger.log(`[NapCat] [${processType}] 收到重启请求,正在重启Worker进程...`);
restartWorker().catch(e => {
const secretKey = 'secretKey' in msg ? (msg as any).secretKey : undefined;
restartWorker(secretKey).catch(e => {
logger.logError(`[NapCat] [${processType}] 重启Worker进程失败:`, e);
});
}
@@ -292,7 +295,8 @@ async function startWorkerProcess (): Promise<void> {
// 注册重启进程函数到 WebUI
WebUiDataRuntime.setRestartProcessCall(async () => {
try {
const success = processManager!.sendToParent({ type: 'restart' });
const success = processManager!.sendToParent({ type: 'restart', secretKey: AuthHelper.getSecretKey() });
if (success) {
return { result: true, message: '进程重启请求已发送' };
+5 -2
View File
@@ -60,7 +60,7 @@ class ElectronProcessManager implements IProcessManager {
const child: any = this.utilityProcess.fork(modulePath, args, options);
return {
pid: child.pid as number | undefined,
get pid () { return child.pid as number | undefined; },
stdout: child.stdout as Readable | null,
stderr: child.stderr as Readable | null,
@@ -113,7 +113,7 @@ class NodeProcessManager implements IProcessManager {
const child = this.forkFn(modulePath, args, options as any);
return {
pid: child.pid,
get pid () { return child.pid; },
stdout: child.stdout,
stderr: child.stderr,
@@ -164,6 +164,9 @@ export async function createProcessManager (): Promise<{
if (isElectron) {
// @ts-ignore - electron 运行时存在但类型声明可能缺失
const electron = await import('electron');
if (electron.app && !electron.app.isReady()) {
await electron.app.whenReady();
}
return {
manager: new ElectronProcessManager(electron.utilityProcess),
isElectron: true,