Commit abd5de79 by 1808837298@qq.com

refactor: Make Channel Setting nullable and improve setting handling #836

parent 8fffa159
...@@ -35,7 +35,7 @@ type Channel struct { ...@@ -35,7 +35,7 @@ type Channel struct {
AutoBan *int `json:"auto_ban" gorm:"default:1"` AutoBan *int `json:"auto_ban" gorm:"default:1"`
OtherInfo string `json:"other_info"` OtherInfo string `json:"other_info"`
Tag *string `json:"tag" gorm:"index"` Tag *string `json:"tag" gorm:"index"`
Setting string `json:"setting" gorm:"type:text"` Setting *string `json:"setting" gorm:"type:text"`
} }
func (channel *Channel) GetModels() []string { func (channel *Channel) GetModels() []string {
...@@ -493,8 +493,8 @@ func SearchTags(keyword string, group string, model string, idSort bool) ([]*str ...@@ -493,8 +493,8 @@ func SearchTags(keyword string, group string, model string, idSort bool) ([]*str
func (channel *Channel) GetSetting() map[string]interface{} { func (channel *Channel) GetSetting() map[string]interface{} {
setting := make(map[string]interface{}) setting := make(map[string]interface{})
if channel.Setting != "" { if channel.Setting != nil && *channel.Setting != "" {
err := json.Unmarshal([]byte(channel.Setting), &setting) err := json.Unmarshal([]byte(*channel.Setting), &setting)
if err != nil { if err != nil {
common.SysError("failed to unmarshal setting: " + err.Error()) common.SysError("failed to unmarshal setting: " + err.Error())
} }
...@@ -508,7 +508,7 @@ func (channel *Channel) SetSetting(setting map[string]interface{}) { ...@@ -508,7 +508,7 @@ func (channel *Channel) SetSetting(setting map[string]interface{}) {
common.SysError("failed to marshal setting: " + err.Error()) common.SysError("failed to marshal setting: " + err.Error())
return return
} }
channel.Setting = string(settingBytes) channel.Setting = common.GetPointer[string](string(settingBytes))
} }
func GetChannelsByIds(ids []int) ([]*Channel, error) { func GetChannelsByIds(ids []int) ([]*Channel, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment