Fix channel model length issue
Fixes #691 --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Calcium-Ion/new-api/issues/691?shareId=XXXX-XXXX-XXXX-XXXX).
This commit is contained in:
@@ -274,6 +274,17 @@ func AddChannel(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
localChannel := channel
|
localChannel := channel
|
||||||
localChannel.Key = key
|
localChannel.Key = key
|
||||||
|
// Validate the length of the model name
|
||||||
|
models := strings.Split(localChannel.Models, ",")
|
||||||
|
for _, model := range models {
|
||||||
|
if len(model) > 256 {
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": fmt.Sprintf("模型名称过长: %s", model),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
channels = append(channels, localChannel)
|
channels = append(channels, localChannel)
|
||||||
}
|
}
|
||||||
err = model.BatchInsertChannels(channels)
|
err = model.BatchInsertChannels(channels)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
type Ability struct {
|
type Ability struct {
|
||||||
Group string `json:"group" gorm:"type:varchar(64);primaryKey;autoIncrement:false"`
|
Group string `json:"group" gorm:"type:varchar(64);primaryKey;autoIncrement:false"`
|
||||||
Model string `json:"model" gorm:"type:varchar(64);primaryKey;autoIncrement:false"`
|
Model string `json:"model" gorm:"type:varchar(256);primaryKey;autoIncrement:false"`
|
||||||
ChannelId int `json:"channel_id" gorm:"primaryKey;autoIncrement:false;index"`
|
ChannelId int `json:"channel_id" gorm:"primaryKey;autoIncrement:false;index"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Priority *int64 `json:"priority" gorm:"bigint;default:0;index"`
|
Priority *int64 `json:"priority" gorm:"bigint;default:0;index"`
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ func CacheGetRandomSatisfiedChannel(group string, model string, retry int) (*Cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if memory cache is disabled, get channel directly from database
|
// if memory cache is disabled, get channel directly from database
|
||||||
if !common.MemoryCacheEnabled {
|
if (!common.MemoryCacheEnabled) {
|
||||||
return GetRandomSatisfiedChannel(group, model, retry)
|
return GetRandomSatisfiedChannel(group, model, retry)
|
||||||
}
|
}
|
||||||
channelSyncLock.RLock()
|
channelSyncLock.RLock()
|
||||||
|
|||||||
Reference in New Issue
Block a user