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
d92c9db6
authored
Aug 27, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(image): add error handling for empty base64 string in image decoding
parent
3401abe4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
2 deletions
+6
-2
service/image.go
+4
-0
service/token_counter.go
+2
-2
No files found.
service/image.go
View file @
d92c9db6
...
@@ -21,6 +21,10 @@ func DecodeBase64ImageData(base64String string) (image.Config, string, string, e
...
@@ -21,6 +21,10 @@ func DecodeBase64ImageData(base64String string) (image.Config, string, string, e
base64String
=
base64String
[
idx
+
1
:
]
base64String
=
base64String
[
idx
+
1
:
]
}
}
if
len
(
base64String
)
==
0
{
return
image
.
Config
{},
""
,
""
,
errors
.
New
(
"base64 string is empty"
)
}
// 将base64字符串解码为字节切片
// 将base64字符串解码为字节切片
decodedData
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
base64String
)
decodedData
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
base64String
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
service/token_counter.go
View file @
d92c9db6
...
@@ -301,7 +301,7 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
...
@@ -301,7 +301,7 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
}
}
}
}
for
_
,
file
:=
range
meta
.
Files
{
for
i
,
file
:=
range
meta
.
Files
{
switch
file
.
FileType
{
switch
file
.
FileType
{
case
types
.
FileTypeImage
:
case
types
.
FileTypeImage
:
if
info
.
RelayFormat
==
types
.
RelayFormatGemini
{
if
info
.
RelayFormat
==
types
.
RelayFormatGemini
{
...
@@ -309,7 +309,7 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
...
@@ -309,7 +309,7 @@ func CountRequestToken(c *gin.Context, meta *types.TokenCountMeta, info *relayco
}
else
{
}
else
{
token
,
err
:=
getImageToken
(
file
,
model
,
info
.
IsStream
)
token
,
err
:=
getImageToken
(
file
,
model
,
info
.
IsStream
)
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"error counting image token
: %v"
,
err
)
return
0
,
fmt
.
Errorf
(
"error counting image token
, media index[%d], original data[%s], err: %v"
,
i
,
file
.
OriginData
,
err
)
}
}
tkm
+=
token
tkm
+=
token
}
}
...
...
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