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
8e8fbc8e
authored
Dec 09, 2025
by
Calcium-Ion
Committed by
GitHub
Dec 09, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2394 from seefs001/fix/fetch-model-header-overide
fix: fetch upstream models
parents
0cfaf8c6
0d23d599
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 @
8e8fbc8e
...
@@ -165,6 +165,30 @@ func GetAllChannels(c *gin.Context) {
...
@@ -165,6 +165,30 @@ func GetAllChannels(c *gin.Context) {
return
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
)
{
func
FetchUpstreamModels
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -223,14 +247,13 @@ func FetchUpstreamModels(c *gin.Context) {
...
@@ -223,14 +247,13 @@ func FetchUpstreamModels(c *gin.Context) {
}
}
key
=
strings
.
TrimSpace
(
key
)
key
=
strings
.
TrimSpace
(
key
)
// 获取响应体 - 根据渠道类型决定是否添加 AuthHeader
headers
,
err
:=
buildFetchModelsHeaders
(
channel
,
key
)
var
body
[]
byte
if
err
!=
nil
{
switch
channel
.
Type
{
common
.
ApiError
(
c
,
err
)
case
constant
.
ChannelTypeAnthropic
:
return
body
,
err
=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetClaudeAuthHeader
(
key
))
default
:
body
,
err
=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetAuthHeader
(
key
))
}
}
body
,
err
:=
GetResponseBody
(
"GET"
,
url
,
channel
,
headers
)
if
err
!=
nil
{
if
err
!=
nil
{
common
.
ApiError
(
c
,
err
)
common
.
ApiError
(
c
,
err
)
return
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