Fixed #125, sanitize Username with [^a-zA-Z0-9_-] and remove whitespace

This commit is contained in:
Yami Odymel 2025-06-18 23:27:39 +08:00
parent 65397fb3a1
commit 8b55209273
No known key found for this signature in database
GPG Key ID: 68E469836934DB36
2 changed files with 11 additions and 0 deletions

View File

@ -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 {

View File

@ -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