| | package service |
| |
|
| | import ( |
| | "strings" |
| |
|
| | "github.com/QuantumNous/new-api/setting" |
| | "github.com/QuantumNous/new-api/setting/ratio_setting" |
| | ) |
| |
|
| | func GetUserUsableGroups(userGroup string) map[string]string { |
| | groupsCopy := setting.GetUserUsableGroupsCopy() |
| | if userGroup != "" { |
| | specialSettings, b := ratio_setting.GetGroupRatioSetting().GroupSpecialUsableGroup.Get(userGroup) |
| | if b { |
| | |
| | for specialGroup, desc := range specialSettings { |
| | if strings.HasPrefix(specialGroup, "-:") { |
| | |
| | groupToRemove := strings.TrimPrefix(specialGroup, "-:") |
| | delete(groupsCopy, groupToRemove) |
| | } else if strings.HasPrefix(specialGroup, "+:") { |
| | |
| | groupToAdd := strings.TrimPrefix(specialGroup, "+:") |
| | groupsCopy[groupToAdd] = desc |
| | } else { |
| | |
| | groupsCopy[specialGroup] = desc |
| | } |
| | } |
| | } |
| | |
| | if _, ok := groupsCopy[userGroup]; !ok { |
| | groupsCopy[userGroup] = "用户分组" |
| | } |
| | } |
| | return groupsCopy |
| | } |
| |
|
| | func GroupInUserUsableGroups(userGroup, groupName string) bool { |
| | _, ok := GetUserUsableGroups(userGroup)[groupName] |
| | return ok |
| | } |
| |
|
| | |
| | func GetUserAutoGroup(userGroup string) []string { |
| | groups := GetUserUsableGroups(userGroup) |
| | autoGroups := make([]string, 0) |
| | for _, group := range setting.GetAutoGroups() { |
| | if _, ok := groups[group]; ok { |
| | autoGroups = append(autoGroups, group) |
| | } |
| | } |
| | return autoGroups |
| | } |
| |
|
| | |
| | |
| | |
| | func GetUserGroupRatio(userGroup, group string) float64 { |
| | ratio, ok := ratio_setting.GetGroupGroupRatio(userGroup, group) |
| | if ok { |
| | return ratio |
| | } |
| | return ratio_setting.GetGroupRatio(group) |
| | } |
| |
|