Skip to content

Commit

Permalink
move query param handling into the struct
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Aug 29, 2023
1 parent 7d5cf0a commit 1f7bf6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 6 additions & 9 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ type StreamSignedURLParameters struct {
}

type StreamInitiateTUSUploadParameters struct {
DirectUserUpload bool
TusResumable TusProtocolVersion
UploadLength int64
UploadCreator string
Metadata TUSUploadMetadata
DirectUserUpload bool `url:"direct_user,omitempty"`
TusResumable TusProtocolVersion `url:"-"`
UploadLength int64 `url:"-"`
UploadCreator string `url:"-"`
Metadata TUSUploadMetadata `url:"-"`
}

type StreamInitiateTUSUploadResponse struct {
Expand Down Expand Up @@ -431,10 +431,7 @@ func (api *API) StreamInitiateTUSVideoUpload(ctx context.Context, rc *ResourceCo
headers.Set("Upload-Metadata", metadataTusCsv)
}

uri := fmt.Sprintf("/accounts/%s/stream", rc.Identifier)
if params.DirectUserUpload {
uri += "?direct_user=true"
}
uri := buildURI(fmt.Sprintf("/accounts/%s/stream", rc.Identifier), params)
res, err := api.makeRequestWithAuthTypeAndHeadersComplete(ctx, http.MethodPost, uri, nil, api.authType, headers)
if err != nil {
return StreamInitiateTUSUploadResponse{}, err
Expand Down
4 changes: 2 additions & 2 deletions stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func TestStream_StreamInitiateTUSVideoUpload(t *testing.T) {
if r.URL.Query().Get("direct_user") == "true" {
w.Header().Set("Location", "https://upload.videodelivery.net/tus/90c68cb5cd4fd5350b1962279c90bec0?tusv2=true")
} else {
w.Header().Set("Location", "https://production.gateway.api.cloudflare.com/client/v4/accounts/test-account-id/media/278f2a7e763c73dedc064b965d2cfbed?tusv2=true")
w.Header().Set("Location", "https://api.cloudflare.com/client/v4/accounts/"+testAccountID+"/media/278f2a7e763c73dedc064b965d2cfbed?tusv2=true")
}

w.Header().Set("stream-media-id", "278f2a7e763c73dedc064b965d2cfbed")
Expand All @@ -606,7 +606,7 @@ func TestStream_StreamInitiateTUSVideoUpload(t *testing.T) {

out, err := client.StreamInitiateTUSVideoUpload(context.Background(), AccountIdentifier(testAccountID), params)
if assert.NoError(t, err) {
assert.Equal(t, "https://production.gateway.api.cloudflare.com/client/v4/accounts/test-account-id/media/278f2a7e763c73dedc064b965d2cfbed?tusv2=true", out.ResponseHeaders.Get("Location"))
assert.Equal(t, "https://api.cloudflare.com/client/v4/accounts/"+testAccountID+"/media/278f2a7e763c73dedc064b965d2cfbed?tusv2=true", out.ResponseHeaders.Get("Location"))
assert.Equal(t, "278f2a7e763c73dedc064b965d2cfbed", out.ResponseHeaders.Get("stream-media-id"))
assert.Equal(t, "1.0.0", out.ResponseHeaders.Get("Tus-Resumable"))
}
Expand Down

0 comments on commit 1f7bf6a

Please sign in to comment.