改进ntfy通知,将中文标题进行编码后发送 (#2541)

* 1.改进ntfy通知,将中文标题进行编码后发送,可以直接展示中文标题;2.改进notify.py和notify.js中ntfy的推送;
---------

Co-authored-by: qiaoyun680 <qiaoyun680>
This commit is contained in:
qiaoyun680
2024-10-23 16:38:51 +08:00
committed by GitHub
parent ecc55883f0
commit 56bc2f0b1d
3 changed files with 35 additions and 13 deletions
+8 -2
View File
@@ -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;