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
a2fbf368
authored
Jul 30, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复缓存开启下自动禁用失效
parent
9055698b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
model/channel.go
+8
-11
No files found.
model/channel.go
View file @
a2fbf368
...
...
@@ -75,7 +75,7 @@ func (channel *Channel) getKeys() []string {
// If the key starts with '[', try to parse it as a JSON array (e.g., for Vertex AI scenarios)
if
strings
.
HasPrefix
(
trimmed
,
"["
)
{
var
arr
[]
json
.
RawMessage
if
err
:=
js
on
.
Unmarshal
([]
byte
(
trimmed
),
&
arr
);
err
==
nil
{
if
err
:=
comm
on
.
Unmarshal
([]
byte
(
trimmed
),
&
arr
);
err
==
nil
{
res
:=
make
([]
string
,
len
(
arr
))
for
i
,
v
:=
range
arr
{
res
[
i
]
=
string
(
v
)
...
...
@@ -197,7 +197,7 @@ func (channel *Channel) GetGroups() []string {
func
(
channel
*
Channel
)
GetOtherInfo
()
map
[
string
]
interface
{}
{
otherInfo
:=
make
(
map
[
string
]
interface
{})
if
channel
.
OtherInfo
!=
""
{
err
:=
js
on
.
Unmarshal
([]
byte
(
channel
.
OtherInfo
),
&
otherInfo
)
err
:=
comm
on
.
Unmarshal
([]
byte
(
channel
.
OtherInfo
),
&
otherInfo
)
if
err
!=
nil
{
common
.
SysError
(
"failed to unmarshal other info: "
+
err
.
Error
())
}
...
...
@@ -425,7 +425,7 @@ func (channel *Channel) Update() error {
trimmed
:=
strings
.
TrimSpace
(
keyStr
)
if
strings
.
HasPrefix
(
trimmed
,
"["
)
{
var
arr
[]
json
.
RawMessage
if
err
:=
js
on
.
Unmarshal
([]
byte
(
trimmed
),
&
arr
);
err
==
nil
{
if
err
:=
comm
on
.
Unmarshal
([]
byte
(
trimmed
),
&
arr
);
err
==
nil
{
keys
=
make
([]
string
,
len
(
arr
))
for
i
,
v
:=
range
arr
{
keys
[
i
]
=
string
(
v
)
...
...
@@ -553,6 +553,7 @@ func handlerMultiKeyUpdate(channel *Channel, usingKey string, status int) {
}
func
UpdateChannelStatus
(
channelId
int
,
usingKey
string
,
status
int
,
reason
string
)
bool
{
println
(
"UpdateChannelStatus called with channelId:"
,
channelId
,
"usingKey:"
,
usingKey
,
"status:"
,
status
,
"reason:"
,
reason
)
if
common
.
MemoryCacheEnabled
{
channelStatusLock
.
Lock
()
defer
channelStatusLock
.
Unlock
()
...
...
@@ -571,10 +572,6 @@ func UpdateChannelStatus(channelId int, usingKey string, status int, reason stri
if
channelCache
.
Status
==
status
{
return
false
}
// 如果缓存渠道不存在(说明已经被禁用),且要设置的状态不为启用,直接返回
if
status
!=
common
.
ChannelStatusEnabled
{
return
false
}
CacheUpdateChannelStatus
(
channelId
,
status
)
}
}
...
...
@@ -778,7 +775,7 @@ func SearchTags(keyword string, group string, model string, idSort bool) ([]*str
func
(
channel
*
Channel
)
ValidateSettings
()
error
{
channelParams
:=
&
dto
.
ChannelSettings
{}
if
channel
.
Setting
!=
nil
&&
*
channel
.
Setting
!=
""
{
err
:=
js
on
.
Unmarshal
([]
byte
(
*
channel
.
Setting
),
channelParams
)
err
:=
comm
on
.
Unmarshal
([]
byte
(
*
channel
.
Setting
),
channelParams
)
if
err
!=
nil
{
return
err
}
...
...
@@ -789,7 +786,7 @@ func (channel *Channel) ValidateSettings() error {
func
(
channel
*
Channel
)
GetSetting
()
dto
.
ChannelSettings
{
setting
:=
dto
.
ChannelSettings
{}
if
channel
.
Setting
!=
nil
&&
*
channel
.
Setting
!=
""
{
err
:=
js
on
.
Unmarshal
([]
byte
(
*
channel
.
Setting
),
&
setting
)
err
:=
comm
on
.
Unmarshal
([]
byte
(
*
channel
.
Setting
),
&
setting
)
if
err
!=
nil
{
common
.
SysError
(
"failed to unmarshal setting: "
+
err
.
Error
())
channel
.
Setting
=
nil
// 清空设置以避免后续错误
...
...
@@ -800,7 +797,7 @@ func (channel *Channel) GetSetting() dto.ChannelSettings {
}
func
(
channel
*
Channel
)
SetSetting
(
setting
dto
.
ChannelSettings
)
{
settingBytes
,
err
:=
js
on
.
Marshal
(
setting
)
settingBytes
,
err
:=
comm
on
.
Marshal
(
setting
)
if
err
!=
nil
{
common
.
SysError
(
"failed to marshal setting: "
+
err
.
Error
())
return
...
...
@@ -811,7 +808,7 @@ func (channel *Channel) SetSetting(setting dto.ChannelSettings) {
func
(
channel
*
Channel
)
GetParamOverride
()
map
[
string
]
interface
{}
{
paramOverride
:=
make
(
map
[
string
]
interface
{})
if
channel
.
ParamOverride
!=
nil
&&
*
channel
.
ParamOverride
!=
""
{
err
:=
js
on
.
Unmarshal
([]
byte
(
*
channel
.
ParamOverride
),
&
paramOverride
)
err
:=
comm
on
.
Unmarshal
([]
byte
(
*
channel
.
ParamOverride
),
&
paramOverride
)
if
err
!=
nil
{
common
.
SysError
(
"failed to unmarshal param override: "
+
err
.
Error
())
}
...
...
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