feat: publish v1.0.0-rc.36-custom.1
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
This commit is contained in:
commit
bb7968b612
2381 files changed
+551494
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"github.com/QuantumNous/new-api/common"
|
||||
"github.com/QuantumNous/new-api/setting/ratio_setting"
|
||||
)
|
||||
|
||||
func IsChannelEnabledForGroupModel(group string, modelName string, channelID int) bool {
|
||||
if group == "" || modelName == "" || channelID <= 0 {
|
||||
return false
|
||||
}
|
||||
if !common.MemoryCacheEnabled {
|
||||
return isChannelEnabledForGroupModelDB(group, modelName, channelID)
|
||||
}
|
||||
|
||||
channelSyncLock.RLock()
|
||||
defer channelSyncLock.RUnlock()
|
||||
|
||||
if group2model2channels == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if isChannelIDInList(group2model2channels[group][modelName], channelID) {
|
||||
return true
|
||||
}
|
||||
normalized := ratio_setting.RoutingMatchModelName(modelName)
|
||||
if normalized != "" && normalized != modelName {
|
||||
return isChannelIDInList(group2model2channels[group][normalized], channelID)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsChannelEnabledForAnyGroupModel(groups []string, modelName string, channelID int) bool {
|
||||
if len(groups) == 0 {
|
||||
return false
|
||||
}
|
||||
for _, g := range groups {
|
||||
if IsChannelEnabledForGroupModel(g, modelName, channelID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isChannelEnabledForGroupModelDB(group string, modelName string, channelID int) bool {
|
||||
var count int64
|
||||
err := DB.Model(&Ability{}).
|
||||
Where(commonGroupCol+" = ? and model = ? and channel_id = ? and enabled = ?", group, modelName, channelID, true).
|
||||
Count(&count).Error
|
||||
if err == nil && count > 0 {
|
||||
return true
|
||||
}
|
||||
normalized := ratio_setting.RoutingMatchModelName(modelName)
|
||||
if normalized == "" || normalized == modelName {
|
||||
return false
|
||||
}
|
||||
count = 0
|
||||
err = DB.Model(&Ability{}).
|
||||
Where(commonGroupCol+" = ? and model = ? and channel_id = ? and enabled = ?", group, normalized, channelID, true).
|
||||
Count(&count).Error
|
||||
return err == nil && count > 0
|
||||
}
|
||||
|
||||
func isChannelIDInList(list []int, channelID int) bool {
|
||||
return slices.Contains(list, channelID)
|
||||
}
|
||||
Reference in new issue
Block a user