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
08442b7b
authored
Sep 27, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 防止渠道地址传到用户端
parent
b01e567c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
controller/relay-utils.go
+11
-4
No files found.
controller/relay-utils.go
View file @
08442b7b
...
...
@@ -8,6 +8,7 @@ import (
"io"
"net/http"
"one-api/common"
"regexp"
"strconv"
)
...
...
@@ -106,12 +107,18 @@ func countTokenText(text string, model string) int {
}
func
errorWrapper
(
err
error
,
code
string
,
statusCode
int
)
*
OpenAIErrorWithStatusCode
{
if
statusCode
==
http
.
StatusInternalServerError
{
//避免暴露内部错误
err
=
fmt
.
Errorf
(
"internal server error"
)
text
:=
err
.
Error
()
// 定义一个正则表达式匹配URL
urlPattern
:=
`http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+`
urlRegexp
,
reErr
:=
regexp
.
Compile
(
urlPattern
)
if
reErr
==
nil
{
text
=
urlRegexp
.
ReplaceAllString
(
text
,
"https://api.openai.com"
)
}
//避免暴露内部错误
openAIError
:=
OpenAIError
{
Message
:
err
.
Error
()
,
Message
:
text
,
Type
:
"one_api_error"
,
Code
:
code
,
}
...
...
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