From 50adbffe56da96f71866f4d602210cd345176ab9 Mon Sep 17 00:00:00 2001 From: Bhavik Shah Date: Tue, 12 Sep 2023 22:36:25 -0700 Subject: [PATCH 1/2] adds stream create parameters: maxDurationSeconds and expiry --- .changelog/1399.txt | 3 +++ stream.go | 8 ++++++++ stream_test.go | 13 ++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .changelog/1399.txt diff --git a/.changelog/1399.txt b/.changelog/1399.txt new file mode 100644 index 00000000000..64d0db476af --- /dev/null +++ b/.changelog/1399.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +streams: adds support for stream create parameters for tus upload initiate +``` diff --git a/stream.go b/stream.go index a2cae8dd91e..3a831bc1e81 100644 --- a/stream.go +++ b/stream.go @@ -204,10 +204,12 @@ type StreamInitiateTUSUploadResponse struct { type TUSUploadMetadata struct { Name string `json:"name,omitempty"` + MaxDurationSeconds int `json:"maxDurationSeconds,omitempty"` RequireSignedURLs bool `json:"requiresignedurls,omitempty"` AllowedOrigins string `json:"allowedorigins,omitempty"` ThumbnailTimestampPct float64 `json:"thumbnailtimestamppct,omitempty"` ScheduledDeletion *time.Time `json:"scheduledDeletion,omitempty"` + Expiry *time.Time `json:"expiry,omitempty"` Watermark string `json:"watermark,omitempty"` } @@ -216,6 +218,9 @@ func (t TUSUploadMetadata) ToTUSCsv() (string, error) { if t.Name != "" { metadataValues = append(metadataValues, fmt.Sprintf("%s %s", "name", base64.StdEncoding.EncodeToString([]byte(t.Name)))) } + if t.MaxDurationSeconds != 0 { + metadataValues = append(metadataValues, fmt.Sprintf("%s %s", "maxDurationSeconds", base64.StdEncoding.EncodeToString([]byte(strconv.Itoa(t.MaxDurationSeconds))))) + } if t.RequireSignedURLs { metadataValues = append(metadataValues, "requiresignedurls") } @@ -228,6 +233,9 @@ func (t TUSUploadMetadata) ToTUSCsv() (string, error) { if t.ScheduledDeletion != nil { metadataValues = append(metadataValues, fmt.Sprintf("%s %s", "scheduledDeletion", base64.StdEncoding.EncodeToString([]byte(t.ScheduledDeletion.Format(time.RFC3339))))) } + if t.Expiry != nil { + metadataValues = append(metadataValues, fmt.Sprintf("%s %s", "expiry", base64.StdEncoding.EncodeToString([]byte(t.Expiry.Format(time.RFC3339))))) + } if t.Watermark != "" { metadataValues = append(metadataValues, fmt.Sprintf("%s %s", "watermark", base64.StdEncoding.EncodeToString([]byte(t.Watermark)))) } diff --git a/stream_test.go b/stream_test.go index d42b941a4d6..c589a08ce58 100644 --- a/stream_test.go +++ b/stream_test.go @@ -554,10 +554,21 @@ func TestStream_TUSUploadMetadataToTUSCsv(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "name dGVzdC5tcDQ=,requiresignedurls,allowedorigins ZXhhbXBsZS5jb20=,thumbnailtimestamppct MC41,scheduledDeletion MjAyMy0xMC0wMVQwMjoyMDowMFo=", csv) + expiry, _ := time.Parse(time.RFC3339, "2023-09-25T02:45:00Z") + md.Expiry = &expiry + csv, err = md.ToTUSCsv() + assert.NoError(t, err) + assert.Equal(t, "name dGVzdC5tcDQ=,requiresignedurls,allowedorigins ZXhhbXBsZS5jb20=,thumbnailtimestamppct MC41,scheduledDeletion MjAyMy0xMC0wMVQwMjoyMDowMFo=,expiry MjAyMy0wOS0yNVQwMjo0NTowMFo=", csv) + md.Watermark = "watermark-profile-uid" csv, err = md.ToTUSCsv() assert.NoError(t, err) - assert.Equal(t, "name dGVzdC5tcDQ=,requiresignedurls,allowedorigins ZXhhbXBsZS5jb20=,thumbnailtimestamppct MC41,scheduledDeletion MjAyMy0xMC0wMVQwMjoyMDowMFo=,watermark d2F0ZXJtYXJrLXByb2ZpbGUtdWlk", csv) + assert.Equal(t, "name dGVzdC5tcDQ=,requiresignedurls,allowedorigins ZXhhbXBsZS5jb20=,thumbnailtimestamppct MC41,scheduledDeletion MjAyMy0xMC0wMVQwMjoyMDowMFo=,expiry MjAyMy0wOS0yNVQwMjo0NTowMFo=,watermark d2F0ZXJtYXJrLXByb2ZpbGUtdWlk", csv) + + md.MaxDurationSeconds = 300 + csv, err = md.ToTUSCsv() + assert.NoError(t, err) + assert.Equal(t, "name dGVzdC5tcDQ=,maxDurationSeconds MzAw,requiresignedurls,allowedorigins ZXhhbXBsZS5jb20=,thumbnailtimestamppct MC41,scheduledDeletion MjAyMy0xMC0wMVQwMjoyMDowMFo=,expiry MjAyMy0wOS0yNVQwMjo0NTowMFo=,watermark d2F0ZXJtYXJrLXByb2ZpbGUtdWlk", csv) // empty metadata should return empty string md = TUSUploadMetadata{} From aa6c94ab1fc6ee19ddefa6b826fc7c5a906135e8 Mon Sep 17 00:00:00 2001 From: Bhavik Shah Date: Tue, 12 Sep 2023 22:40:05 -0700 Subject: [PATCH 2/2] fixes changelog number --- .changelog/{1399.txt => 1400.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{1399.txt => 1400.txt} (100%) diff --git a/.changelog/1399.txt b/.changelog/1400.txt similarity index 100% rename from .changelog/1399.txt rename to .changelog/1400.txt