Make stream keys objects with comment instead of string slice

This commit is contained in:
Gabe Kangas
2022-11-23 16:39:55 -08:00
parent c9e3ccad45
commit c4dc802941
8 changed files with 46 additions and 19 deletions

View File

@@ -946,12 +946,22 @@ func GetCustomColorVariableValues() map[string]string {
}
// GetStreamKeys will return valid stream keys.
func GetStreamKeys() []string {
keys, _ := _datastore.GetStringSlice(streamKeysKey)
return keys
func GetStreamKeys() []models.StreamKey {
configEntry, err := _datastore.Get(streamKeysKey)
if err != nil {
return []models.StreamKey{}
}
var streamKeys []models.StreamKey
if err := configEntry.getObject(&streamKeys); err != nil {
return []models.StreamKey{}
}
return streamKeys
}
// SetStreamKeys will set valid stream keys.
func SetStreamKeys(keys []string) error {
return _datastore.SetStringSlice(streamKeysKey, keys)
func SetStreamKeys(actions []models.StreamKey) error {
configEntry := ConfigEntry{Key: streamKeysKey, Value: actions}
return _datastore.Save(configEntry)
}

View File

@@ -3,6 +3,7 @@ package data
import (
"strings"
"github.com/owncast/owncast/models"
log "github.com/sirupsen/logrus"
)
@@ -56,5 +57,7 @@ func migrateToDatastoreValues1(datastore *Datastore) {
func migrateToDatastoreValues2(datastore *Datastore) {
oldAdminPassword, _ := datastore.GetString("stream_key")
_ = SetAdminPassword(oldAdminPassword)
_ = SetStreamKeys([]string{oldAdminPassword})
_ = SetStreamKeys([]models.StreamKey{
{Key: oldAdminPassword, Comment: "Default stream key"},
})
}

View File

@@ -81,7 +81,7 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) {
validStreamingKeys := data.GetStreamKeys()
for _, key := range validStreamingKeys {
if secretMatch(key, c.URL.Path) {
if secretMatch(key.Key, c.URL.Path) {
accessGranted = true
break
}