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
c0d85e2d
authored
May 15, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: enhance image decoding logic to handle base64 file types and improve error handling
parent
f88b7cd7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
2 deletions
+8
-2
service/token_counter.go
+8
-2
No files found.
service/token_counter.go
View file @
c0d85e2d
...
...
@@ -120,11 +120,12 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
var
config
image
.
Config
var
err
error
var
format
string
var
b64str
string
if
strings
.
HasPrefix
(
imageUrl
.
Url
,
"http"
)
{
config
,
format
,
err
=
DecodeUrlImageData
(
imageUrl
.
Url
)
}
else
{
common
.
SysLog
(
fmt
.
Sprintf
(
"decoding image"
))
config
,
format
,
_
,
err
=
DecodeBase64ImageData
(
imageUrl
.
Url
)
config
,
format
,
b64str
,
err
=
DecodeBase64ImageData
(
imageUrl
.
Url
)
}
if
err
!=
nil
{
return
0
,
err
...
...
@@ -132,7 +133,12 @@ func getImageToken(info *relaycommon.RelayInfo, imageUrl *dto.MessageImageUrl, m
imageUrl
.
MimeType
=
format
if
config
.
Width
==
0
||
config
.
Height
==
0
{
return
0
,
errors
.
New
(
fmt
.
Sprintf
(
"fail to decode image config: %s"
,
imageUrl
.
Url
))
// not an image
if
format
!=
""
&&
b64str
!=
""
{
// file type
return
3
*
baseTokens
,
nil
}
return
0
,
errors
.
New
(
fmt
.
Sprintf
(
"fail to decode base64 config: %s"
,
imageUrl
.
Url
))
}
shortSide
:=
config
.
Width
...
...
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