mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-04-30 13:31:46 +00:00
fix(image): add error handling for empty base64 string in image decoding
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
|||||||
} 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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user