v0.3.5: restore full push notification system (14 channels)
Restored from v0.2.4: - notifiers/: 14 push channels (bark/serverchan/telegram/lark/webhook/wechat/discord/smtp/...) - push-user.service.ts: multi-user push config linked to cloud_configs.promotion_account - notification.service.ts: full dispatcher with per-config + global fallback New integrations: - cloud.service.ts: notifyConfigEvent on save_success/cookie_expire/save_fail - admin.routes.ts: 7 new API endpoints for push users, notify providers, channel test - database.ts: migration for cloud_configs.notify_config column How it works: - Configure push channels in /admin/system-configs (global_notify_config JSON) - Or per-cloud: link push_users.account = cloud_configs.promotion_account - Notify events: save_success (green), cookie_expire (red), save_fail >=3 consecutive (yellow)
This commit is contained in:
44
source_clean/src/cloud/notifiers/bark.notifier.ts
Normal file
44
source_clean/src/cloud/notifiers/bark.notifier.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.types';
|
||||
|
||||
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 },
|
||||
{ key: 'level', label: '级别', type: 'text', default: 'info', required: false },
|
||||
];
|
||||
|
||||
export const barkNotifier: Notifier = {
|
||||
name: 'bark',
|
||||
label: 'Bark',
|
||||
params,
|
||||
async notify(params) {
|
||||
try {
|
||||
const key = params.key;
|
||||
const server = (params.server || 'https://api.day.app').replace(/\/+$/, '');
|
||||
const title = params.title || 'CloudSearch';
|
||||
const content = params.content || '';
|
||||
const level = params.level || 'info';
|
||||
const icon = level === 'error' ? '⚠️' : level === 'warn' ? '🔔' : 'ℹ️';
|
||||
const resp = await fetch(`${server}/${key}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
title: `${icon} ${title}`,
|
||||
body: content,
|
||||
group: 'CloudSearch',
|
||||
level: level === 'error' ? 'timeSensitive' : 'active',
|
||||
icon: '',
|
||||
}),
|
||||
});
|
||||
if (!resp.ok) {
|
||||
const text = await resp.text();
|
||||
return { success: false, message: `HTTP ${resp.status}: ${text.slice(0, 100)}` };
|
||||
}
|
||||
return { success: true, message: 'Bark 推送成功' };
|
||||
}
|
||||
catch (err: any) {
|
||||
return { success: false, message: err.message };
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user