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
3085e512
authored
Jun 15, 2024
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 记录自动禁用原因 (close #300)
parent
5efdabf1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
50 deletions
+57
-50
constant/system-setting.go
+0
-0
model/channel.go
+44
-3
service/channel.go
+2
-2
web/src/components/TokensTable.js
+11
-45
No files found.
constant/system.go
→
constant/system
-setting
.go
View file @
3085e512
File moved
model/channel.go
View file @
3085e512
package
model
package
model
import
(
import
(
"encoding/json"
"gorm.io/gorm"
"gorm.io/gorm"
"one-api/common"
"one-api/common"
)
)
...
@@ -29,6 +30,31 @@ type Channel struct {
...
@@ -29,6 +30,31 @@ type Channel struct {
StatusCodeMapping
*
string
`json:"status_code_mapping" gorm:"type:varchar(1024);default:''"`
StatusCodeMapping
*
string
`json:"status_code_mapping" gorm:"type:varchar(1024);default:''"`
Priority
*
int64
`json:"priority" gorm:"bigint;default:0"`
Priority
*
int64
`json:"priority" gorm:"bigint;default:0"`
AutoBan
*
int
`json:"auto_ban" gorm:"default:1"`
AutoBan
*
int
`json:"auto_ban" gorm:"default:1"`
OtherInfo
string
`json:"other_info"`
}
func
(
channel
*
Channel
)
GetOtherInfo
()
map
[
string
]
interface
{}
{
var
otherInfo
map
[
string
]
interface
{}
if
channel
.
OtherInfo
!=
""
{
err
:=
json
.
Unmarshal
([]
byte
(
channel
.
OtherInfo
),
&
otherInfo
)
if
err
!=
nil
{
common
.
SysError
(
"failed to unmarshal other info: "
+
err
.
Error
())
}
}
return
otherInfo
}
func
(
channel
*
Channel
)
SetOtherInfo
(
otherInfo
map
[
string
]
interface
{})
{
otherInfoBytes
,
err
:=
json
.
Marshal
(
otherInfo
)
if
err
!=
nil
{
common
.
SysError
(
"failed to marshal other info: "
+
err
.
Error
())
return
}
channel
.
OtherInfo
=
string
(
otherInfoBytes
)
}
func
(
channel
*
Channel
)
Save
()
error
{
return
DB
.
Save
(
channel
)
.
Error
}
}
func
GetAllChannels
(
startIdx
int
,
num
int
,
selectAll
bool
,
idSort
bool
)
([]
*
Channel
,
error
)
{
func
GetAllChannels
(
startIdx
int
,
num
int
,
selectAll
bool
,
idSort
bool
)
([]
*
Channel
,
error
)
{
...
@@ -213,15 +239,30 @@ func (channel *Channel) Delete() error {
...
@@ -213,15 +239,30 @@ func (channel *Channel) Delete() error {
return
err
return
err
}
}
func
UpdateChannelStatusById
(
id
int
,
status
int
)
{
func
UpdateChannelStatusById
(
id
int
,
status
int
,
reason
string
)
{
err
:=
UpdateAbilityStatus
(
id
,
status
==
common
.
ChannelStatusEnabled
)
err
:=
UpdateAbilityStatus
(
id
,
status
==
common
.
ChannelStatusEnabled
)
if
err
!=
nil
{
if
err
!=
nil
{
common
.
SysError
(
"failed to update ability status: "
+
err
.
Error
())
common
.
SysError
(
"failed to update ability status: "
+
err
.
Error
())
}
}
err
=
DB
.
Model
(
&
Channel
{})
.
Where
(
"id = ?"
,
id
)
.
Update
(
"status"
,
status
)
.
Error
channel
,
err
:=
GetChannelById
(
id
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
common
.
SysError
(
"failed to update channel status: "
+
err
.
Error
())
// find channel by id error, directly update status
err
=
DB
.
Model
(
&
Channel
{})
.
Where
(
"id = ?"
,
id
)
.
Update
(
"status"
,
status
)
.
Error
if
err
!=
nil
{
common
.
SysError
(
"failed to update channel status: "
+
err
.
Error
())
}
}
else
{
// find channel by id success, update status and other info
info
:=
channel
.
GetOtherInfo
()
info
[
"status_reason"
]
=
reason
channel
.
SetOtherInfo
(
info
)
channel
.
Status
=
status
err
=
channel
.
Save
()
if
err
!=
nil
{
common
.
SysError
(
"failed to update channel status: "
+
err
.
Error
())
}
}
}
}
}
func
UpdateChannelUsedQuota
(
id
int
,
quota
int
)
{
func
UpdateChannelUsedQuota
(
id
int
,
quota
int
)
{
...
...
service/channel.go
View file @
3085e512
...
@@ -11,14 +11,14 @@ import (
...
@@ -11,14 +11,14 @@ import (
// disable & notify
// disable & notify
func
DisableChannel
(
channelId
int
,
channelName
string
,
reason
string
)
{
func
DisableChannel
(
channelId
int
,
channelName
string
,
reason
string
)
{
model
.
UpdateChannelStatusById
(
channelId
,
common
.
ChannelStatusAutoDisabled
)
model
.
UpdateChannelStatusById
(
channelId
,
common
.
ChannelStatusAutoDisabled
,
reason
)
subject
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被禁用"
,
channelName
,
channelId
)
subject
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被禁用"
,
channelName
,
channelId
)
content
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被禁用,原因:%s"
,
channelName
,
channelId
,
reason
)
content
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被禁用,原因:%s"
,
channelName
,
channelId
,
reason
)
notifyRootUser
(
subject
,
content
)
notifyRootUser
(
subject
,
content
)
}
}
func
EnableChannel
(
channelId
int
,
channelName
string
)
{
func
EnableChannel
(
channelId
int
,
channelName
string
)
{
model
.
UpdateChannelStatusById
(
channelId
,
common
.
ChannelStatusEnabled
)
model
.
UpdateChannelStatusById
(
channelId
,
common
.
ChannelStatusEnabled
,
""
)
subject
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被启用"
,
channelName
,
channelId
)
subject
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被启用"
,
channelName
,
channelId
)
content
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被启用"
,
channelName
,
channelId
)
content
:=
fmt
.
Sprintf
(
"通道「%s」(#%d)已被启用"
,
channelName
,
channelId
)
notifyRootUser
(
subject
,
content
)
notifyRootUser
(
subject
,
content
)
...
...
web/src/components/TokensTable.js
View file @
3085e512
...
@@ -227,6 +227,14 @@ const TokensTable = () => {
...
@@ -227,6 +227,14 @@ const TokensTable = () => {
},
},
{
{
node
:
'item'
,
node
:
'item'
,
key
:
'lobe'
,
name
:
'Lobe Chat'
,
onClick
:
()
=>
{
onOpenLink
(
'lobe'
,
record
.
key
);
},
},
{
node
:
'item'
,
key
:
'ama'
,
key
:
'ama'
,
name
:
'AMA 问天(BotGem)'
,
name
:
'AMA 问天(BotGem)'
,
onClick
:
()
=>
{
onClick
:
()
=>
{
...
@@ -377,51 +385,6 @@ const TokensTable = () => {
...
@@ -377,51 +385,6 @@ const TokensTable = () => {
await
loadTokens
(
activePage
-
1
);
await
loadTokens
(
activePage
-
1
);
};
};
const
onCopy
=
async
(
type
,
key
)
=>
{
let
status
=
localStorage
.
getItem
(
'status'
);
let
serverAddress
=
''
;
if
(
status
)
{
status
=
JSON
.
parse
(
status
);
serverAddress
=
status
.
server_address
;
}
if
(
serverAddress
===
''
)
{
serverAddress
=
window
.
location
.
origin
;
}
let
encodedServerAddress
=
encodeURIComponent
(
serverAddress
);
const
nextLink
=
localStorage
.
getItem
(
'chat_link'
);
const
mjLink
=
localStorage
.
getItem
(
'chat_link2'
);
let
nextUrl
;
if
(
nextLink
)
{
nextUrl
=
nextLink
+
`/#/?settings={"key":"sk-
${
key
}
","url":"
${
serverAddress
}
"}`
;
}
else
{
nextUrl
=
`https://chat.oneapi.pro/#/?settings={"key":"sk-
${
key
}
","url":"
${
serverAddress
}
"}`
;
}
let
url
;
switch
(
type
)
{
case
'ama'
:
url
=
mjLink
+
`/#/?settings={"key":"sk-
${
key
}
","url":"
${
serverAddress
}
"}`
;
break
;
case
'opencat'
:
url
=
`opencat://team/join?domain=
${
encodedServerAddress
}
&token=sk-
${
key
}
`
;
break
;
case
'next'
:
url
=
nextUrl
;
break
;
default
:
url
=
`sk-
${
key
}
`
;
}
// if (await copy(url)) {
// showSuccess('已复制到剪贴板!');
// } else {
// showWarning('无法复制到剪贴板,请手动复制,已将令牌填入搜索框。');
// setSearchKeyword(url);
// }
};
const
copyText
=
async
(
text
)
=>
{
const
copyText
=
async
(
text
)
=>
{
if
(
await
copy
(
text
))
{
if
(
await
copy
(
text
))
{
showSuccess
(
'已复制到剪贴板!'
);
showSuccess
(
'已复制到剪贴板!'
);
...
@@ -461,6 +424,9 @@ const TokensTable = () => {
...
@@ -461,6 +424,9 @@ const TokensTable = () => {
case
'opencat'
:
case
'opencat'
:
url
=
`opencat://team/join?domain=
${
encodedServerAddress
}
&token=sk-
${
key
}
`
;
url
=
`opencat://team/join?domain=
${
encodedServerAddress
}
&token=sk-
${
key
}
`
;
break
;
break
;
case
'lobe'
:
url
=
`https://chat-preview.lobehub.com/?settings={"keyVaults":{"openai":{"apiKey":"sk-
${
key
}
","baseURL":"
${
encodedServerAddress
}
"}}}`
;
break
;
case
'next-mj'
:
case
'next-mj'
:
url
=
url
=
mjLink
+
`/#/?settings={"key":"sk-
${
key
}
","url":"
${
serverAddress
}
"}`
;
mjLink
+
`/#/?settings={"key":"sk-
${
key
}
","url":"
${
serverAddress
}
"}`
;
...
...
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