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
@@ -275,6 +275,67 @@ func updateChannelSiliconFlowBalance(channel *model.Channel) (float64, error) {
|
||||
return balance, nil
|
||||
}
|
||||
|
||||
func getDeepSeekBalanceUSD(response DeepSeekUsageResponse, usdExchangeRate float64) (float64, error) {
|
||||
var usdBalance *string
|
||||
var cnyBalance *string
|
||||
|
||||
for i := range response.BalanceInfos {
|
||||
balanceInfo := &response.BalanceInfos[i]
|
||||
switch balanceInfo.Currency {
|
||||
case "USD":
|
||||
if usdBalance == nil {
|
||||
usdBalance = &balanceInfo.TotalBalance
|
||||
}
|
||||
case "CNY":
|
||||
if cnyBalance == nil {
|
||||
cnyBalance = &balanceInfo.TotalBalance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if usdBalance != nil {
|
||||
balance, err := strconv.ParseFloat(*usdBalance, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if math.IsNaN(balance) || math.IsInf(balance, 0) {
|
||||
return 0, errors.New("USD balance must be finite")
|
||||
}
|
||||
if balance < 0 {
|
||||
return 0, errors.New("USD balance must be non-negative")
|
||||
}
|
||||
return balance, nil
|
||||
}
|
||||
if cnyBalance == nil {
|
||||
return 0, errors.New("currency USD or CNY not found")
|
||||
}
|
||||
if math.IsNaN(usdExchangeRate) || math.IsInf(usdExchangeRate, 0) {
|
||||
return 0, errors.New("USD exchange rate must be finite")
|
||||
}
|
||||
if usdExchangeRate <= 0 {
|
||||
return 0, errors.New("USD exchange rate must be greater than zero")
|
||||
}
|
||||
|
||||
balanceCNY, err := strconv.ParseFloat(*cnyBalance, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if math.IsNaN(balanceCNY) || math.IsInf(balanceCNY, 0) {
|
||||
return 0, errors.New("CNY balance must be finite")
|
||||
}
|
||||
if balanceCNY < 0 {
|
||||
return 0, errors.New("CNY balance must be non-negative")
|
||||
}
|
||||
balanceUSD := decimal.NewFromFloat(balanceCNY).Div(decimal.NewFromFloat(usdExchangeRate)).InexactFloat64()
|
||||
if math.IsNaN(balanceUSD) || math.IsInf(balanceUSD, 0) {
|
||||
return 0, errors.New("converted USD balance must be finite")
|
||||
}
|
||||
if balanceUSD < 0 {
|
||||
return 0, errors.New("converted USD balance must be non-negative")
|
||||
}
|
||||
return balanceUSD, nil
|
||||
}
|
||||
|
||||
func updateChannelDeepSeekBalance(channel *model.Channel) (float64, error) {
|
||||
url := "https://api.deepseek.com/user/balance"
|
||||
body, err := GetResponseBody("GET", url, channel, GetAuthHeader(channel.Key))
|
||||
@@ -286,17 +347,7 @@ func updateChannelDeepSeekBalance(channel *model.Channel) (float64, error) {
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
index := -1
|
||||
for i, balanceInfo := range response.BalanceInfos {
|
||||
if balanceInfo.Currency == "CNY" {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if index == -1 {
|
||||
return 0, errors.New("currency CNY not found")
|
||||
}
|
||||
balance, err := strconv.ParseFloat(response.BalanceInfos[index].TotalBalance, 64)
|
||||
balance, err := getDeepSeekBalanceUSD(response, operation_setting.USDExchangeRate)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user