34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
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' },
|
|
|
|
];
|
|
|
|
export const gotifyNotifier: Notifier = {
|
|
name: 'gotify',
|
|
label: 'Gotify',
|
|
params,
|
|
async notify(params) {
|
|
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 };
|
|
}
|
|
},
|
|
};
|