Compare commits

...

9 Commits

Author SHA1 Message Date
whyour
c2f823911f 发布版本 v2.19.2 2025-06-28 01:05:07 +08:00
whyour
0587644a6b command-run 增加返回 QL-Task-Log 日志路径 2025-06-28 01:05:05 +08:00
whyour
87b934aafe QLAPI.systemNotify 支持自定义通知类型和参数 2025-06-24 02:00:51 +08:00
whyour
7a92e7c6ab 修复取消安装依赖 2025-06-22 21:47:39 +08:00
whyour
1d8403c0ec 修复环境变量过大解析 2025-06-22 21:10:55 +08:00
whyour
ef9e38f167 备份数据支持选择模块,支持清除依赖缓存 2025-06-22 14:25:19 +08:00
whyour
c9bd053fbd 修改服务启动方式 2025-06-11 00:42:29 +08:00
憶夣
57939391b9
ntfy 增加可选的认证与用户动作 (#2741)
* feat:ntfy增加可选的认证

* feat:ntfy增加可选的用户动作

* fix:ntfy动作包含中文报错
2025-06-07 00:26:27 +08:00
whyour
394e96bbf8 修复 health 接口报错 2025-06-07 00:25:47 +08:00
24 changed files with 2313 additions and 317 deletions

View File

@ -273,6 +273,7 @@ export default (app: Router) => {
{ {
onStart: async (cp, startTime) => { onStart: async (cp, startTime) => {
res.setHeader('QL-Task-Pid', `${cp.pid}`); res.setHeader('QL-Task-Pid', `${cp.pid}`);
res.setHeader('QL-Task-Log', `${logPath}`);
}, },
onEnd: async (cp, endTime, diff) => { onEnd: async (cp, endTime, diff) => {
res.end(); res.end();
@ -316,10 +317,15 @@ export default (app: Router) => {
route.put( route.put(
'/data/export', '/data/export',
celebrate({
body: Joi.object({
type: Joi.array().items(Joi.string()).optional(),
}),
}),
async (req: Request, res: Response, next: NextFunction) => { async (req: Request, res: Response, next: NextFunction) => {
try { try {
const systemService = Container.get(SystemService); const systemService = Container.get(SystemService);
await systemService.exportData(res); await systemService.exportData(res, req.body.type);
} catch (e) { } catch (e) {
return next(e); return next(e);
} }
@ -416,4 +422,22 @@ export default (app: Router) => {
} }
}, },
); );
route.put(
'/config/dependence-clean',
celebrate({
body: Joi.object({
type: Joi.string().allow(''),
}),
}),
async (req: Request, res: Response, next: NextFunction) => {
try {
const systemService = Container.get(SystemService);
const result = await systemService.cleanDependence(req.body.type);
res.send(result);
} catch (e) {
return next(e);
}
},
);
}; };

View File

@ -1,4 +1,5 @@
import 'reflect-metadata'; import 'reflect-metadata';
import cluster, { type Worker } from 'cluster';
import compression from 'compression'; import compression from 'compression';
import cors from 'cors'; import cors from 'cors';
import express from 'express'; import express from 'express';
@ -10,11 +11,19 @@ import { monitoringMiddleware } from './middlewares/monitoring';
import { type GrpcServerService } from './services/grpc'; import { type GrpcServerService } from './services/grpc';
import { type HttpServerService } from './services/http'; import { type HttpServerService } from './services/http';
interface WorkerMetadata {
id: number;
pid: number;
serviceType: string;
startTime: Date;
}
class Application { class Application {
private app: express.Application; private app: express.Application;
private httpServerService?: HttpServerService; private httpServerService?: HttpServerService;
private grpcServerService?: GrpcServerService; private grpcServerService?: GrpcServerService;
private isShuttingDown = false; private isShuttingDown = false;
private workerMetadataMap = new Map<number, WorkerMetadata>();
constructor() { constructor() {
this.app = express(); this.app = express();
@ -22,24 +31,57 @@ class Application {
async start() { async start() {
try { try {
if (cluster.isPrimary) {
await this.initializeDatabase(); await this.initializeDatabase();
await this.initServer(); }
this.setupMiddlewares(); if (cluster.isPrimary) {
await this.initializeServices(); this.startMasterProcess();
this.setupGracefulShutdown(); } else {
await this.startWorkerProcess();
process.send?.('ready'); }
} catch (error) { } catch (error) {
Logger.error('Failed to start application:', error); Logger.error('Failed to start application:', error);
process.exit(1); process.exit(1);
} }
} }
async initServer() { private startMasterProcess() {
const { HttpServerService } = await import('./services/http'); this.forkWorker('http');
const { GrpcServerService } = await import('./services/grpc'); this.forkWorker('grpc');
this.httpServerService = Container.get(HttpServerService);
this.grpcServerService = Container.get(GrpcServerService); cluster.on('exit', (worker, code, signal) => {
const metadata = this.workerMetadataMap.get(worker.id);
if (metadata) {
if (!this.isShuttingDown) {
Logger.error(
`${metadata.serviceType} worker ${worker.process.pid} died (${
signal || code
}). Restarting...`,
);
const newWorker = this.forkWorker(metadata.serviceType);
Logger.info(
`Restarted ${metadata.serviceType} worker (New PID: ${newWorker.process.pid})`,
);
}
this.workerMetadataMap.delete(worker.id);
}
});
this.setupMasterShutdown();
}
private forkWorker(serviceType: string): Worker {
const worker = cluster.fork({ SERVICE_TYPE: serviceType });
this.workerMetadataMap.set(worker.id, {
id: worker.id,
pid: worker.process.pid!,
serviceType,
startTime: new Date(),
});
return worker;
} }
private async initializeDatabase() { private async initializeDatabase() {
@ -53,33 +95,49 @@ class Application {
this.app.use(monitoringMiddleware); this.app.use(monitoringMiddleware);
} }
private async initializeServices() { private setupMasterShutdown() {
await this.grpcServerService?.initialize();
await require('./loaders/app').default({ app: this.app });
const server = await this.httpServerService?.initialize(
this.app,
config.port,
);
await require('./loaders/server').default({ server });
}
private setupGracefulShutdown() {
const shutdown = async () => { const shutdown = async () => {
if (this.isShuttingDown) return; if (this.isShuttingDown) return;
this.isShuttingDown = true; this.isShuttingDown = true;
Logger.info('Shutting down services...'); const workers = Object.values(cluster.workers || {});
const workerPromises: Promise<void>[] = [];
workers.forEach((worker) => {
if (worker) {
const exitPromise = new Promise<void>((resolve) => {
worker.once('exit', () => {
Logger.info(`Worker ${worker.process.pid} exited`);
resolve();
});
try { try {
await Promise.all([ worker.send('shutdown');
this.grpcServerService?.shutdown(), } catch (error) {
this.httpServerService?.shutdown(), Logger.warn(
`Failed to send shutdown to worker ${worker.process.pid}:`,
error,
);
}
});
workerPromises.push(exitPromise);
}
});
try {
await Promise.race([
Promise.all(workerPromises),
new Promise<void>((resolve) => {
setTimeout(() => {
Logger.warn('Worker shutdown timeout reached');
resolve();
}, 10000);
}),
]); ]);
process.exit(0); process.exit(0);
} catch (error) { } catch (error) {
Logger.error('Error during shutdown:', error); Logger.error('Error during worker shutdown:', error);
process.exit(1); process.exit(1);
} }
}; };
@ -87,6 +145,83 @@ class Application {
process.on('SIGTERM', shutdown); process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown); process.on('SIGINT', shutdown);
} }
private async startWorkerProcess() {
const serviceType = process.env.SERVICE_TYPE;
if (!serviceType || !['http', 'grpc'].includes(serviceType)) {
Logger.error('Invalid SERVICE_TYPE:', serviceType);
process.exit(1);
}
Logger.info(`✌️ ${serviceType} worker started (PID: ${process.pid})`);
try {
if (serviceType === 'http') {
await this.startHttpService();
} else {
await this.startGrpcService();
}
process.send?.('ready');
} catch (error) {
Logger.error(`${serviceType} worker failed:`, error);
process.exit(1);
}
}
private async startHttpService() {
this.setupMiddlewares();
const { HttpServerService } = await import('./services/http');
this.httpServerService = Container.get(HttpServerService);
await require('./loaders/app').default({ app: this.app });
const server = await this.httpServerService.initialize(
this.app,
config.port,
);
await require('./loaders/server').default({ server });
this.setupWorkerShutdown('http');
}
private async startGrpcService() {
const { GrpcServerService } = await import('./services/grpc');
this.grpcServerService = Container.get(GrpcServerService);
await this.grpcServerService.initialize();
this.setupWorkerShutdown('grpc');
}
private setupWorkerShutdown(serviceType: string) {
process.on('message', (msg) => {
if (msg === 'shutdown') {
this.gracefulShutdown(serviceType);
}
});
const shutdown = () => this.gracefulShutdown(serviceType);
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
}
private async gracefulShutdown(serviceType: string) {
if (this.isShuttingDown) return;
this.isShuttingDown = true;
try {
if (serviceType === 'http') {
await this.httpServerService?.shutdown();
} else {
await this.grpcServerService?.shutdown();
}
process.exit(0);
} catch (error) {
Logger.error(`[${serviceType}] Error during shutdown:`, error);
process.exit(1);
}
}
} }
const app = new Application(); const app = new Application();

View File

@ -25,3 +25,27 @@ export const SAMPLE_FILES = [
]; ];
export const PYTHON_INSTALL_DIR = process.env.PYTHON_HOME; export const PYTHON_INSTALL_DIR = process.env.PYTHON_HOME;
export const NotificationModeStringMap = {
0: 'gotify',
1: 'goCqHttpBot',
2: 'serverChan',
3: 'pushDeer',
4: 'bark',
5: 'chat',
6: 'telegramBot',
7: 'dingtalkBot',
8: 'weWorkBot',
9: 'weWorkApp',
10: 'aibotk',
11: 'iGot',
12: 'pushPlus',
13: 'wePlusBot',
14: 'email',
15: 'pushMe',
16: 'feishu',
17: 'webhook',
18: 'chronocat',
19: 'ntfy',
20: 'wxPusherBot',
} as const;

View File

@ -41,7 +41,7 @@ const config: Config = {
prefix: '/api', prefix: '/api',
}, },
jwt: { jwt: {
secret: process.env.JWT_SECRET || createRandomString(16, 32), secret: process.env.JWT_SECRET || 'whyour-secret',
expiresIn: process.env.JWT_EXPIRES_IN, expiresIn: process.env.JWT_EXPIRES_IN,
}, },
cors: { cors: {
@ -86,6 +86,7 @@ const dbPath = path.join(dataPath, 'db/');
const uploadPath = path.join(dataPath, 'upload/'); const uploadPath = path.join(dataPath, 'upload/');
const sshdPath = path.join(dataPath, 'ssh.d/'); const sshdPath = path.join(dataPath, 'ssh.d/');
const systemLogPath = path.join(dataPath, 'syslog/'); const systemLogPath = path.join(dataPath, 'syslog/');
const dependenceCachePath = path.join(dataPath, 'dep_cache/');
const envFile = path.join(preloadPath, 'env.sh'); const envFile = path.join(preloadPath, 'env.sh');
const jsEnvFile = path.join(preloadPath, 'env.js'); const jsEnvFile = path.join(preloadPath, 'env.js');
@ -174,4 +175,5 @@ export default {
sqliteFile, sqliteFile,
sshdPath, sshdPath,
systemLogPath, systemLogPath,
dependenceCachePath,
}; };

View File

@ -1,5 +1,3 @@
import { IncomingHttpHeaders } from 'http';
export enum NotificationMode { export enum NotificationMode {
'gotify' = 'gotify', 'gotify' = 'gotify',
'goCqHttpBot' = 'goCqHttpBot', 'goCqHttpBot' = 'goCqHttpBot',
@ -150,6 +148,10 @@ export class NtfyNotification extends NotificationBaseInfo {
public ntfyUrl = ''; public ntfyUrl = '';
public ntfyTopic = ''; public ntfyTopic = '';
public ntfyPriority = ''; public ntfyPriority = '';
public ntfyToken = '';
public ntfyUsername = '';
public ntfyPassword = '';
public ntfyActions = '';
} }
export class WxPusherBotNotification extends NotificationBaseInfo { export class WxPusherBotNotification extends NotificationBaseInfo {

View File

@ -53,14 +53,7 @@ message Response {
optional string message = 2; optional string message = 2;
} }
message SystemNotifyRequest { message ExtraScheduleItem { string schedule = 1; }
string title = 1;
string content = 2;
}
message ExtraScheduleItem {
string schedule = 1;
}
message CronItem { message CronItem {
optional int32 id = 1; optional int32 id = 1;
@ -124,6 +117,128 @@ message CronDetailResponse {
optional string message = 3; optional string message = 3;
} }
enum NotificationMode {
gotify = 0;
goCqHttpBot = 1;
serverChan = 2;
pushDeer = 3;
bark = 4;
chat = 5;
telegramBot = 6;
dingtalkBot = 7;
weWorkBot = 8;
weWorkApp = 9;
aibotk = 10;
iGot = 11;
pushPlus = 12;
wePlusBot = 13;
email = 14;
pushMe = 15;
feishu = 16;
webhook = 17;
chronocat = 18;
ntfy = 19;
wxPusherBot = 20;
}
message NotificationInfo {
NotificationMode type = 1;
optional string gotifyUrl = 2;
optional string gotifyToken = 3;
optional int32 gotifyPriority = 4;
optional string goCqHttpBotUrl = 5;
optional string goCqHttpBotToken = 6;
optional string goCqHttpBotQq = 7;
optional string serverChanKey = 8;
optional string pushDeerKey = 9;
optional string pushDeerUrl = 10;
optional string synologyChatUrl = 11;
optional string barkPush = 12;
optional string barkIcon = 13;
optional string barkSound = 14;
optional string barkGroup = 15;
optional string barkLevel = 16;
optional string barkUrl = 17;
optional string barkArchive = 18;
optional string telegramBotToken = 19;
optional string telegramBotUserId = 20;
optional string telegramBotProxyHost = 21;
optional string telegramBotProxyPort = 22;
optional string telegramBotProxyAuth = 23;
optional string telegramBotApiHost = 24;
optional string dingtalkBotToken = 25;
optional string dingtalkBotSecret = 26;
optional string weWorkBotKey = 27;
optional string weWorkOrigin = 28;
optional string weWorkAppKey = 29;
optional string aibotkKey = 30;
optional string aibotkType = 31;
optional string aibotkName = 32;
optional string iGotPushKey = 33;
optional string pushPlusToken = 34;
optional string pushPlusUser = 35;
optional string pushPlusTemplate = 36;
optional string pushplusChannel = 37;
optional string pushplusWebhook = 38;
optional string pushplusCallbackUrl = 39;
optional string pushplusTo = 40;
optional string wePlusBotToken = 41;
optional string wePlusBotReceiver = 42;
optional string wePlusBotVersion = 43;
optional string emailService = 44;
optional string emailUser = 45;
optional string emailPass = 46;
optional string emailTo = 47;
optional string pushMeKey = 48;
optional string pushMeUrl = 49;
optional string chronocatURL = 50;
optional string chronocatQQ = 51;
optional string chronocatToken = 52;
optional string webhookHeaders = 53;
optional string webhookBody = 54;
optional string webhookUrl = 55;
optional string webhookMethod = 56;
optional string webhookContentType = 57;
optional string larkKey = 58;
optional string ntfyUrl = 59;
optional string ntfyTopic = 60;
optional string ntfyPriority = 61;
optional string ntfyToken = 62;
optional string ntfyUsername = 63;
optional string ntfyPassword = 64;
optional string ntfyActions = 65;
optional string wxPusherBotAppToken = 66;
optional string wxPusherBotTopicIds = 67;
optional string wxPusherBotUids = 68;
}
message SystemNotifyRequest {
string title = 1;
string content = 2;
optional NotificationInfo notificationInfo = 3;
}
service Api { service Api {
rpc GetEnvs(GetEnvsRequest) returns (EnvsResponse) {} rpc GetEnvs(GetEnvsRequest) returns (EnvsResponse) {}
rpc CreateEnv(CreateEnvRequest) returns (EnvsResponse) {} rpc CreateEnv(CreateEnvRequest) returns (EnvsResponse) {}

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@ import {
DeleteCronsRequest, DeleteCronsRequest,
CronResponse, CronResponse,
} from '../protos/api'; } from '../protos/api';
import { NotificationInfo } from '../data/notify';
Container.set('logger', LoggerInstance); Container.set('logger', LoggerInstance);
@ -227,7 +228,11 @@ export const systemNotify = async (
) => { ) => {
try { try {
const systemService = Container.get(SystemService); const systemService = Container.get(SystemService);
const data = await systemService.notify(call.request); const data = await systemService.notify({
title: call.request.title,
content: call.request.content,
notificationInfo: call.request.notificationInfo as unknown as NotificationInfo,
});
callback(null, data); callback(null, data);
} catch (e: any) { } catch (e: any) {
callback(e); callback(e);

View File

@ -163,11 +163,9 @@ export default class DependenceService {
taskLimit.removeQueuedDependency(doc); taskLimit.removeQueuedDependency(doc);
const depInstallCommand = getInstallCommand(doc.type, doc.name); const depInstallCommand = getInstallCommand(doc.type, doc.name);
const depUnInstallCommand = getUninstallCommand(doc.type, doc.name); const depUnInstallCommand = getUninstallCommand(doc.type, doc.name);
const installCmd = `${depInstallCommand} ${doc.name.trim()}`;
const unInstallCmd = `${depUnInstallCommand} ${doc.name.trim()}`;
const pids = await Promise.all([ const pids = await Promise.all([
getPid(installCmd), getPid(depInstallCommand),
getPid(unInstallCmd), getPid(depUnInstallCommand),
]); ]);
for (const pid of pids) { for (const pid of pids) {
pid && (await killTask(pid)); pid && (await killTask(pid));

View File

@ -49,12 +49,21 @@ export default class NotificationService {
public async notify( public async notify(
title: string, title: string,
content: string, content: string,
notificationInfo?: NotificationInfo,
): Promise<boolean | undefined> { ): Promise<boolean | undefined> {
const { type, ...rest } = await this.userService.getNotificationMode(); let { type, ...rest } = await this.userService.getNotificationMode();
if (notificationInfo?.type) {
type = notificationInfo?.type;
}
if (type) { if (type) {
this.title = title; this.title = title;
this.content = content; this.content = content;
this.params = rest; let params = rest;
if (notificationInfo) {
const { type: _, ...others } = notificationInfo;
params = { ...rest, ...others };
}
this.params = params;
const notificationModeAction = this.modeMap.get(type); const notificationModeAction = this.modeMap.get(type);
try { try {
return await notificationModeAction?.call(this); return await notificationModeAction?.call(this);
@ -623,20 +632,42 @@ export default class NotificationService {
} }
private async ntfy() { private async ntfy() {
const { ntfyUrl, ntfyTopic, ntfyPriority } = this.params; const {
ntfyUrl,
ntfyTopic,
ntfyPriority,
ntfyToken,
ntfyUsername,
ntfyPassword,
ntfyActions,
} = this.params;
// 编码函数 // 编码函数
const encodeRfc2047 = (text: string, charset: string = 'UTF-8'): string => { const encodeRfc2047 = (text: string, charset: string = 'UTF-8'): string => {
const encodedText = Buffer.from(text).toString('base64'); const encodedText = Buffer.from(text).toString('base64');
return `=?${charset}?B?${encodedText}?=`; return `=?${charset}?B?${encodedText}?=`;
}; };
try { try {
const encodedTitle = encodeRfc2047(this.title); const headers: Record<string, string> = {
Title: encodeRfc2047(this.title),
Priority: `${ntfyPriority || '3'}`,
Icon: 'https://qn.whyour.cn/logo.png',
};
if (ntfyToken) {
headers['Authorization'] = `Bearer ${ntfyToken}`;
} else if (ntfyUsername && ntfyPassword) {
headers['Authorization'] = `Basic ${Buffer.from(
`${ntfyUsername}:${ntfyPassword}`,
).toString('base64')}`;
}
if (ntfyActions) {
headers['Actions'] = encodeRfc2047(ntfyActions);
}
const res = await httpClient.request( const res = await httpClient.request(
`${ntfyUrl || 'https://ntfy.sh'}/${ntfyTopic}`, `${ntfyUrl || 'https://ntfy.sh'}/${ntfyTopic}`,
{ {
...this.gotOption, ...this.gotOption,
body: `${this.content}`, body: `${this.content}`,
headers: { Title: encodedTitle, Priority: `${ntfyPriority || '3'}` }, headers: headers,
method: 'POST', method: 'POST',
}, },
); );

View File

@ -7,7 +7,7 @@ import path from 'path';
import { Inject, Service } from 'typedi'; import { Inject, Service } from 'typedi';
import winston from 'winston'; import winston from 'winston';
import config from '../config'; import config from '../config';
import { TASK_COMMAND } from '../config/const'; import { NotificationModeStringMap, TASK_COMMAND } from '../config/const';
import { import {
getPid, getPid,
killTask, killTask,
@ -373,8 +373,27 @@ export default class SystemService {
return { code: 200 }; return { code: 200 };
} }
public async notify({ title, content }: { title: string; content: string }) { public async notify({
const isSuccess = await this.notificationService.notify(title, content); title,
content,
notificationInfo,
}: {
title: string;
content: string;
notificationInfo?: NotificationInfo;
}) {
const typeString =
typeof notificationInfo?.type === 'number'
? NotificationModeStringMap[notificationInfo.type]
: undefined;
if (notificationInfo && typeString) {
notificationInfo.type = typeString;
}
const isSuccess = await this.notificationService.notify(
title,
content,
notificationInfo,
);
if (isSuccess) { if (isSuccess) {
return { code: 200, message: '通知发送成功' }; return { code: 200, message: '通知发送成功' };
} else { } else {
@ -415,10 +434,17 @@ export default class SystemService {
} }
} }
public async exportData(res: Response) { public async exportData(res: Response, type?: string[]) {
try { try {
let dataDirs = ['db', 'upload'];
if (type && type.length) {
dataDirs = dataDirs.concat(type.filter((x) => x !== 'base'));
}
const dataPaths = dataDirs.map((dir) => `data/${dir}`);
await promiseExec( await promiseExec(
`cd ${config.dataPath} && cd ../ && tar -zcvf ${config.dataTgzFile} data/`, `cd ${config.dataPath} && cd ../ && tar -zcvf ${
config.dataTgzFile
} ${dataPaths.join(' ')}`,
); );
res.download(config.dataTgzFile); res.download(config.dataTgzFile);
} catch (error: any) { } catch (error: any) {
@ -503,4 +529,15 @@ export default class SystemService {
return { code: 400, message: '设置时区失败' }; return { code: 400, message: '设置时区失败' };
} }
} }
public async cleanDependence(type: 'node' | 'python3') {
if (!type || !['node', 'python3'].includes(type)) {
return { code: 400, message: '参数错误' };
}
try {
const finalPath = path.join(config.dependenceCachePath, type);
await fs.promises.rm(finalPath, { recursive: true });
} catch (error) {}
return { code: 200 };
}
} }

View File

@ -226,9 +226,17 @@ export QMSG_TYPE=""
## ntfy_url 填写ntfy地址,如https://ntfy.sh ## ntfy_url 填写ntfy地址,如https://ntfy.sh
## ntfy_topic 填写ntfy的消息应用topic ## ntfy_topic 填写ntfy的消息应用topic
## ntfy_priority 填写推送消息优先级,默认为3 ## ntfy_priority 填写推送消息优先级,默认为3
## ntfy_token 填写推送token,可选
## ntfy_username 填写推送用户名称,可选
## ntfy_password 填写推送用户密码,可选
## ntfy_actions 填写推送用户动作,可选
export NTFY_URL="" export NTFY_URL=""
export NTFY_TOPIC="" export NTFY_TOPIC=""
export NTFY_PRIORITY="3" export NTFY_PRIORITY="3"
export NTFY_TOKEN=""
export NTFY_USERNAME=""
export NTFY_PASSWORD=""
export NTFY_ACTIONS=""
## 21. wxPusher ## 21. wxPusher
## 官方文档: https://wxpusher.zjiecode.com/docs/ ## 官方文档: https://wxpusher.zjiecode.com/docs/

View File

@ -140,6 +140,10 @@ const push_config = {
NTFY_URL: '', // ntfy地址,如https://ntfy.sh,默认为https://ntfy.sh NTFY_URL: '', // ntfy地址,如https://ntfy.sh,默认为https://ntfy.sh
NTFY_TOPIC: '', // ntfy的消息应用topic NTFY_TOPIC: '', // ntfy的消息应用topic
NTFY_PRIORITY: '3', // 推送消息优先级,默认为3 NTFY_PRIORITY: '3', // 推送消息优先级,默认为3
NTFY_TOKEN: '', // 推送token,可选
NTFY_USERNAME: '', // 推送用户名称,可选
NTFY_PASSWORD: '', // 推送用户密码,可选
NTFY_ACTIONS: '', // 推送用户动作,可选
// 官方文档: https://wxpusher.zjiecode.com/docs/ // 官方文档: https://wxpusher.zjiecode.com/docs/
// 管理后台: https://wxpusher.zjiecode.com/admin/ // 管理后台: https://wxpusher.zjiecode.com/admin/
@ -1258,7 +1262,7 @@ function ntfyNotify(text, desp) {
} }
return new Promise((resolve) => { return new Promise((resolve) => {
const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY } = push_config; const { NTFY_URL, NTFY_TOPIC, NTFY_PRIORITY, NTFY_TOKEN, NTFY_USERNAME, NTFY_PASSWORD, NTFY_ACTIONS } = push_config;
if (NTFY_TOPIC) { if (NTFY_TOPIC) {
const options = { const options = {
url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`, url: `${NTFY_URL || 'https://ntfy.sh'}/${NTFY_TOPIC}`,
@ -1266,9 +1270,19 @@ function ntfyNotify(text, desp) {
headers: { headers: {
Title: `${encodeRFC2047(text)}`, Title: `${encodeRFC2047(text)}`,
Priority: NTFY_PRIORITY || '3', Priority: NTFY_PRIORITY || '3',
Icon: 'https://qn.whyour.cn/logo.png',
}, },
timeout, timeout,
}; };
if (NTFY_TOKEN) {
options.headers['Authorization'] = `Bearer ${NTFY_TOKEN}`;
} else if (NTFY_USERNAME && NTFY_PASSWORD) {
options.headers['Authorization'] = `Basic ${Buffer.from(`${NTFY_USERNAME}:${NTFY_PASSWORD}`).toString('base64')}`;
}
if (NTFY_ACTIONS) {
options.headers['Actions'] = encodeRFC2047(NTFY_ACTIONS);
}
$.post(options, (err, resp, data) => { $.post(options, (err, resp, data) => {
try { try {
if (err) { if (err) {

View File

@ -126,6 +126,10 @@ push_config = {
'NTFY_URL': '', # ntfy地址,如https://ntfy.sh 'NTFY_URL': '', # ntfy地址,如https://ntfy.sh
'NTFY_TOPIC': '', # ntfy的消息应用topic 'NTFY_TOPIC': '', # ntfy的消息应用topic
'NTFY_PRIORITY':'3', # 推送消息优先级,默认为3 'NTFY_PRIORITY':'3', # 推送消息优先级,默认为3
'NTFY_TOKEN': '', # 推送token,可选
'NTFY_USERNAME': '', # 推送用户名称,可选
'NTFY_PASSWORD': '', # 推送用户密码,可选
'NTFY_ACTIONS': '', # 推送用户动作,可选
'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/ 'WXPUSHER_APP_TOKEN': '', # wxpusher 的 appToken 官方文档: https://wxpusher.zjiecode.com/docs/ 管理后台: https://wxpusher.zjiecode.com/admin/
'WXPUSHER_TOPIC_IDS': '', # wxpusher 的 主题ID多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行 'WXPUSHER_TOPIC_IDS': '', # wxpusher 的 主题ID多个用英文分号;分隔 topic_ids 与 uids 至少配置一个才行
@ -806,7 +810,14 @@ def ntfy(title: str, content: str) -> None:
encoded_title = encode_rfc2047(title) encoded_title = encode_rfc2047(title)
data = content.encode(encoding="utf-8") data = content.encode(encoding="utf-8")
headers = {"Title": encoded_title, "Priority": priority} # 使用编码后的 title headers = {"Title": encoded_title, "Priority": priority, "Icon": "https://qn.whyour.cn/logo.png"} # 使用编码后的 title
if push_config.get("NTFY_TOKEN"):
headers['Authorization'] = "Bearer " + push_config.get("NTFY_TOKEN")
elif push_config.get("NTFY_USERNAME") and push_config.get("NTFY_PASSWORD"):
authStr = push_config.get("NTFY_USERNAME") + ":" + push_config.get("NTFY_PASSWORD")
headers['Authorization'] = "Basic " + base64.b64encode(authStr.encode('utf-8')).decode('utf-8')
if push_config.get("NTFY_ACTIONS"):
headers['Actions'] = encode_rfc2047(push_config.get("NTFY_ACTIONS"))
url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC") url = push_config.get("NTFY_URL") + "/" + push_config.get("NTFY_TOPIC")
response = requests.post(url, data=data, headers=headers) response = requests.post(url, data=data, headers=headers)

View File

@ -87,12 +87,10 @@ function run() {
console.log('执行前置命令结束\n'); console.log('执行前置命令结束\n');
} }
} catch (error) { } catch (error) {
if (!error.message.includes('spawnSync /bin/sh E2BIG')) { if (!error.message.includes('spawnSync /bin/bash E2BIG')) {
console.log(`\ue926 run task before error: `, error); console.log(`\ue926 run task before error: `, error);
} else { } else {
console.log( // environment variable is too large
`\ue926 The environment variable is too large. It is recommended to use task_before.js instead of task_before.sh\n`,
);
} }
if (task_before) { if (task_before) {
console.log('执行前置命令结束\n'); console.log('执行前置命令结束\n');

View File

@ -98,10 +98,8 @@ def run():
error_message = str(error) error_message = str(error)
if "Argument list too long" not in error_message: if "Argument list too long" not in error_message:
print(f"\ue926 run task before error: {error}") print(f"\ue926 run task before error: {error}")
else: # else:
print( # environment variable is too large
"\ue926 The environment variable is too large. It is recommended to use task_before.py instead of task_before.sh\n"
)
if task_before: if task_before:
print("执行前置命令结束\n") print("执行前置命令结束\n")
except Exception as error: except Exception as error:

View File

@ -2,13 +2,9 @@
echo -e "开始发布" echo -e "开始发布"
echo -e "切换master分支" echo -e "切换master分支"
git checkout master git branch -D master
git checkout -b master
echo -e "合并develop代码" git push --set-upstream origin master -f
git merge origin/develop
echo -e "提交master代码"
git push
echo -e "更新cdn文件" echo -e "更新cdn文件"
ts-node-transpile-only sample/tool.ts ts-node-transpile-only sample/tool.ts

View File

@ -113,6 +113,8 @@ export default function () {
const responseStatus = error.response.status; const responseStatus = error.response.status;
if (responseStatus !== 401) { if (responseStatus !== 401) {
history.push('/error'); history.push('/error');
} else {
window.location.reload();
} }
}) })
.finally(() => setInitLoading(false)); .finally(() => setInitLoading(false));

View File

@ -395,7 +395,11 @@
"PushMe的Keyhttps://push.i-i.me/": "PushMe key, https://push.i-i.me/", "PushMe的Keyhttps://push.i-i.me/": "PushMe key, https://push.i-i.me/",
"自建的PushMeServer消息接口地址例如http://127.0.0.1:3010不填则使用官方消息接口": "The self built PushMeServer message interface address, for example: http://127.0.0.1:3010 If left blank, use the official message interface", "自建的PushMeServer消息接口地址例如http://127.0.0.1:3010不填则使用官方消息接口": "The self built PushMeServer message interface address, for example: http://127.0.0.1:3010 If left blank, use the official message interface",
"ntfy的url地址例如 https://ntfy.sh": "The URL address of ntfy, for example, https://ntfy.sh.", "ntfy的url地址例如 https://ntfy.sh": "The URL address of ntfy, for example, https://ntfy.sh.",
"ntfy的消息应用topic": "The topic for ntfy's messaging application.", "ntfy应用topic": "The topic for ntfy's application.",
"ntfy应用token": "The token for ntfy's application, see https://docs.ntfy.sh/config/#access-tokens",
"ntfy应用用户名": "The username for ntfy's application, see https://docs.ntfy.sh/config/#users-and-roles",
"ntfy应用密码": "The password for ntfy's application, see https://docs.ntfy.sh/config/#users-and-roles",
"ntfy用户动作": "The user actions for ntfy's application, up to three actions, see https://docs.ntfy.sh/publish/?h=actions#action-buttons",
"wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/", "wxPusherBot的appToken": "wxPusherBot's appToken, obtain according to docs https://wxpusher.zjiecode.com/docs/",
"wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured", "wxPusherBot的topicIds": "wxPusherBot's topicIds, at least one of topicIds or uids must be configured",
"wxPusherBot的uids": "wxPusherBot's uids, at least one of topicIds or uids must be configured", "wxPusherBot的uids": "wxPusherBot's uids, at least one of topicIds or uids must be configured",
@ -506,5 +510,16 @@
"强制打开可能会导致编辑器显示异常": "Force opening may cause display issues in the editor", "强制打开可能会导致编辑器显示异常": "Force opening may cause display issues in the editor",
"确认离开": "Confirm Leave", "确认离开": "Confirm Leave",
"当前文件未保存,确认离开吗": "Current file is not saved, are you sure to leave?", "当前文件未保存,确认离开吗": "Current file is not saved, are you sure to leave?",
"收件邮箱地址,多个分号分隔,默认发送给发件邮箱地址": "Receiving email address, multiple semicolon separated, sent to the sending email address by default" "收件邮箱地址,多个分号分隔,默认发送给发件邮箱地址": "Receiving email address, multiple semicolon separated, sent to the sending email address by default",
"选择备份模块": "Select backup module",
"开始备份": "Start backup",
"基础数据": "Basic data",
"脚本文件": "Script files",
"日志文件": "Log files",
"依赖缓存": "Dependency cache",
"远程脚本缓存": "Remote script cache",
"远程仓库缓存": "Remote repository cache",
"SSH 文件缓存": "SSH file cache",
"清除依赖缓存": "Clean dependency cache",
"清除成功": "Clean successful"
} }

View File

@ -395,7 +395,11 @@
"PushMe的Keyhttps://push.i-i.me/": "PushMe的Keyhttps://push.i-i.me/", "PushMe的Keyhttps://push.i-i.me/": "PushMe的Keyhttps://push.i-i.me/",
"自建的PushMeServer消息接口地址例如http://127.0.0.1:3010不填则使用官方消息接口": "自建的PushMeServer消息接口地址例如http://127.0.0.1:3010不填则使用官方消息接口", "自建的PushMeServer消息接口地址例如http://127.0.0.1:3010不填则使用官方消息接口": "自建的PushMeServer消息接口地址例如http://127.0.0.1:3010不填则使用官方消息接口",
"ntfy的url地址例如 https://ntfy.sh": "ntfy的url地址例如 https://ntfy.sh", "ntfy的url地址例如 https://ntfy.sh": "ntfy的url地址例如 https://ntfy.sh",
"ntfy的消息应用topic": "ntfy的消息应用topic", "ntfy应用topic": "ntfy应用topic",
"ntfy应用token": "ntfy应用token参考 https://docs.ntfy.sh/config/#access-tokens",
"ntfy应用用户名": "ntfy应用用户名参考 https://docs.ntfy.sh/config/#users-and-roles",
"ntfy应用密码": "ntfy应用密码参考 https://docs.ntfy.sh/config/#users-and-roles",
"ntfy用户动作": "ntfy用户动作最多三个动作参考 https://docs.ntfy.sh/publish/?h=actions#action-buttons",
"wxPusherBot的appToken": "wxPusherBot的appToken, 按照文档获取 https://wxpusher.zjiecode.com/docs/", "wxPusherBot的appToken": "wxPusherBot的appToken, 按照文档获取 https://wxpusher.zjiecode.com/docs/",
"wxPusherBot的topicIds": "wxPusherBot的topicIds, topicIds 和 uids 至少配置一个才行", "wxPusherBot的topicIds": "wxPusherBot的topicIds, topicIds 和 uids 至少配置一个才行",
"wxPusherBot的uids": "wxPusherBot的uids, topicIds 和 uids 至少配置一个才行", "wxPusherBot的uids": "wxPusherBot的uids, topicIds 和 uids 至少配置一个才行",
@ -506,6 +510,16 @@
"强制打开可能会导致编辑器显示异常": "强制打开可能会导致编辑器显示异常", "强制打开可能会导致编辑器显示异常": "强制打开可能会导致编辑器显示异常",
"确认离开": "确认离开", "确认离开": "确认离开",
"当前文件未保存,确认离开吗": "当前文件未保存,确认离开吗", "当前文件未保存,确认离开吗": "当前文件未保存,确认离开吗",
"收件邮箱地址,多个分号分隔,默认发送给发件邮箱地址": "收件邮箱地址,多个分号分隔,默认发送给发件邮箱地址" "收件邮箱地址,多个分号分隔,默认发送给发件邮箱地址": "收件邮箱地址,多个分号分隔,默认发送给发件邮箱地址",
"选择备份模块": "选择备份模块",
"开始备份": "开始备份",
"基础数据": "基础数据",
"脚本文件": "脚本文件",
"日志文件": "日志文件",
"依赖缓存": "依赖缓存",
"远程脚本缓存": "远程脚本缓存",
"远程仓库缓存": "远程仓库缓存",
"SSH 文件缓存": "SSH 文件缓存",
"清除依赖缓存": "清除依赖缓存",
"清除成功": "清除成功"
} }

View File

@ -1,6 +1,6 @@
import intl from 'react-intl-universal'; import intl from 'react-intl-universal';
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { Button, InputNumber, Form, message, Input, Alert } from 'antd'; import { Button, InputNumber, Form, message, Input, Alert, Select } from 'antd';
import config from '@/utils/config'; import config from '@/utils/config';
import { request } from '@/utils/http'; import { request } from '@/utils/http';
import './index.less'; import './index.less';
@ -25,6 +25,7 @@ const Dependence = () => {
const [form] = Form.useForm(); const [form] = Form.useForm();
const [log, setLog] = useState<string>(''); const [log, setLog] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const [cleanType, setCleanType] = useState<string>('node');
const getSystemConfig = () => { const getSystemConfig = () => {
request request
@ -84,6 +85,24 @@ const Dependence = () => {
} }
}; };
const cleanDependenceCache = (type: string) => {
setLoading(true);
setLog('');
request
.put(`${config.apiPrefix}system/config/dependence-clean`, {
type,
})
.then(({ code, data }) => {
if (code === 200) {
message.success(intl.get('清除成功'));
}
})
.catch((error: any) => {
console.log(error);
})
.finally(() => setLoading(false));
};
useEffect(() => { useEffect(() => {
const ws = WebSocketManager.getInstance(); const ws = WebSocketManager.getInstance();
ws.subscribe('updateNodeMirror', handleMessage); ws.subscribe('updateNodeMirror', handleMessage);
@ -222,6 +241,38 @@ const Dependence = () => {
</Button> </Button>
</Input.Group> </Input.Group>
</Form.Item> </Form.Item>
<Form.Item
label={intl.get('清除依赖缓存')}
name="clean"
tooltip={{
title: intl.get('清除依赖缓存'),
placement: 'topLeft',
}}
>
<Input.Group compact>
<Select
defaultValue={'node'}
style={{ width: 100 }}
onChange={(value) => {
setCleanType(value);
}}
options={[
{ label: 'node', value: 'node' },
{ label: 'python3', value: 'python3' },
]}
/>
<Button
type="primary"
loading={loading}
onClick={() => {
cleanDependenceCache(cleanType);
}}
style={{ width: 100 }}
>
{intl.get('确认')}
</Button>
</Input.Group>
</Form.Item>
</Form> </Form>
<pre <pre
style={{ style={{

View File

@ -10,6 +10,7 @@ import {
Upload, Upload,
Modal, Modal,
Select, Select,
Checkbox,
} from 'antd'; } from 'antd';
import * as DarkReader from '@umijs/ssr-darkreader'; import * as DarkReader from '@umijs/ssr-darkreader';
import config from '@/utils/config'; import config from '@/utils/config';
@ -31,6 +32,19 @@ const dataMap = {
timezone: 'timezone', timezone: 'timezone',
}; };
const exportModules = [
{ value: 'base', label: intl.get('基础数据'), disabled: true },
{ value: 'config', label: intl.get('配置文件') },
{ value: 'scripts', label: intl.get('脚本文件') },
{ value: 'log', label: intl.get('日志文件') },
{ value: 'deps', label: intl.get('依赖文件') },
{ value: 'syslog', label: intl.get('系统日志') },
{ value: 'dep_cache', label: intl.get('依赖缓存') },
{ value: 'raw', label: intl.get('远程脚本缓存') },
{ value: 'repo', label: intl.get('远程仓库缓存') },
{ value: 'ssh.d', label: intl.get('SSH 文件缓存') },
];
const Other = ({ const Other = ({
systemInfo, systemInfo,
reloadTheme, reloadTheme,
@ -45,6 +59,8 @@ const Other = ({
const [exportLoading, setExportLoading] = useState(false); const [exportLoading, setExportLoading] = useState(false);
const showUploadProgress = useProgress(intl.get('上传')); const showUploadProgress = useProgress(intl.get('上传'));
const showDownloadProgress = useProgress(intl.get('下载')); const showDownloadProgress = useProgress(intl.get('下载'));
const [visible, setVisible] = useState(false);
const [selectedModules, setSelectedModules] = useState<string[]>(['base']);
const { const {
enable: enableDarkMode, enable: enableDarkMode,
@ -110,7 +126,7 @@ const Other = ({
request request
.put<Blob>( .put<Blob>(
`${config.apiPrefix}system/data/export`, `${config.apiPrefix}system/data/export`,
{}, { type: selectedModules },
{ {
responseType: 'blob', responseType: 'blob',
timeout: 86400000, timeout: 86400000,
@ -127,7 +143,10 @@ const Other = ({
.catch((error: any) => { .catch((error: any) => {
console.log(error); console.log(error);
}) })
.finally(() => setExportLoading(false)); .finally(() => {
setExportLoading(false);
setVisible(false);
});
}; };
const showReloadModal = () => { const showReloadModal = () => {
@ -178,6 +197,7 @@ const Other = ({
}, []); }, []);
return ( return (
<>
<Form layout="vertical" form={form}> <Form layout="vertical" form={form}>
<Form.Item <Form.Item
label={intl.get('主题')} label={intl.get('主题')}
@ -196,7 +216,10 @@ const Other = ({
> >
{intl.get('亮色')} {intl.get('亮色')}
</Radio.Button> </Radio.Button>
<Radio.Button value="dark" style={{ width: 66, textAlign: 'center' }}> <Radio.Button
value="dark"
style={{ width: 66, textAlign: 'center' }}
>
{intl.get('暗色')} {intl.get('暗色')}
</Radio.Button> </Radio.Button>
<Radio.Button <Radio.Button
@ -296,7 +319,14 @@ const Other = ({
/> />
</Form.Item> </Form.Item>
<Form.Item label={intl.get('数据备份还原')} name="frequency"> <Form.Item label={intl.get('数据备份还原')} name="frequency">
<Button type="primary" onClick={exportData} loading={exportLoading}> <Button
type="primary"
onClick={() => {
setSelectedModules(['base']);
setVisible(true);
}}
loading={exportLoading}
>
{exportLoading ? intl.get('生成数据中...') : intl.get('备份')} {exportLoading ? intl.get('生成数据中...') : intl.get('备份')}
</Button> </Button>
<Upload <Upload
@ -332,6 +362,40 @@ const Other = ({
<CheckUpdate systemInfo={systemInfo} /> <CheckUpdate systemInfo={systemInfo} />
</Form.Item> </Form.Item>
</Form> </Form>
<Modal
title={intl.get('选择备份模块')}
open={visible}
onOk={exportData}
onCancel={() => setVisible(false)}
okText={intl.get('开始备份')}
cancelText={intl.get('取消')}
okButtonProps={{ loading: exportLoading }} // 绑定加载状态到按钮
>
<Checkbox.Group
value={selectedModules}
onChange={(v) => {
setSelectedModules(v as string[]);
}}
style={{
width: '100%',
display: 'flex',
flexWrap: 'wrap',
gap: '8px 16px',
}}
>
{exportModules.map((module) => (
<Checkbox
key={module.value}
value={module.value}
disabled={module.disabled}
style={{ marginLeft: 0 }}
>
{module.label}
</Checkbox>
))}
</Checkbox.Group>
</Modal>
</>
); );
}; };

View File

@ -128,10 +128,14 @@ export default {
}, },
{ {
label: 'ntfyTopic', label: 'ntfyTopic',
tip: intl.get('ntfy的消息应用topic'), tip: intl.get('ntfy应用topic'),
required: true, required: true,
}, },
{ label: 'ntfyPriority', tip: intl.get('推送消息的优先级') }, { label: 'ntfyPriority', tip: intl.get('推送消息的优先级') },
{ label: 'ntfyToken', tip: intl.get('ntfy应用token') },
{ label: 'ntfyUsername', tip: intl.get('ntfy应用用户名') },
{ label: 'ntfyPassword', tip: intl.get('ntfy应用密码') },
{ label: 'ntfyActions', tip: intl.get('ntfy用户动作') },
], ],
chat: [ chat: [
{ {

View File

@ -1,12 +1,10 @@
version: 2.19.1 version: 2.19.2
changeLogLink: https://t.me/jiao_long/430 changeLogLink: https://t.me/jiao_long/431
publishTime: 2025-05-24 16:00 publishTime: 2025-06-27 23:59
changeLog: | changeLog: |
1. 修复依赖是否安装检查逻辑 1. 备份数据支持选择模块,支持清除依赖缓存
2. 修复文件下载 path 参数 2. QLAPI 和 openapi 的 systemNotify 支持自定义通知类型和参数
3. 修复 python 查询逻辑 3. ntfy 增加可选的认证与用户动作,感谢 https://github.com/liheji
4. 修复任务视图状态筛选 4. 修复取消安装依赖
5. 修复创建脚本可能失败 5. 修复环境变量过大解析报错
6. 修复重置用户名失败 6. 修改服务启动方式
7. 修复无法识别 python 依赖安装的命令
8. 其他缺陷修复