diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 8bfe5812..fa77be81 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -25,6 +25,7 @@ import { ImagePreview, Card, Tag, + Upload, } from '@douyinfe/semi-ui'; import { getChannelModels } from '../../helpers'; import { @@ -34,6 +35,7 @@ import { IconSetting, IconCode, IconGlobe, + IconBolt, } from '@douyinfe/semi-icons'; const { Text, Title } = Typography; @@ -97,8 +99,9 @@ const EditChannel = (props) => { tag: '', }; const [batch, setBatch] = useState(false); + const [mergeToSingle, setMergeToSingle] = useState(false); const [autoBan, setAutoBan] = useState(true); - // const [autoBan, setAutoBan] = useState(true); + const [jsonFiles, setJsonFiles] = useState([]); const [inputs, setInputs] = useState(originInputs); const [originModelOptions, setOriginModelOptions] = useState([]); const [modelOptions, setModelOptions] = useState([]); @@ -325,9 +328,20 @@ const EditChannel = (props) => { }, [props.editingChannel.id]); const submit = async () => { - if (!isEdit && (inputs.name === '' || inputs.key === '')) { - showInfo(t('请填写渠道名称和渠道密钥!')); - return; + if (!isEdit) { + if (inputs.name === '') { + showInfo(t('请填写渠道名称!')); + return; + } + if (inputs.type === 41 && batch) { + if (jsonFiles.length === 0) { + showInfo(t('请至少选择一个 JSON 凭证文件!')); + return; + } + } else if (inputs.key === '') { + showInfo(t('请填写渠道密钥!')); + return; + } } if (inputs.models.length === 0) { showInfo(t('请至少选择一个模型!')); @@ -356,13 +370,32 @@ const EditChannel = (props) => { localInputs.auto_ban = autoBan ? 1 : 0; localInputs.models = localInputs.models.join(','); localInputs.group = localInputs.groups.join(','); + + if (inputs.type === 41 && batch) { + const keyObj = {}; + jsonFiles.forEach((content, idx) => { + keyObj[content] = idx; + }); + localInputs.key = JSON.stringify(keyObj); + } + + let mode = 'single'; + if (batch) { + mode = mergeToSingle ? 'multi_to_single' : 'batch'; + } + + const payload = { + mode, + channel: localInputs, + }; + if (isEdit) { res = await API.put(`/api/channel/`, { ...localInputs, id: parseInt(channelId), }); } else { - res = await API.post(`/api/channel/`, localInputs); + res = await API.post(`/api/channel/`, payload); } const { success, message } = res.data; if (success) { @@ -415,6 +448,18 @@ const EditChannel = (props) => { } }; + const handleJsonFileUpload = (file) => { + return new Promise((resolve) => { + const reader = new FileReader(); + reader.onload = (e) => { + const content = e.target.result; + setJsonFiles((prev) => [...prev, content]); + resolve({ shouldUpload: false, status: 'success' }); + }; + reader.readAsText(file); + }); + }; + return ( <> {
{t('密钥')} {batch ? ( -