Browse Source

feat(api): put replay APIs behind feature flag

pull/3395/head
Gabe Kangas 2 years ago
parent
commit
8021c66869
No known key found for this signature in database
GPG Key ID: 4345B2060657F330
  1. 16
      controllers/clips.go
  2. 6
      controllers/replays.go
  3. 2
      core/transcoder/hlsHandler.go
  4. 2
      replays/hlsRecorder.go

16
controllers/clips.go

@ -7,12 +7,18 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/replays" "github.com/owncast/owncast/replays"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// GetAllClips will return all clips that have been previously created. // GetAllClips will return all clips that have been previously created.
func GetAllClips(w http.ResponseWriter, r *http.Request) { func GetAllClips(w http.ResponseWriter, r *http.Request) {
if !config.EnableReplayFeatures {
w.WriteHeader(http.StatusNotFound)
return
}
clips, err := replays.GetAllClips() clips, err := replays.GetAllClips()
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
@ -25,6 +31,11 @@ func GetAllClips(w http.ResponseWriter, r *http.Request) {
// AddClip will create a new clip for a given stream and time window. // AddClip will create a new clip for a given stream and time window.
func AddClip(w http.ResponseWriter, r *http.Request) { func AddClip(w http.ResponseWriter, r *http.Request) {
if !config.EnableReplayFeatures {
w.WriteHeader(http.StatusNotFound)
return
}
type addClipRequest struct { type addClipRequest struct {
StreamId string `json:"streamId"` StreamId string `json:"streamId"`
ClipTitle string `json:"clipTitle"` ClipTitle string `json:"clipTitle"`
@ -95,6 +106,11 @@ func AddClip(w http.ResponseWriter, r *http.Request) {
// GetClip will return playable content for a given clip Id. // GetClip will return playable content for a given clip Id.
func GetClip(w http.ResponseWriter, r *http.Request) { func GetClip(w http.ResponseWriter, r *http.Request) {
if !config.EnableReplayFeatures {
w.WriteHeader(http.StatusNotFound)
return
}
pathComponents := strings.Split(r.URL.Path, "/") pathComponents := strings.Split(r.URL.Path, "/")
if len(pathComponents) == 3 { if len(pathComponents) == 3 {
// Return the master playlist for the requested stream // Return the master playlist for the requested stream

6
controllers/replays.go

@ -4,12 +4,18 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/replays" "github.com/owncast/owncast/replays"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// GetReplays will return a list of all available replays. // GetReplays will return a list of all available replays.
func GetReplays(w http.ResponseWriter, r *http.Request) { func GetReplays(w http.ResponseWriter, r *http.Request) {
if !config.EnableReplayFeatures {
w.WriteHeader(http.StatusNotFound)
return
}
streams, err := replays.GetStreams() streams, err := replays.GetStreams()
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)

2
core/transcoder/hlsHandler.go

@ -23,7 +23,9 @@ func (h *HLSHandler) StreamEnded() {
func (h *HLSHandler) SetStreamId(streamId string) { func (h *HLSHandler) SetStreamId(streamId string) {
h.Storage.SetStreamId(streamId) h.Storage.SetStreamId(streamId)
if config.EnableReplayFeatures {
h.Recorder = replays.NewRecording(streamId) h.Recorder = replays.NewRecording(streamId)
}
} }
// SegmentWritten is fired when a HLS segment is written to disk. // SegmentWritten is fired when a HLS segment is written to disk.

2
replays/hlsRecorder.go

@ -32,6 +32,8 @@ func NewRecording(streamID string) *HLSRecorder {
return nil return nil
} }
log.Infoln("Recording replay of this stream:", streamID)
h := HLSRecorder{ h := HLSRecorder{
streamID: streamID, streamID: streamID,
startTime: time.Now(), startTime: time.Now(),

Loading…
Cancel
Save