Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
db3dd8e3
authored
Sep 27, 2025
by
Seefs
Committed by
GitHub
Sep 27, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1862 from HynoR/fix/dup3
feat: add duplicate key removal function when edit or add new channel
parents
acd5a473
afecbb07
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
9 deletions
+83
-9
web/src/components/table/channels/modals/EditChannelModal.jsx
+83
-9
No files found.
web/src/components/table/channels/modals/EditChannelModal.jsx
View file @
db3dd8e3
...
@@ -822,7 +822,9 @@ const EditChannelModal = (props) => {
...
@@ -822,7 +822,9 @@ const EditChannelModal = (props) => {
delete
localInputs
.
key
;
delete
localInputs
.
key
;
}
}
}
else
{
}
else
{
localInputs
.
key
=
batch
?
JSON
.
stringify
(
keys
)
:
JSON
.
stringify
(
keys
[
0
]);
localInputs
.
key
=
batch
?
JSON
.
stringify
(
keys
)
:
JSON
.
stringify
(
keys
[
0
]);
}
}
}
}
}
}
...
@@ -919,6 +921,56 @@ const EditChannelModal = (props) => {
...
@@ -919,6 +921,56 @@ const EditChannelModal = (props) => {
}
}
};
};
// 密钥去重函数
const
deduplicateKeys
=
()
=>
{
const
currentKey
=
formApiRef
.
current
?.
getValue
(
'key'
)
||
inputs
.
key
||
''
;
if
(
!
currentKey
.
trim
())
{
showInfo
(
t
(
'请先输入密钥'
));
return
;
}
// 按行分割密钥
const
keyLines
=
currentKey
.
split
(
'\n'
);
const
beforeCount
=
keyLines
.
length
;
// 使用哈希表去重,保持原有顺序
const
keySet
=
new
Set
();
const
deduplicatedKeys
=
[];
keyLines
.
forEach
((
line
)
=>
{
const
trimmedLine
=
line
.
trim
();
if
(
trimmedLine
&&
!
keySet
.
has
(
trimmedLine
))
{
keySet
.
add
(
trimmedLine
);
deduplicatedKeys
.
push
(
trimmedLine
);
}
});
const
afterCount
=
deduplicatedKeys
.
length
;
const
deduplicatedKeyText
=
deduplicatedKeys
.
join
(
'\n'
);
// 更新表单和状态
if
(
formApiRef
.
current
)
{
formApiRef
.
current
.
setValue
(
'key'
,
deduplicatedKeyText
);
}
handleInputChange
(
'key'
,
deduplicatedKeyText
);
// 显示去重结果
const
message
=
t
(
'去重完成:去重前 {{before}} 个密钥,去重后 {{after}} 个密钥'
,
{
before
:
beforeCount
,
after
:
afterCount
,
},
);
if
(
beforeCount
===
afterCount
)
{
showInfo
(
t
(
'未发现重复密钥'
));
}
else
{
showSuccess
(
message
);
}
};
const
addCustomModels
=
()
=>
{
const
addCustomModels
=
()
=>
{
if
(
customModel
.
trim
()
===
''
)
return
;
if
(
customModel
.
trim
()
===
''
)
return
;
const
modelArray
=
customModel
.
split
(
','
).
map
((
model
)
=>
model
.
trim
());
const
modelArray
=
customModel
.
split
(
','
).
map
((
model
)
=>
model
.
trim
());
...
@@ -1014,24 +1066,41 @@ const EditChannelModal = (props) => {
...
@@ -1014,24 +1066,41 @@ const EditChannelModal = (props) => {
</
Checkbox
>
</
Checkbox
>
)
}
)
}
{
batch
&&
(
{
batch
&&
(
<>
<
Checkbox
<
Checkbox
disabled=
{
isEdit
}
disabled=
{
isEdit
}
checked=
{
multiToSingle
}
checked=
{
multiToSingle
}
onChange=
{
()
=>
{
onChange=
{
()
=>
{
setMultiToSingle
((
prev
)
=>
!
prev
);
setMultiToSingle
((
prev
)
=>
{
setInputs
((
prev
)
=>
{
const
nextValue
=
!
prev
;
const
newInputs
=
{
...
prev
};
setInputs
((
prevInputs
)
=>
{
if
(
!
multiToSingle
)
{
const
newInputs
=
{
...
prevInputs
};
if
(
nextValue
)
{
newInputs
.
multi_key_mode
=
multiKeyMode
;
newInputs
.
multi_key_mode
=
multiKeyMode
;
}
else
{
}
else
{
delete
newInputs
.
multi_key_mode
;
delete
newInputs
.
multi_key_mode
;
}
}
return
newInputs
;
return
newInputs
;
});
});
return
nextValue
;
});
}
}
}
}
>
>
{
t
(
'密钥聚合模式'
)
}
{
t
(
'密钥聚合模式'
)
}
</
Checkbox
>
</
Checkbox
>
{
inputs
.
type
!==
41
&&
(
<
Button
size=
'small'
type=
'tertiary'
theme=
'outline'
onClick=
{
deduplicateKeys
}
style=
{
{
textDecoration
:
'underline'
}
}
>
{
t
(
'密钥去重'
)
}
</
Button
>
)
}
</>
)
}
)
}
</
Space
>
</
Space
>
)
:
null
;
)
:
null
;
...
@@ -1218,7 +1287,10 @@ const EditChannelModal = (props) => {
...
@@ -1218,7 +1287,10 @@ const EditChannelModal = (props) => {
value=
{
inputs
.
vertex_key_type
||
'json'
}
value=
{
inputs
.
vertex_key_type
||
'json'
}
onChange=
{
(
value
)
=>
{
onChange=
{
(
value
)
=>
{
// 更新设置中的 vertex_key_type
// 更新设置中的 vertex_key_type
handleChannelOtherSettingsChange
(
'vertex_key_type'
,
value
);
handleChannelOtherSettingsChange
(
'vertex_key_type'
,
value
,
);
// 切换为 api_key 时,关闭批量与手动/文件切换,并清理已选文件
// 切换为 api_key 时,关闭批量与手动/文件切换,并清理已选文件
if
(
value
===
'api_key'
)
{
if
(
value
===
'api_key'
)
{
setBatch
(
false
);
setBatch
(
false
);
...
@@ -1238,7 +1310,8 @@ const EditChannelModal = (props) => {
...
@@ -1238,7 +1310,8 @@ const EditChannelModal = (props) => {
/>
/>
)
}
)
}
{
batch
?
(
{
batch
?
(
inputs
.
type
===
41
&&
(
inputs
.
vertex_key_type
||
'json'
)
===
'json'
?
(
inputs
.
type
===
41
&&
(
inputs
.
vertex_key_type
||
'json'
)
===
'json'
?
(
<
Form
.
Upload
<
Form
.
Upload
field=
'vertex_files'
field=
'vertex_files'
label=
{
t
(
'密钥文件 (.json)'
)
}
label=
{
t
(
'密钥文件 (.json)'
)
}
...
@@ -1274,7 +1347,7 @@ const EditChannelModal = (props) => {
...
@@ -1274,7 +1347,7 @@ const EditChannelModal = (props) => {
autoComplete=
'new-password'
autoComplete=
'new-password'
onChange=
{
(
value
)
=>
handleInputChange
(
'key'
,
value
)
}
onChange=
{
(
value
)
=>
handleInputChange
(
'key'
,
value
)
}
extraText=
{
extraText=
{
<
div
className=
'flex items-center gap-2'
>
<
div
className=
'flex items-center gap-2
flex-wrap
'
>
{
isEdit
&&
{
isEdit
&&
isMultiKeyChannel
&&
isMultiKeyChannel
&&
keyMode
===
'append'
&&
(
keyMode
===
'append'
&&
(
...
@@ -1302,7 +1375,8 @@ const EditChannelModal = (props) => {
...
@@ -1302,7 +1375,8 @@ const EditChannelModal = (props) => {
)
)
)
:
(
)
:
(
<>
<>
{
inputs
.
type
===
41
&&
(
inputs
.
vertex_key_type
||
'json'
)
===
'json'
?
(
{
inputs
.
type
===
41
&&
(
inputs
.
vertex_key_type
||
'json'
)
===
'json'
?
(
<>
<>
{
!
batch
&&
(
{
!
batch
&&
(
<
div
className=
'flex items-center justify-between mb-3'
>
<
div
className=
'flex items-center justify-between mb-3'
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment