v0.3.34: 每日汇报增加推送通道选择UI

This commit is contained in:
2026-05-17 21:52:37 +08:00
parent 17b40cea7b
commit cf2796666d
54 changed files with 191 additions and 135 deletions

View File

@@ -24,7 +24,7 @@ export function getGlobalNotifyConfig(): Record<string, any> {
try { return JSON.parse(raw); } catch { return {}; }
}
function getGlobalNotifyConfigs(): NotifyChannel[] {
export function getGlobalNotifyConfigs(): NotifyChannel[] {
const raw = getSystemConfig('global_notify_config') || '{}';
let globalConfig: any = {};
try { globalConfig = JSON.parse(raw); } catch {}
@@ -56,7 +56,7 @@ function checkEventEnabled(eventName: string): boolean {
// ======================== Core send ========================
async function sendToChannels(channels: NotifyChannel[], title: string, content: string, level: NotifyLevel): Promise<void> {
export async function sendToChannels(channels: NotifyChannel[], title: string, content: string, level: NotifyLevel): Promise<void> {
for (const ch of channels) {
try {
await notifyWith(ch.name, {

View File

@@ -3,8 +3,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'key', label: 'Bark Key', type: 'text', required: true, placeholder: 'xxxxxxxxxxxxxxxxx' },
{ key: 'server', label: '服务器', type: 'url', default: 'https://api.day.app', required: false, placeholder: 'https://api.day.app' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch 通知', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const barkNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'webhook_url', label: 'Webhook URL', type: 'url', required: true, placeholder: 'https://oapi.dingtalk.com/robot/send?access_token=xxx' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const dingtalkNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'webhook_url', label: 'Webhook URL', type: 'url', required: true, placeholder: 'https://discord.com/api/webhooks/...' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const discordNotifier: Notifier = {

View File

@@ -3,8 +3,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'server', label: '服务器地址', type: 'url', required: true, placeholder: 'https://gotify.example.com' },
{ key: 'token', label: 'App Token', type: 'password', required: true, placeholder: 'Gotify App Token' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const gotifyNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'webhook_url', label: 'Webhook URL', type: 'url', required: true, placeholder: 'https://open.feishu.cn/open-apis/bot/v2/hook/xxx' },
{ key: 'title', label: '\u6807\u9898', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '\u5185\u5bb9', type: 'text', required: true }
];
export const larkNotifier: Notifier = {

View File

@@ -3,8 +3,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'topic', label: 'Topic', type: 'text', required: true, placeholder: 'my-notification-topic' },
{ key: 'server', label: '服务器', type: 'url', default: 'https://ntfy.sh', required: false, placeholder: 'https://ntfy.sh' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const ntfyNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'token', label: 'Token', type: 'password', required: true, placeholder: 'pushplus token' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const pushplusNotifier: Notifier = {

View File

@@ -3,8 +3,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'key', label: 'API Key', type: 'password', required: true, placeholder: 'Qmsg API Key' },
{ key: 'qq', label: 'QQ 号', type: 'text', required: false, placeholder: '留空则推送到所有绑定QQ' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const qmsgNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'sendkey', label: 'SendKey', type: 'password', required: true, placeholder: 'Server酱 SendKey' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const serverchanNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'sendkey', label: 'SendKey', type: 'password', required: true, placeholder: 'Server酱 Turbo SendKey' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const serverchanturboNotifier: Notifier = {

View File

@@ -8,8 +8,7 @@ const params: NotifierParam[] = [
{ key: 'pass', label: '密码/授权码', type: 'password', required: true, placeholder: 'SMTP 授权码' },
{ key: 'from', label: '发件人', type: 'text', required: true, placeholder: 'sender@example.com' },
{ key: 'to', label: '收件人', type: 'text', required: true, placeholder: 'receiver@example.com' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const smtpNotifier: Notifier = {

View File

@@ -3,8 +3,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'token', label: 'Bot Token', type: 'password', required: true, placeholder: '123456:ABC-def' },
{ key: 'chat_id', label: 'Chat ID', type: 'text', required: true, placeholder: '@频道 或 -1001234567890' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const telegramNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'url', label: 'Webhook URL', type: 'url', required: true, placeholder: 'https://example.com/webhook' },
{ key: 'title', label: '\u6807\u9898', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '\u5185\u5bb9', type: 'text', required: true }
];
export const webhookNotifier: Notifier = {

View File

@@ -2,8 +2,7 @@ import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.
const params: NotifierParam[] = [
{ key: 'webhook_url', label: 'Webhook URL', type: 'url', required: true, placeholder: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx' },
{ key: 'title', label: '标题', type: 'text', default: 'CloudSearch', required: false },
{ key: 'content', label: '内容', type: 'text', required: true }
];
export const wechatWorkBotNotifier: Notifier = {

View File

@@ -5,7 +5,7 @@
import { getDb } from '../database/database';
import { getSystemConfig } from '../admin/system-config.service';
import { getCloudConfigs } from '../cloud/credential.service';
import { notify } from '../cloud/notification.service';
import { notify, getGlobalNotifyConfigs, sendToChannels } from '../cloud/notification.service';
import { CLOUD_LABELS } from '../config/cloud-constants';
// ═══════════════════════════════════════════════
@@ -19,6 +19,7 @@ export interface DailyReportConfig {
includeSaves: boolean;
includeStorage: boolean;
includeUsers: boolean;
channels?: string[]; // 指定推送通道,空=全部全局通道
}
export interface DailyReport {
@@ -53,6 +54,7 @@ export function getDailyReportConfig(): DailyReportConfig {
includeSaves: parsed.includeSaves !== false,
includeStorage: parsed.includeStorage !== false,
includeUsers: parsed.includeUsers !== false,
channels: parsed.channels || [],
};
}
@@ -286,7 +288,16 @@ export async function runDailyReportIfScheduled(): Promise<void> {
cfg.includeUsers
);
notify('CloudSearch 每日汇报', content, 'info');
// 通道过滤:如果配置了 channels 则只发指定通道
if (cfg.channels && cfg.channels.length > 0) {
const allChannels = getGlobalNotifyConfigs();
const filtered = allChannels.filter(c => cfg.channels!.includes(c.name));
if (filtered.length > 0) {
sendToChannels(filtered, 'CloudSearch 每日汇报', content, 'info').catch(() => {});
}
} else {
notify('CloudSearch 每日汇报', content, 'info');
}
// Record last run
const { getDb } = require('../database/database');
@@ -332,6 +343,15 @@ export async function sendTestDailyReport(): Promise<{ success: boolean; report:
cfg.includeStorage,
cfg.includeUsers
);
notify('CloudSearch 每日汇报 [测试]', content, 'info');
const tcfg = getDailyReportConfig();
if (tcfg.channels && tcfg.channels.length > 0) {
const allChannels = getGlobalNotifyConfigs();
const filtered = allChannels.filter(c => tcfg.channels!.includes(c.name));
if (filtered.length > 0) {
sendToChannels(filtered, 'CloudSearch 每日汇报 [测试]', content, 'info').catch(() => {});
}
} else {
notify('CloudSearch 每日汇报 [测试]', content, 'info');
}
return { success: true, report };
}