修复自定义通知

This commit is contained in:
whyour
2022-09-20 19:13:11 +08:00
parent e08f0cd308
commit f23e7a9e49
3 changed files with 22 additions and 8 deletions
+17 -2
View File
@@ -389,8 +389,12 @@ export default class NotificationService {
const { webhookUrl, webhookBody, webhookHeaders, webhookMethod, webhookContentType } =
this.params;
const { formatBody, formatUrl } = this.formatNotifyContent(webhookUrl, webhookBody);
if (!formatUrl && !formatBody) {
return false;
}
const headers = parseHeaders(webhookHeaders);
const body = parseBody(webhookBody, webhookContentType);
const body = parseBody(formatBody, webhookContentType);
const bodyParam = this.formatBody(webhookContentType, body);
const options = {
method: webhookMethod,
@@ -400,7 +404,7 @@ export default class NotificationService {
allowGetBody: true,
...bodyParam
}
const res = await got(webhookUrl, options);
const res = await got(formatUrl, options);
return String(res.statusCode).startsWith('20');
}
@@ -416,4 +420,15 @@ export default class NotificationService {
}
return {};
}
private formatNotifyContent(url: string, body: string) {
if (!url.includes('$title') && !body.includes('$title')) {
return {};
}
return {
formatUrl: url.replaceAll('$title', encodeURIComponent(this.title)).replaceAll('$content', encodeURIComponent(this.content)),
formatBody: body.replaceAll('$title', this.title).replaceAll('$content', this.content),
}
}
}