Based on QuantumNous/new-api v1.0.0-rc.36 (shallow history squashed). - CNY quota display mode: RMB-denominated top-up and crediting across Epay/Waffo channels - New CheckinButton in both authenticated and public headers (Turnstile supported) - New /subscribe page with public plan snapshot, Alipay/balance payment, auto group upgrade/reset - New /docs 12-section beginner guide with anchor navigation - New home PromoBanner linking to /docs; i18n synced (en/zh/zh-TW/fr/ja/ru/vi) - README: document custom features, live demo https://ai.88531.cn
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package setting
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"strconv"
|
|
"sync/atomic"
|
|
|
|
"github.com/QuantumNous/new-api/common"
|
|
)
|
|
|
|
const DefaultMaxTokenAutoGroups = 5
|
|
|
|
var autoGroups = []string{
|
|
"default",
|
|
}
|
|
|
|
var DefaultUseAutoGroup = false
|
|
|
|
var maxTokenAutoGroups atomic.Int64
|
|
|
|
func init() {
|
|
maxTokenAutoGroups.Store(DefaultMaxTokenAutoGroups)
|
|
}
|
|
|
|
func ContainsAutoGroup(group string) bool {
|
|
return slices.Contains(autoGroups, group)
|
|
}
|
|
|
|
func UpdateAutoGroupsByJsonString(jsonString string) error {
|
|
autoGroups = make([]string, 0)
|
|
return common.Unmarshal([]byte(jsonString), &autoGroups)
|
|
}
|
|
|
|
func AutoGroups2JsonString() string {
|
|
jsonBytes, err := common.Marshal(autoGroups)
|
|
if err != nil {
|
|
return "[]"
|
|
}
|
|
return string(jsonBytes)
|
|
}
|
|
|
|
func GetAutoGroups() []string {
|
|
return autoGroups
|
|
}
|
|
|
|
func GetMaxTokenAutoGroups() int {
|
|
return int(maxTokenAutoGroups.Load())
|
|
}
|
|
|
|
func ValidateMaxTokenAutoGroups(value string) error {
|
|
maxCount, err := strconv.Atoi(value)
|
|
if err != nil || maxCount <= 0 {
|
|
return fmt.Errorf("MaxTokenAutoGroups must be a positive integer")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func UpdateMaxTokenAutoGroups(value string) error {
|
|
if err := ValidateMaxTokenAutoGroups(value); err != nil {
|
|
return err
|
|
}
|
|
maxCount, _ := strconv.Atoi(value)
|
|
maxTokenAutoGroups.Store(int64(maxCount))
|
|
return nil
|
|
}
|