Skip to content

Commit

Permalink
Merge pull request #692 from Calcium-Ion/fix-channel-model-length
Browse files Browse the repository at this point in the history
Fix channel model length issue
  • Loading branch information
Calcium-Ion authored Jan 5, 2025
2 parents 055a238 + 08a89a5 commit 3f8c12c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 11 additions & 0 deletions controller/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ func AddChannel(c *gin.Context) {
}
localChannel := channel
localChannel.Key = key
// Validate the length of the model name
models := strings.Split(localChannel.Models, ",")
for _, model := range models {
if len(model) > 255 {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": fmt.Sprintf("模型名称过长: %s", model),
})
return
}
}
channels = append(channels, localChannel)
}
err = model.BatchInsertChannels(channels)
Expand Down
3 changes: 1 addition & 2 deletions model/ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type Ability struct {
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(255);primaryKey;autoIncrement:false"`
ChannelId int `json:"channel_id" gorm:"primaryKey;autoIncrement:false;index"`
Enabled bool `json:"enabled"`
Priority *int64 `json:"priority" gorm:"bigint;default:0;index"`
Expand Down Expand Up @@ -278,7 +278,6 @@ func FixAbility() (int, error) {
return 0, err
}
var channels []Channel

if len(abilityChannelIds) == 0 {
err = DB.Find(&channels).Error
} else {
Expand Down

0 comments on commit 3f8c12c

Please sign in to comment.