From f7f1c0f115ff8c9c9628808c651cac2f5dfbd4bb Mon Sep 17 00:00:00 2001 From: Thom Shutt Date: Fri, 26 Jul 2024 17:32:49 +0100 Subject: [PATCH] Better method for detecting clipping requests --- handlers/upload.go | 13 +------------ handlers/upload_test.go | 24 +++--------------------- 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/handlers/upload.go b/handlers/upload.go index a1359f46..9b4d8065 100644 --- a/handlers/upload.go +++ b/handlers/upload.go @@ -109,9 +109,7 @@ func (r UploadVODRequest) IsProfileValid() bool { } func (r UploadVODRequest) IsClippingRequest() bool { - return r.hasTargetOutput(func(o UploadVODRequestOutputLocationOutputs) string { - return o.Clip - }) + return r.ClipStrategy.PlaybackID != "" } func (r UploadVODRequest) ValidateClippingRequest() error { @@ -165,15 +163,6 @@ func (r UploadVODRequest) getSourceCopyEnabled() bool { type getOutput func(UploadVODRequestOutputLocationOutputs) string -func (r UploadVODRequest) hasTargetOutput(getOutput getOutput) bool { - for _, o := range r.OutputLocations { - if getOutput(o.Outputs) == "enabled" { - return true - } - } - return false -} - func (r UploadVODRequest) getTargetOutput(getOutput getOutput) UploadVODRequestOutputLocation { for _, o := range r.OutputLocations { if getOutput(o.Outputs) == "enabled" { diff --git a/handlers/upload_test.go b/handlers/upload_test.go index 747c9d3a..8a2e94d0 100644 --- a/handlers/upload_test.go +++ b/handlers/upload_test.go @@ -200,31 +200,13 @@ func TestIsProfileValid(t *testing.T) { func TestWeCanDetermineIfItsAClippingRequest(t *testing.T) { u := UploadVODRequest{ - OutputLocations: []UploadVODRequestOutputLocation{ - { - URL: "some-url", - Type: "clip", - Outputs: UploadVODRequestOutputLocationOutputs{ - Clip: "enabled", - }, - }, + ClipStrategy: video.ClipStrategy{ + PlaybackID: "12345", }, } require.True(t, u.IsClippingRequest()) - u = UploadVODRequest{ - OutputLocations: []UploadVODRequestOutputLocation{ - { - URL: "some-url", - Type: "vod", - Outputs: UploadVODRequestOutputLocationOutputs{ - HLS: "enabled", - MP4: "enabled", - Thumbnails: "enabled", - }, - }, - }, - } + u = UploadVODRequest{} require.False(t, u.IsClippingRequest()) }