diff --git a/entity/entity.go b/entity/entity.go index acd23eb..0f57d9a 100644 --- a/entity/entity.go +++ b/entity/entity.go @@ -1,5 +1,10 @@ package entity +import ( + "regexp" + "strings" +) + // Event represents the type of event for the channel. type Event = string @@ -20,6 +25,11 @@ type ChannelConfig struct { CreatedAt int64 `json:"created_at"` } +func (c *ChannelConfig) Sanitize() { + c.Username = regexp.MustCompile(`[^a-zA-Z0-9_-]`).ReplaceAllString(c.Username, "") + c.Username = strings.TrimSpace(c.Username) +} + // ChannelInfo represents the information about a channel, // mostly used for the template rendering. type ChannelInfo struct { diff --git a/manager/manager.go b/manager/manager.go index d675c33..bb9659d 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -88,6 +88,7 @@ func (m *Manager) LoadConfig() error { // CreateChannel starts monitoring an M3U8 stream func (m *Manager) CreateChannel(conf *entity.ChannelConfig, shouldSave bool) error { + conf.Sanitize() ch := channel.New(conf) // prevent duplicate channels