feat: support channel level auth

This commit is contained in:
JustSong
2024-11-10 10:47:25 +08:00
parent 08a8688aa7
commit 1a3ebafd34
3 changed files with 56 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { Segment, Dimmer, Loader } from 'semantic-ui-react'; import { Dimmer, Loader, Segment } from 'semantic-ui-react';
const Loading = ({ prompt: name = 'page' }) => { const Loading = ({ prompt: name = 'page' }) => {
return ( return (

View File

@@ -172,3 +172,10 @@ export const verifyJSON = (str) => {
} }
return true; return true;
}; };
export const generateToken = (byteNum) => {
const bytes = crypto.getRandomValues(new Uint8Array(byteNum));
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0'))
.join('')
.toUpperCase();
};

View File

@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Button, Form, Header, Message, Segment } from 'semantic-ui-react'; import { Button, Form, Header, Message, Segment } from 'semantic-ui-react';
import { useParams } from 'react-router-dom'; import { useParams } from 'react-router-dom';
import { API, showError, showSuccess } from '../../helpers'; import { API, generateToken, showError, showSuccess } from '../../helpers';
import { CHANNEL_OPTIONS } from '../../constants'; import { CHANNEL_OPTIONS } from '../../constants';
import axios from 'axios'; import axios from 'axios';
@@ -21,6 +21,7 @@ const EditChannel = () => {
other: '', other: '',
corp_id: '', // only for corp_app corp_id: '', // only for corp_app
agent_id: '', // only for corp_app agent_id: '', // only for corp_app
token: '',
}; };
const [inputs, setInputs] = useState(originInputs); const [inputs, setInputs] = useState(originInputs);
@@ -166,9 +167,12 @@ const EditChannel = () => {
<br /> <br />
需要新增测试模板模板标题推荐填写为消息推送模板内容填写为 需要新增测试模板模板标题推荐填写为消息推送模板内容填写为
<br/>标题{' {{'}title.DATA{'}}'} <br />
<br/>描述{' {{'}description.DATA{'}}'} 标题{' {{'}title.DATA{'}}'}
<br/>内容{' {{'}content.DATA{'}}'} <br />
描述{' {{'}description.DATA{'}}'}
<br />
内容{' {{'}content.DATA{'}}'}
</Message> </Message>
<Form.Group widths={3}> <Form.Group widths={3}>
<Form.Input <Form.Input
@@ -550,7 +554,8 @@ const EditChannel = () => {
</a>{' '} </a>{' '}
等实现 利用 OneBot 协议可以实现推送 QQ 消息 等实现 利用 OneBot 协议可以实现推送 QQ 消息
<br /> <br />
注意如果推送目标是群号则前面必须加上群号前缀例如 group_123456789 注意如果推送目标是群号则前面必须加上群号前缀例如
group_123456789
</Message> </Message>
<Form.Group widths={3}> <Form.Group widths={3}>
<Form.Input <Form.Input
@@ -674,11 +679,19 @@ const EditChannel = () => {
<Message> <Message>
自定义推送目前仅支持 POST 请求请求体为 JSON 格式 自定义推送目前仅支持 POST 请求请求体为 JSON 格式
<br /> <br />
支持以下模板变量<code>$title</code><code>$description</code><code>$content</code><code>$url</code><code>$to</code> 支持以下模板变量<code>$title</code><code>$description</code>
<code>$content</code><code>$url</code><code>$to</code>
<br /> <br />
<a href="https://iamazing.cn/page/message-pusher-common-custom-templates" target='_blank'>这个页面</a> <a
href='https://iamazing.cn/page/message-pusher-common-custom-templates'
target='_blank'
>
这个页面
</a>
给出了常见的第三方平台的配置实例你可以参考这些示例进行配置
<br /> <br />
注意为了防止攻击者利用本功能访问内部网络也为了你的信息安全请求地址必须使用 HTTPS 协议 注意为了防止攻击者利用本功能访问内部网络也为了你的信息安全请求地址必须使用
HTTPS 协议
</Message> </Message>
<Form.Group widths={2}> <Form.Group widths={2}>
<Form.Input <Form.Input
@@ -697,7 +710,10 @@ const EditChannel = () => {
value={inputs.other} value={inputs.other}
name='other' name='other'
onChange={handleInputChange} onChange={handleInputChange}
style={{ minHeight: 200, fontFamily: 'JetBrains Mono, Consolas' }} style={{
minHeight: 200,
fontFamily: 'JetBrains Mono, Consolas',
}}
/> />
</Form.Group> </Form.Group>
</> </>
@@ -756,6 +772,23 @@ const EditChannel = () => {
value={type} value={type}
onChange={handleInputChange} onChange={handleInputChange}
/> />
<Form.Input
label='鉴权令牌'
name='token'
onChange={handleInputChange}
autoComplete='new-password'
value={inputs.token}
placeholder='通道维度鉴权令牌,设置后使用该通道推送需要鉴权(使用全局鉴权令牌也可以)'
action={{
content: '随机生成',
onClick: () => {
setInputs((inputs) => ({
...inputs,
token: generateToken(16),
}));
},
}}
/>
{renderChannelForm()} {renderChannelForm()}
<Button disabled={type === 'email'} onClick={submit}> <Button disabled={type === 'email'} onClick={submit}>
提交 提交