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
bc87b023
authored
May 13, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support batch creation of channels (close #58)
parent
bb13fe81
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
12 deletions
+52
-12
controller/channel.go
+12
-1
model/channel.go
+6
-0
web/src/pages/Channel/EditChannel.js
+34
-11
No files found.
controller/channel.go
View file @
bc87b023
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"one-api/common"
"one-api/common"
"one-api/model"
"one-api/model"
"strconv"
"strconv"
"strings"
)
)
func
GetAllChannels
(
c
*
gin
.
Context
)
{
func
GetAllChannels
(
c
*
gin
.
Context
)
{
...
@@ -84,7 +85,17 @@ func AddChannel(c *gin.Context) {
...
@@ -84,7 +85,17 @@ func AddChannel(c *gin.Context) {
}
}
channel
.
CreatedTime
=
common
.
GetTimestamp
()
channel
.
CreatedTime
=
common
.
GetTimestamp
()
channel
.
AccessedTime
=
common
.
GetTimestamp
()
channel
.
AccessedTime
=
common
.
GetTimestamp
()
err
=
channel
.
Insert
()
keys
:=
strings
.
Split
(
channel
.
Key
,
"
\n
"
)
channels
:=
make
([]
model
.
Channel
,
0
)
for
_
,
key
:=
range
keys
{
if
key
==
""
{
continue
}
localChannel
:=
channel
localChannel
.
Key
=
key
channels
=
append
(
channels
,
localChannel
)
}
err
=
model
.
BatchInsertChannels
(
channels
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
...
...
model/channel.go
View file @
bc87b023
...
@@ -53,6 +53,12 @@ func GetRandomChannel() (*Channel, error) {
...
@@ -53,6 +53,12 @@ func GetRandomChannel() (*Channel, error) {
return
&
channel
,
err
return
&
channel
,
err
}
}
func
BatchInsertChannels
(
channels
[]
Channel
)
error
{
var
err
error
err
=
DB
.
Create
(
&
channels
)
.
Error
return
err
}
func
(
channel
*
Channel
)
Insert
()
error
{
func
(
channel
*
Channel
)
Insert
()
error
{
var
err
error
var
err
error
err
=
DB
.
Create
(
channel
)
.
Error
err
=
DB
.
Create
(
channel
)
.
Error
...
...
web/src/pages/Channel/EditChannel.js
View file @
bc87b023
...
@@ -16,8 +16,10 @@ const EditChannel = () => {
...
@@ -16,8 +16,10 @@ const EditChannel = () => {
base_url
:
''
,
base_url
:
''
,
other
:
''
other
:
''
};
};
const
[
batch
,
setBatch
]
=
useState
(
false
);
const
[
inputs
,
setInputs
]
=
useState
(
originInputs
);
const
[
inputs
,
setInputs
]
=
useState
(
originInputs
);
const
handleInputChange
=
(
e
,
{
name
,
value
})
=>
{
const
handleInputChange
=
(
e
,
{
name
,
value
})
=>
{
console
.
log
(
name
,
value
);
setInputs
((
inputs
)
=>
({
...
inputs
,
[
name
]:
value
}));
setInputs
((
inputs
)
=>
({
...
inputs
,
[
name
]:
value
}));
};
};
...
@@ -130,17 +132,38 @@ const EditChannel = () => {
...
@@ -130,17 +132,38 @@ const EditChannel = () => {
autoComplete
=
'new-password'
autoComplete
=
'new-password'
/>
/>
<
/Form.Field
>
<
/Form.Field
>
<
Form
.
Field
>
{
<
Form
.
Input
batch
?
<
Form
.
Field
>
label
=
'密钥'
<
Form
.
TextArea
name
=
'key'
label
=
'密钥'
placeholder
=
{
'请输入密钥'
}
name
=
'key'
onChange
=
{
handleInputChange
}
placeholder
=
{
'请输入密钥,一行一个'
}
value
=
{
inputs
.
key
}
onChange
=
{
handleInputChange
}
// type='password'
value
=
{
inputs
.
key
}
autoComplete
=
'new-password'
style
=
{{
minHeight
:
150
,
fontFamily
:
'JetBrains Mono, Consolas'
}}
/>
autoComplete
=
'new-password'
<
/Form.Field
>
/>
<
/Form.Field> : <Form.Field
>
<
Form
.
Input
label
=
'密钥'
name
=
'key'
placeholder
=
{
'请输入密钥'
}
onChange
=
{
handleInputChange
}
value
=
{
inputs
.
key
}
autoComplete
=
'new-password'
/>
<
/Form.Field
>
}
{
!
isEdit
&&
(
<
Form
.
Checkbox
checked
=
{
batch
}
label
=
'批量创建'
name
=
'batch'
onChange
=
{()
=>
setBatch
(
!
batch
)}
/
>
)
}
<
Button
onClick
=
{
submit
}
>
提交
<
/Button
>
<
Button
onClick
=
{
submit
}
>
提交
<
/Button
>
<
/Form
>
<
/Form
>
<
/Segment
>
<
/Segment
>
...
...
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