perf: 通知选择器优化

This commit is contained in:
xiaojunnuo
2024-12-02 14:06:55 +08:00
parent 68a503796c
commit 2c0cbdd29e
11 changed files with 274 additions and 150 deletions

View File

@@ -140,4 +140,17 @@ export class NotificationController extends CrudController<NotificationService>
const res = await this.service.setDefault(id, this.getUserId());
return this.ok(res);
}
@Post('/options', { summary: Constants.per.authOnly })
async options() {
const res = await this.service.list({
query: {
userId: this.getUserId(),
},
});
for (const item of res) {
delete item.setting;
}
return this.ok(res);
}
}

View File

@@ -30,6 +30,27 @@ export class DiscordNotification extends BaseNotification {
})
mentionedList!: string[];
@NotificationInput({
title: '代理',
component: {
placeholder: 'http://xxxxx:xx',
},
helper: '使用https_proxy',
required: false,
})
httpsProxy = '';
@NotificationInput({
title: '忽略证书校验',
value: false,
component: {
name: 'a-switch',
vModel: 'checked',
},
required: false,
})
skipSslVerify: boolean;
async send(body: NotificationBody) {
if (!this.webhook) {
throw new Error('Webhook URL 不能为空');
@@ -49,6 +70,8 @@ export class DiscordNotification extends BaseNotification {
url: this.webhook,
method: 'POST',
data: json,
httpProxy: this.httpsProxy,
skipSslVerify: this.skipSslVerify,
});
}
}

View File

@@ -17,6 +17,27 @@ export class SlackNotification extends BaseNotification {
})
webhook = '';
@NotificationInput({
title: '代理',
component: {
placeholder: 'http://xxxxx:xx',
},
helper: '使用https_proxy',
required: false,
})
httpsProxy = '';
@NotificationInput({
title: '忽略证书校验',
value: false,
component: {
name: 'a-switch',
vModel: 'checked',
},
required: false,
})
skipSslVerify: boolean;
async send(body: NotificationBody) {
if (!this.webhook) {
throw new Error('token不能为空');
@@ -28,6 +49,8 @@ export class SlackNotification extends BaseNotification {
data: {
text: `${body.title}\n${body.content}\n[查看详情](${body.url})`,
},
httpProxy: this.httpsProxy,
skipSslVerify: this.skipSslVerify,
});
}
}

View File

@@ -7,6 +7,16 @@ import { BaseNotification, IsNotification, NotificationBody, NotificationInput }
needPlus: true,
})
export class TelegramNotification extends BaseNotification {
@NotificationInput({
title: 'URL',
value: 'https://api.telegram.org',
component: {
placeholder: 'https://api.telegram.org',
},
required: true,
})
endpoint = 'https://api.telegram.org';
@NotificationInput({
title: 'Bot Token',
component: {
@@ -27,6 +37,27 @@ export class TelegramNotification extends BaseNotification {
})
chatId = '';
@NotificationInput({
title: '代理',
component: {
placeholder: 'http://xxxxx:xx',
},
helper: '使用https_proxy',
required: false,
})
httpsProxy = '';
@NotificationInput({
title: '忽略证书校验',
value: false,
component: {
name: 'a-switch',
vModel: 'checked',
},
required: false,
})
skipSslVerify: boolean;
async send(body: NotificationBody) {
if (!this.botToken || !this.chatId) {
throw new Error('Bot Token 和聊天ID不能为空');
@@ -47,6 +78,8 @@ export class TelegramNotification extends BaseNotification {
text: messageContent,
parse_mode: 'MarkdownV2', // 或使用 'HTML' 取决于需要的格式
},
httpProxy: this.httpsProxy,
skipSslVerify: this.skipSslVerify,
});
}
}