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:
cneicy committed 2026-09-26 04:49:11 +08:00
1 parent aa6c3f50f4
commit ceddfd3d6b
828 files changed
+122253 -13702

No files matched your search

+33 -5
View File
@@ -59,6 +59,8 @@ type Channel struct {
Keys []string `json:"-" gorm:"-"`
}
const ChannelStatusReasonAllKeysDisabled = "All keys are disabled"
type ChannelInfo struct {
IsMultiKey bool `json:"is_multi_key"` // 是否多Key模式
MultiKeySize int `json:"multi_key_size"` // 多Key模式下的Key数量
@@ -711,7 +713,7 @@ func handlerMultiKeyUpdate(channel *Channel, usingKey string, status int, reason
if !hasEnabledMultiKey(keys, channel.ChannelInfo.MultiKeyStatusList) {
channel.Status = common.ChannelStatusAutoDisabled
info := channel.GetOtherInfo()
info["status_reason"] = "All keys are disabled"
info["status_reason"] = ChannelStatusReasonAllKeysDisabled
info["status_time"] = common.GetTimestamp()
channel.SetOtherInfo(info)
} else if status == common.ChannelStatusEnabled {
@@ -782,7 +784,12 @@ func UpdateChannelStatus(channelId int, usingKey string, status int, reason stri
if err != nil {
return false
} else {
if channel.Status == status {
// A manual channel operation must replace the exhaustion reason even
// when the status value is already manually disabled.
overridesKeyExhaustion := channel.ChannelInfo.IsMultiKey && usingKey == "" &&
status == common.ChannelStatusManuallyDisabled && reason != ChannelStatusReasonAllKeysDisabled &&
channel.GetOtherInfo()["status_reason"] == ChannelStatusReasonAllKeysDisabled
if channel.Status == status && !overridesKeyExhaustion {
return false
}
@@ -819,6 +826,19 @@ func EnableChannelByTag(tag string) error {
}
func DisableChannelByTag(tag string) error {
// Explicit tag-level disable also cancels automatic restoration for
// channels that were already disabled because all keys were unavailable.
var channels []Channel
if err := DB.Where("tag = ?", tag).Find(&channels).Error; err != nil {
return err
}
for _, channel := range channels {
if channel.ChannelInfo.IsMultiKey && channel.GetOtherInfo()["status_reason"] == ChannelStatusReasonAllKeysDisabled {
if !UpdateChannelStatus(channel.Id, "", common.ChannelStatusManuallyDisabled, "manual tag operation") {
return fmt.Errorf("failed to disable channel #%d by tag", channel.Id)
}
}
}
err := DB.Model(&Channel{}).Where("tag = ?", tag).Update("status", common.ChannelStatusManuallyDisabled).Error
if err != nil {
return err
@@ -992,7 +1012,10 @@ func (channel *Channel) ValidateSettings() error {
if err := channelOtherSettings.ValidateToolLossPolicy(); err != nil {
return err
}
if channel.Type == constant.ChannelTypeAdvancedCustom {
if preset := common.GetAdvancedCustomPreset(channel.Type); preset != nil {
channelOtherSettings.AdvancedCustom = preset
}
if constant.IsAdvancedCustomChannel(channel.Type) {
if channelOtherSettings.AdvancedCustom == nil {
return fmt.Errorf("advanced_custom is required")
}
@@ -1002,7 +1025,7 @@ func (channel *Channel) ValidateSettings() error {
return err
}
}
if channel.Type == constant.ChannelTypeAdvancedCustom && channelOtherSettings.UpstreamModelUpdateCheckEnabled {
if constant.IsAdvancedCustomChannel(channel.Type) && channelOtherSettings.UpstreamModelUpdateCheckEnabled {
if _, ok := channelOtherSettings.AdvancedCustom.ModelListRoute(); !ok {
return fmt.Errorf("advanced custom channels require a %s route when upstream model update checks are enabled", dto.AdvancedCustomModelListPath)
}
@@ -1011,7 +1034,9 @@ func (channel *Channel) ValidateSettings() error {
}
func (channel *Channel) GetSetting() dto.ChannelSettings {
setting := dto.ChannelSettings{}
// Model validation is enabled by default; an explicit false in the JSON
// remains the per-channel opt-out.
setting := dto.ChannelSettings{ResponsesAstraModelGuard: common.GetPointer(true)}
if channel.Setting != nil && *channel.Setting != "" {
err := common.Unmarshal([]byte(*channel.Setting), &setting)
if err != nil {
@@ -1042,6 +1067,9 @@ func (channel *Channel) GetOtherSettings() dto.ChannelOtherSettings {
_ = channel.Save() // 保存修改
}
}
if preset := common.GetAdvancedCustomPreset(channel.Type); preset != nil {
setting.AdvancedCustom = preset
}
return setting
}