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. 4
      core/transcoder/hlsHandler.go
  4. 2
      replays/hlsRecorder.go

16
controllers/clips.go

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

6
controllers/replays.go

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

4
core/transcoder/hlsHandler.go

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

2
replays/hlsRecorder.go

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

Loading…
Cancel
Save