feat(channel): enhance channel handling with multi-key support

This commit is contained in:
CaIon
2025-06-16 02:30:46 +08:00
parent 617c8e8f4f
commit 7403df7e9c
4 changed files with 115 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
package model
import (
"database/sql/driver"
"encoding/json"
"one-api/common"
"strings"
@@ -9,11 +10,6 @@ import (
"gorm.io/gorm"
)
type ChannelInfo struct {
MultiKeyMode bool `json:"multi_key_mode"` // 是否多Key模式
MultiKeyStatusList map[int]int `json:"multi_key_status_list"` // key状态列表key index -> status
}
type Channel struct {
Id int `json:"id"`
Type int `json:"type" gorm:"default:0"`
@@ -46,6 +42,23 @@ type Channel struct {
ChannelInfo ChannelInfo `json:"channel_info" gorm:"type:json"`
}
type ChannelInfo struct {
MultiKeyMode bool `json:"multi_key_mode"` // 是否多Key模式
MultiKeyStatusList map[int]int `json:"multi_key_status_list"` // key状态列表key index -> status
MultiKeySize int `json:"multi_key_size"` // 多Key模式下的key数量
}
// Value implements driver.Valuer interface
func (c ChannelInfo) Value() (driver.Value, error) {
return json.Marshal(c)
}
// Scan implements sql.Scanner interface
func (c *ChannelInfo) Scan(value interface{}) error {
bytesValue, _ := value.([]byte)
return json.Unmarshal(bytesValue, c)
}
func (channel *Channel) GetModels() []string {
if channel.Models == "" {
return []string{}