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
7e1ad4bd
authored
Dec 24, 2025
by
Seefs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 支持小写bearer和Bearer后带多个空格 && 修复 WSS预扣费错误提取key的问题
parent
8ee5c23b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
middleware/auth.go
+6
-2
service/quota.go
+1
-1
No files found.
middleware/auth.go
View file @
7e1ad4bd
...
@@ -218,10 +218,14 @@ func TokenAuth() func(c *gin.Context) {
...
@@ -218,10 +218,14 @@ func TokenAuth() func(c *gin.Context) {
}
}
key
:=
c
.
Request
.
Header
.
Get
(
"Authorization"
)
key
:=
c
.
Request
.
Header
.
Get
(
"Authorization"
)
parts
:=
make
([]
string
,
0
)
parts
:=
make
([]
string
,
0
)
key
=
strings
.
TrimPrefix
(
key
,
"Bearer "
)
if
strings
.
HasPrefix
(
key
,
"Bearer "
)
||
strings
.
HasPrefix
(
key
,
"bearer "
)
{
key
=
strings
.
TrimSpace
(
key
[
7
:
])
}
if
key
==
""
||
key
==
"midjourney-proxy"
{
if
key
==
""
||
key
==
"midjourney-proxy"
{
key
=
c
.
Request
.
Header
.
Get
(
"mj-api-secret"
)
key
=
c
.
Request
.
Header
.
Get
(
"mj-api-secret"
)
key
=
strings
.
TrimPrefix
(
key
,
"Bearer "
)
if
strings
.
HasPrefix
(
key
,
"Bearer "
)
||
strings
.
HasPrefix
(
key
,
"bearer "
)
{
key
=
strings
.
TrimSpace
(
key
[
7
:
])
}
key
=
strings
.
TrimPrefix
(
key
,
"sk-"
)
key
=
strings
.
TrimPrefix
(
key
,
"sk-"
)
parts
=
strings
.
Split
(
key
,
"-"
)
parts
=
strings
.
Split
(
key
,
"-"
)
key
=
parts
[
0
]
key
=
parts
[
0
]
...
...
service/quota.go
View file @
7e1ad4bd
...
@@ -95,7 +95,7 @@ func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usag
...
@@ -95,7 +95,7 @@ func PreWssConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo, usag
return
err
return
err
}
}
token
,
err
:=
model
.
GetTokenByKey
(
strings
.
Trim
Left
(
relayInfo
.
TokenKey
,
"sk-"
),
false
)
token
,
err
:=
model
.
GetTokenByKey
(
strings
.
Trim
Prefix
(
relayInfo
.
TokenKey
,
"sk-"
),
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
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