From e322ed4f054a836859134dc417d5402b01952447 Mon Sep 17 00:00:00 2001 From: CaIon Date: Sun, 27 Jul 2025 16:32:14 +0800 Subject: [PATCH] fix: ensure minimum quota display and handle zero values in render function --- relay/relay-text.go | 3 +++ web/src/helpers/render.js | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/relay/relay-text.go b/relay/relay-text.go index 84d4e38b..1856a2a1 100644 --- a/relay/relay-text.go +++ b/relay/relay-text.go @@ -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, "+ "tokenId %d, model %s, pre-consumed quota %d", relayInfo.UserId, relayInfo.ChannelId, relayInfo.TokenId, modelName, preConsumedQuota)) } else { + if !ratio.IsZero() && quota == 0 { + quota = 1 + } model.UpdateUserUsedQuotaAndRequestCount(relayInfo.UserId, quota) model.UpdateChannelUsedQuota(relayInfo.ChannelId, quota) } diff --git a/web/src/helpers/render.js b/web/src/helpers/render.js index bd0a8131..1178d5f9 100644 --- a/web/src/helpers/render.js +++ b/web/src/helpers/render.js @@ -883,12 +883,22 @@ export function renderQuotaWithAmount(amount) { } export function renderQuota(quota, digits = 2) { + let quotaPerUnit = localStorage.getItem('quota_per_unit'); let displayInCurrency = localStorage.getItem('display_in_currency'); quotaPerUnit = parseFloat(quotaPerUnit); displayInCurrency = displayInCurrency === 'true'; 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); }