From 1a3ebafd34efcb3e12c329adf8c8ff9cd5108c5e Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 10 Nov 2024 10:47:25 +0800 Subject: [PATCH] feat: support channel level auth --- web/src/components/Loading.js | 4 +- web/src/helpers/utils.js | 7 ++++ web/src/pages/Channel/EditChannel.js | 61 +++++++++++++++++++++------- 3 files changed, 56 insertions(+), 16 deletions(-) diff --git a/web/src/components/Loading.js b/web/src/components/Loading.js index 1210a56..73a8da5 100644 --- a/web/src/components/Loading.js +++ b/web/src/components/Loading.js @@ -1,11 +1,11 @@ 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' }) => { return ( - 加载{name}中... + 加载 {name} 中... ); diff --git a/web/src/helpers/utils.js b/web/src/helpers/utils.js index be5decc..4ec2c5f 100644 --- a/web/src/helpers/utils.js +++ b/web/src/helpers/utils.js @@ -172,3 +172,10 @@ export const verifyJSON = (str) => { } 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(); +}; diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 524d190..3cd9394 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { Button, Form, Header, Message, Segment } from 'semantic-ui-react'; 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 axios from 'axios'; @@ -21,6 +21,7 @@ const EditChannel = () => { other: '', corp_id: '', // only for corp_app agent_id: '', // only for corp_app + token: '', }; const [inputs, setInputs] = useState(originInputs); @@ -91,7 +92,7 @@ const EditChannel = () => { } try { JSON.parse(localInputs.other); - }catch (e) { + } catch (e) { showError('JSON 格式错误:' + e.message); return; } @@ -166,9 +167,12 @@ const EditChannel = () => { 。
需要新增测试模板,模板标题推荐填写为「消息推送」,模板内容填写为: -
标题:{' {{'}title.DATA{'}}'} -
描述:{' {{'}description.DATA{'}}'} -
内容:{' {{'}content.DATA{'}}'} +
+ 标题:{' {{'}title.DATA{'}}'} +
+ 描述:{' {{'}description.DATA{'}}'} +
+ 内容:{' {{'}content.DATA{'}}'} { cqhttp {' '} 等实现。 利用 OneBot 协议可以实现推送 QQ 消息。 -
- 注意,如果推送目标是群号则前面必须加上群号前缀,例如 group_123456789。 +
+ 注意,如果推送目标是群号则前面必须加上群号前缀,例如 + group_123456789。 { <> 自定义推送,目前仅支持 POST 请求,请求体为 JSON 格式。 -
- 支持以下模板变量:$title$description$content$url$to。 -
- 这个页面给出了常见的第三方平台的配置实例,你可以参考这些示例进行配置。 -
- 注意,为了防止攻击者利用本功能访问内部网络,也为了你的信息安全,请求地址必须使用 HTTPS 协议。 +
+ 支持以下模板变量:$title$description, + $content$url$to。 +
+ + 这个页面 + + 给出了常见的第三方平台的配置实例,你可以参考这些示例进行配置。 +
+ 注意,为了防止攻击者利用本功能访问内部网络,也为了你的信息安全,请求地址必须使用 + HTTPS 协议。
{ value={inputs.other} name='other' onChange={handleInputChange} - style={{ minHeight: 200, fontFamily: 'JetBrains Mono, Consolas' }} + style={{ + minHeight: 200, + fontFamily: 'JetBrains Mono, Consolas', + }} /> @@ -756,6 +772,23 @@ const EditChannel = () => { value={type} onChange={handleInputChange} /> + { + setInputs((inputs) => ({ + ...inputs, + token: generateToken(16), + })); + }, + }} + /> {renderChannelForm()}