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
1c5ba67e
authored
Jul 27, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: ensure minimum quota display and handle zero values in render function
parent
84fb6eea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletions
+14
-1
relay/relay-text.go
+3
-0
web/src/helpers/render.js
+11
-1
No files found.
relay/relay-text.go
View file @
1c5ba67e
...
@@ -517,6 +517,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
...
@@ -517,6 +517,9 @@ func postConsumeQuota(ctx *gin.Context, relayInfo *relaycommon.RelayInfo,
common
.
LogError
(
ctx
,
fmt
.
Sprintf
(
"total tokens is 0, cannot consume quota, userId %d, channelId %d, "
+
common
.
LogError
(
ctx
,
fmt
.
Sprintf
(
"total tokens is 0, cannot consume quota, userId %d, channelId %d, "
+
"tokenId %d, model %s, pre-consumed quota %d"
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
relayInfo
.
TokenId
,
modelName
,
preConsumedQuota
))
"tokenId %d, model %s, pre-consumed quota %d"
,
relayInfo
.
UserId
,
relayInfo
.
ChannelId
,
relayInfo
.
TokenId
,
modelName
,
preConsumedQuota
))
}
else
{
}
else
{
if
!
ratio
.
IsZero
()
&&
quota
==
0
{
quota
=
1
}
model
.
UpdateUserUsedQuotaAndRequestCount
(
relayInfo
.
UserId
,
quota
)
model
.
UpdateUserUsedQuotaAndRequestCount
(
relayInfo
.
UserId
,
quota
)
model
.
UpdateChannelUsedQuota
(
relayInfo
.
ChannelId
,
quota
)
model
.
UpdateChannelUsedQuota
(
relayInfo
.
ChannelId
,
quota
)
}
}
...
...
web/src/helpers/render.js
View file @
1c5ba67e
...
@@ -883,12 +883,22 @@ export function renderQuotaWithAmount(amount) {
...
@@ -883,12 +883,22 @@ export function renderQuotaWithAmount(amount) {
}
}
export
function
renderQuota
(
quota
,
digits
=
2
)
{
export
function
renderQuota
(
quota
,
digits
=
2
)
{
let
quotaPerUnit
=
localStorage
.
getItem
(
'quota_per_unit'
);
let
quotaPerUnit
=
localStorage
.
getItem
(
'quota_per_unit'
);
let
displayInCurrency
=
localStorage
.
getItem
(
'display_in_currency'
);
let
displayInCurrency
=
localStorage
.
getItem
(
'display_in_currency'
);
quotaPerUnit
=
parseFloat
(
quotaPerUnit
);
quotaPerUnit
=
parseFloat
(
quotaPerUnit
);
displayInCurrency
=
displayInCurrency
===
'true'
;
displayInCurrency
=
displayInCurrency
===
'true'
;
if
(
displayInCurrency
)
{
if
(
displayInCurrency
)
{
return
'$'
+
(
quota
/
quotaPerUnit
).
toFixed
(
digits
);
const
result
=
quota
/
quotaPerUnit
;
const
fixedResult
=
result
.
toFixed
(
digits
);
// 如果 toFixed 后结果为 0 但原始值不为 0,显示最小值
if
(
parseFloat
(
fixedResult
)
===
0
&&
quota
>
0
&&
result
>
0
)
{
const
minValue
=
Math
.
pow
(
10
,
-
digits
);
return
'$'
+
minValue
.
toFixed
(
digits
);
}
return
'$'
+
fixedResult
;
}
}
return
renderNumber
(
quota
);
return
renderNumber
(
quota
);
}
}
...
...
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