0.2.2: 消息推送插件化重构 + 14通道 + 多用户推送 + 全局推送 + 事件模板自定义 + 每日报告 + 变量说明
This commit is contained in:
33
packages/backend/src/cloud/notifiers/gotify.notifier.ts
Normal file
33
packages/backend/src/cloud/notifiers/gotify.notifier.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Notifier, NotifyParams, NotifyResult, NotifierParam } from './notifier.types';
|
||||
|
||||
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 },
|
||||
{ key: 'priority', label: '优先级', type: 'number', default: 5, required: false },
|
||||
];
|
||||
|
||||
export const gotifyNotifier: Notifier = {
|
||||
name: 'gotify',
|
||||
label: 'Gotify',
|
||||
params,
|
||||
async notify(params: NotifyParams): Promise<NotifyResult> {
|
||||
try {
|
||||
const server = params.server.replace(/\/+$/, '');
|
||||
const resp = await fetch(`${server}/message?token=${params.token}`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
title: params.title || 'CloudSearch',
|
||||
message: params.content || '',
|
||||
priority: params.priority || 5,
|
||||
}),
|
||||
});
|
||||
if (resp.ok) return { success: true, message: 'Gotify 推送成功' };
|
||||
return { success: false, message: `HTTP ${resp.status}` };
|
||||
} catch (err: any) {
|
||||
return { success: false, message: err.message };
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user