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
0d23d599
authored
Dec 08, 2025
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fetch upstream models
parent
52c9e0ed
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
controller/channel.go
+30
-7
No files found.
controller/channel.go
View file @
0d23d599
...
...
@@ -165,6 +165,30 @@ func GetAllChannels(c *gin.Context) {
return
}
func
buildFetchModelsHeaders
(
channel
*
model
.
Channel
,
key
string
)
(
http
.
Header
,
error
)
{
var
headers
http
.
Header
switch
channel
.
Type
{
case
constant
.
ChannelTypeAnthropic
:
headers
=
GetClaudeAuthHeader
(
key
)
default
:
headers
=
GetAuthHeader
(
key
)
}
headerOverride
:=
channel
.
GetHeaderOverride
()
for
k
,
v
:=
range
headerOverride
{
str
,
ok
:=
v
.
(
string
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"invalid header override for key %s"
,
k
)
}
if
strings
.
Contains
(
str
,
"{api_key}"
)
{
str
=
strings
.
ReplaceAll
(
str
,
"{api_key}"
,
key
)
}
headers
.
Set
(
k
,
str
)
}
return
headers
,
nil
}
func
FetchUpstreamModels
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
...
...
@@ -223,14 +247,13 @@ func FetchUpstreamModels(c *gin.Context) {
}
key
=
strings
.
TrimSpace
(
key
)
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
var
body
[]
byte
switch
channel
.
Type
{
case
constant
.
ChannelTypeAnthropic
:
body
,
err
=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetClaudeAuthHeader
(
key
))
default
:
body
,
err
=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetAuthHeader
(
key
))
headers
,
err
:=
buildFetchModelsHeaders
(
channel
,
key
)
if
err
!=
nil
{
common
.
ApiError
(
c
,
err
)
return
}
body
,
err
:=
GetResponseBody
(
"GET"
,
url
,
channel
,
headers
)
if
err
!=
nil
{
common
.
ApiError
(
c
,
err
)
return
...
...
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