mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
ntfy 增加可选的认证与用户动作 (#2741)
* feat:ntfy增加可选的认证 * feat:ntfy增加可选的用户动作 * fix:ntfy动作包含中文报错
This commit is contained in:
+15
-3
@@ -623,20 +623,32 @@ export default class NotificationService {
|
||||
}
|
||||
|
||||
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 encodedText = Buffer.from(text).toString('base64');
|
||||
return `=?${charset}?B?${encodedText}?=`;
|
||||
};
|
||||
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(
|
||||
`${ntfyUrl || 'https://ntfy.sh'}/${ntfyTopic}`,
|
||||
{
|
||||
...this.gotOption,
|
||||
body: `${this.content}`,
|
||||
headers: { Title: encodedTitle, Priority: `${ntfyPriority || '3'}` },
|
||||
headers: headers,
|
||||
method: 'POST',
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user