feat: sync deployed v1.0.0-rc.38-custom.42
Sync production source including routing, billing, Astra detection and public uptime. Update custom build instructions and license packaging.
This commit is contained in:
1 parent
aa6c3f50f4
commit
ceddfd3d6b
828 files changed
+122253
-13702
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/QuantumNous/new-api/logger"
|
||||
"github.com/QuantumNous/new-api/model"
|
||||
relaycommon "github.com/QuantumNous/new-api/relay/common"
|
||||
"github.com/QuantumNous/new-api/relaykit/dto"
|
||||
"github.com/QuantumNous/new-api/relaykit/types"
|
||||
|
||||
"github.com/bytedance/gopkg/util/gopool"
|
||||
@@ -154,7 +155,12 @@ func (s *BillingSession) Reserve(targetQuota int) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if s.settled || s.refunded || s.trusted || targetQuota <= s.preConsumedQuota {
|
||||
imageRequest := false
|
||||
if s.relayInfo != nil {
|
||||
_, imageRequest = s.relayInfo.Request.(*dto.ImageRequest)
|
||||
imageRequest = imageRequest || s.relayInfo.ImageRequestCount > 0
|
||||
}
|
||||
if s.settled || s.refunded || s.trusted && !imageRequest || targetQuota <= s.preConsumedQuota {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -163,7 +169,7 @@ func (s *BillingSession) Reserve(targetQuota int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := s.reserveFunding(delta); err != nil {
|
||||
if err := s.reserveFunding(delta, imageRequest); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.reserveToken(delta); err != nil {
|
||||
@@ -174,6 +180,9 @@ func (s *BillingSession) Reserve(targetQuota int) error {
|
||||
s.preConsumedQuota += delta
|
||||
s.tokenConsumed += delta
|
||||
s.extraReserved += delta
|
||||
if imageRequest {
|
||||
s.trusted = false
|
||||
}
|
||||
s.syncRelayInfo()
|
||||
return nil
|
||||
}
|
||||
@@ -240,9 +249,20 @@ func (s *BillingSession) preConsume(c *gin.Context, quota int) *types.NewAPIErro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *BillingSession) reserveFunding(delta int) error {
|
||||
func (s *BillingSession) reserveFunding(delta int, requireAvailableQuota bool) error {
|
||||
switch funding := s.funding.(type) {
|
||||
case *WalletFunding:
|
||||
if requireAvailableQuota {
|
||||
// Image quantity is known before submission, including retries and
|
||||
// overrides. Reserve atomically instead of admitting wallet debt.
|
||||
if err := funding.PreConsume(delta); err != nil {
|
||||
if errors.Is(err, ErrInsufficientWalletQuota) {
|
||||
return types.NewErrorWithStatusCode(err, types.ErrorCodeInsufficientUserQuota, http.StatusForbidden, types.ErrOptionWithSkipRetry(), types.ErrOptionWithNoRecordErrorLog())
|
||||
}
|
||||
return types.NewError(err, types.ErrorCodeUpdateDataError, types.ErrOptionWithSkipRetry())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// 与结算补扣(SettleBilling 正差额 → WalletFunding.Settle)语义一致:
|
||||
// 全额无条件扣减,余额不足的部分记为欠费(余额可为负),不中断请求,
|
||||
// 保证日志记录的预扣额度与用户余额的实际变动始终对账一致。
|
||||
|
||||
Reference in new issue
Block a user