feat: support custom channel now (close #72, close #75, #71)

This commit is contained in:
JustSong
2023-05-08 22:20:14 +08:00
parent 6914575f47
commit 82068de143
6 changed files with 90 additions and 2 deletions
+6
View File
@@ -41,6 +41,12 @@ export const CHANNEL_OPTIONS = [
value: 'one_bot',
color: '#76FF03',
},
{
key: 'custom',
text: '自定义消息通道',
value: 'custom',
color: '#cc33ff',
},
{
key: 'group',
text: '群组消息',
+47 -1
View File
@@ -83,6 +83,19 @@ const EditChannel = () => {
);
return;
}
break;
case 'custom':
if (!localInputs.url.startsWith('https://')) {
showError('自定义通道的 URL 必须以 https:// 开头!');
return;
}
try {
JSON.parse(localInputs.other);
}catch (e) {
showError('JSON 格式错误:' + e.message);
return;
}
break;
}
if (isEditing) {
res = await API.put(`/api/channel/`, {
@@ -601,7 +614,40 @@ const EditChannel = () => {
</Form.Group>
</>
);
case 'custom':
return (
<>
<Message>
自定义推送目前仅支持 POST 请求请求体为 JSON 格式
<br/>
支持以下模板变量<code>$title</code><code>$description</code><code>$content</code><code>$url</code><code>$to</code>
<br/>
<a href="https://iamazing.cn/page/message-pusher-common-custom-templates" target='_blank'>这个页面</a>
<br/>
注意为了防止攻击者利用本功能访问内部网络也为了你的信息安全请求地址必须使用 HTTPS 协议
</Message>
<Form.Group widths={2}>
<Form.Input
label='请求地址'
name='url'
onChange={handleInputChange}
autoComplete='new-password'
value={inputs.url}
placeholder='在此填写完整的请求地址,必须使用 HTTPS 协议'
/>
</Form.Group>
<Form.Group widths='equal'>
<Form.TextArea
label='请求体'
placeholder='在此输入请求体,支持模板变量,必须为合法的 JSON 格式'
value={inputs.other}
name='other'
onChange={handleInputChange}
style={{ minHeight: 200, fontFamily: 'JetBrains Mono, Consolas' }}
/>
</Form.Group>
</>
);
case 'none':
return (
<>