feat: publish sanitized custom.97 source

This commit is contained in:
cneicy committed 2026-10-27 20:43:39 +08:00
1 parent 8e6ed0317b
commit 86c0276156
1022 files changed
+69903 -19207

No files matched your search

+6 -7
View File
@@ -3,7 +3,6 @@ package model
import (
"context"
"errors"
"fmt"
"github.com/QuantumNous/new-api/common"
"gorm.io/gorm"
@@ -164,7 +163,7 @@ func reserveTokenQuotaDB(id int, quota int) (bool, error) {
// Redis 异常或水合失败时降级为数据库条件更新,保证服务可用。
func TryReserveUserQuota(id int, quota int) (bool, error) {
if quota < 0 {
return false, errors.New("quota 不能为负数!")
return false, errors.New("quota cannot be negative")
}
if quota == 0 {
return true, nil
@@ -181,7 +180,7 @@ func TryReserveUserQuota(id int, quota int) (bool, error) {
}
if err != nil || result == cacheQuotaMiss {
if err != nil {
common.SysLog("user quota cache reserve unavailable, falling back to database: " + err.Error())
common.SysLog(common.LogText("user quota cache reserve unavailable, falling back to database: %s", err.Error()))
}
return reserveUserQuotaDB(id, quota)
}
@@ -191,7 +190,7 @@ func TryReserveUserQuota(id int, quota int) (bool, error) {
if err = persistUserQuotaDelta(id, -quota); err != nil {
compensated, compensateErr := cacheApplyUserQuotaDelta(id, int64(quota))
if compensateErr != nil || compensated != cacheQuotaOK {
common.SysError(fmt.Sprintf("failed to compensate reserved user quota: result=%d error=%v", compensated, compensateErr))
common.SysError(common.LogText("failed to compensate reserved user quota: result=%d error=%v", compensated, compensateErr))
}
return false, err
}
@@ -202,7 +201,7 @@ func TryReserveUserQuota(id int, quota int) (bool, error) {
// tokens skip the balance check but still update remain/used accounting.
func TryReserveTokenQuota(id int, key string, quota int, unlimited bool) (bool, error) {
if quota < 0 {
return false, errors.New("quota 不能为负数!")
return false, errors.New("quota cannot be negative")
}
if quota == 0 {
return true, nil
@@ -222,7 +221,7 @@ func TryReserveTokenQuota(id int, key string, quota int, unlimited bool) (bool,
}
if err != nil || result == cacheQuotaMiss {
if err != nil {
common.SysLog("token quota cache reserve unavailable, falling back to database: " + err.Error())
common.SysLog(common.LogText("token quota cache reserve unavailable, falling back to database: %s", err.Error()))
}
return reserveTokenQuotaDB(id, quota)
}
@@ -232,7 +231,7 @@ func TryReserveTokenQuota(id int, key string, quota int, unlimited bool) (bool,
if err = persistTokenQuotaDelta(id, -quota); err != nil {
compensated, compensateErr := cacheApplyTokenQuotaDelta(id, key, int64(quota))
if compensateErr != nil || compensated != cacheQuotaOK {
common.SysError(fmt.Sprintf("failed to compensate reserved token quota: result=%d error=%v", compensated, compensateErr))
common.SysError(common.LogText("failed to compensate reserved token quota: result=%d error=%v", compensated, compensateErr))
}
return false, err
}