mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
改进ntfy通知,将中文标题进行编码后发送 (#2541)
* 1.改进ntfy通知,将中文标题进行编码后发送,可以直接展示中文标题;2.改进notify.py和notify.js中ntfy的推送; --------- Co-authored-by: qiaoyun680 <qiaoyun680>
This commit is contained in:
@@ -666,12 +666,18 @@ export default class NotificationService {
|
||||
|
||||
private async ntfy() {
|
||||
const { ntfyUrl, ntfyTopic, ntfyPriority } = 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 res: any = await got
|
||||
.post(`${ntfyUrl || 'https://ntfy.sh'}/${ntfyTopic}`, {
|
||||
...this.gotOption,
|
||||
body: `${this.title}\n${this.content}`,
|
||||
headers: { 'Title': 'qinglong', 'Priority': `${ntfyPriority || '3'}` },
|
||||
body: `${this.content}`,
|
||||
headers: { 'Title': encodedTitle, 'Priority': `${ntfyPriority || '3'}` },
|
||||
});
|
||||
if (res.statusCode === 200) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user