修复通知

This commit is contained in:
hanhh 2021-09-19 23:00:21 +08:00
parent aa08f489d7
commit f482796cdf

View File

@ -80,21 +80,25 @@ export default class NotificationService {
private async serverChan() { private async serverChan() {
const { serverChanKey } = this.params; const { serverChanKey } = this.params;
const url = serverChanKey.includes('SCT') const url = serverChanKey.startsWith('SCT')
? `https://sctapi.ftqq.com/${SCKEY}.send` ? `https://sctapi.ftqq.com/${serverChanKey}.send`
: `https://sc.ftqq.com/${SCKEY}.send`; : `https://sc.ftqq.com/${serverChanKey}.send`;
const res: any = await got const res: any = await got
.post(url, { .post(url, {
timeout: this.timeout, timeout: this.timeout,
retry: 0, retry: 0,
body: `text=${this.title}&desp=${this.content}`, body: `title=${this.title}&desp=${this.content}`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}) })
.json(); .json();
return res.errno === 0 || res.data.errno === 0; return res.errno === 0 || res.data.errno === 0;
} }
private async bark() { private async bark() {
const { barkPush, barkSound, barkGroup } = this.params; let { barkPush, barkSound, barkGroup } = this.params;
if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) {
barkPush = `https://api.day.app/${barkPush}`;
}
const url = `${barkPush}/${encodeURIComponent( const url = `${barkPush}/${encodeURIComponent(
this.title, this.title,
)}/${encodeURIComponent( )}/${encodeURIComponent(
@ -119,8 +123,12 @@ export default class NotificationService {
telegramBotToken, telegramBotToken,
telegramBotUserId, telegramBotUserId,
} = this.params; } = this.params;
const url = `https://${telegramBotApiHost}/bot${telegramBotToken}/sendMessage`; const url = `https://${
const options = { telegramBotApiHost ? telegramBotApiHost : 'api.telegram.org'
}/bot${telegramBotToken}/sendMessage`;
let agent;
if (telegramBotProxyHost && telegramBotProxyPort) {
const options: any = {
keepAlive: true, keepAlive: true,
keepAliveMsecs: 1000, keepAliveMsecs: 1000,
maxSockets: 256, maxSockets: 256,
@ -129,16 +137,18 @@ export default class NotificationService {
}; };
const httpAgent = new HttpProxyAgent(options); const httpAgent = new HttpProxyAgent(options);
const httpsAgent = new HttpsProxyAgent(options); const httpsAgent = new HttpsProxyAgent(options);
agent = {
http: httpAgent,
https: httpsAgent,
};
}
const res: any = await got const res: any = await got
.post(url, { .post(url, {
timeout: this.timeout, timeout: this.timeout,
retry: 0, retry: 0,
body: `chat_id=${telegramBotUserId}&text=${this.title}\n\n${this.content}&disable_web_page_preview=true`, body: `chat_id=${telegramBotUserId}&text=${this.title}\n\n${this.content}&disable_web_page_preview=true`,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
agent: { agent,
http: httpAgent,
https: httpsAgent,
},
}) })
.json(); .json();
return !!res.ok; return !!res.ok;