Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds support to initiate streams upload using tus #1359

Merged
merged 11 commits into from Aug 29, 2023
Merged

adds support to initiate streams upload using tus #1359

merged 11 commits into from Aug 29, 2023

Conversation

bbbshah
Copy link
Contributor

@bbbshah bbbshah commented Aug 6, 2023

Adds support to streams to initiate tus video upload.

Description

The current api client doesn't support streams: initiate tus video upload.
This PR adds a new func StreamInitiateTUSVideoUpload to streams.go.

Has your change been tested?

Added unit tests for the newly added functions.

Types of changes

What sort of change does your code introduce/modify?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • This change is using publicly documented in cloudflare/api-schemas
    and relies on stable APIs.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2023

changelog detected ✅

@bbbshah bbbshah marked this pull request as ready for review August 17, 2023 07:10
@bbbshah
Copy link
Contributor Author

bbbshah commented Aug 29, 2023

@jacobbednarz Would you be able to take a look at this PR when you get a chance? Thank you in advance!

stream.go Outdated
Comment on lines 193 to 199
type StreamInitiateTUSUploadParameters struct {
DirectUserUpload bool
TusResumable TusProtocolVersion
UploadLength int64
UploadCreator string
Metadata TUSUploadMetadata
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows us to use the struct for query parameter building in buildURI instead of manually performing it.

stream.go Outdated
Comment on lines 434 to 437
uri := fmt.Sprintf("/accounts/%s/stream", rc.Identifier)
if params.DirectUserUpload {
uri += "?direct_user=true"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

stream_test.go Outdated
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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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")

stream_test.go Outdated

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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"))

@jacobbednarz
Copy link
Member

this looks good, thanks!

for future PRs, i recommend clicking the "allow maintainers to make changes" checkbox to save the back and forth here and we can apply small edits like the above ones without having to do the extra round trip.

@codecov-commenter
Copy link

Codecov Report

Merging #1359 (1f7bf6a) into master (b9ac804) will increase coverage by 0.08%.
Report is 223 commits behind head on master.
The diff coverage is 50.54%.

@@            Coverage Diff             @@
##           master    #1359      +/-   ##
==========================================
+ Coverage   48.33%   48.41%   +0.08%     
==========================================
  Files         133      139       +6     
  Lines       13023    13809     +786     
==========================================
+ Hits         6295     6686     +391     
- Misses       5201     5466     +265     
- Partials     1527     1657     +130     
Files Changed Coverage Δ
access_audit_log.go 79.31% <ø> (ø)
access_bookmark.go 72.44% <ø> (ø)
access_keys.go 71.42% <ø> (ø)
access_organization.go 53.84% <ø> (ø)
access_service_tokens.go 51.85% <ø> (ø)
account_members.go 65.54% <ø> (ø)
account_roles.go 53.84% <ø> (ø)
accounts.go 50.81% <ø> (ø)
addressing_address_map.go 39.04% <ø> (ø)
addressing_ip_prefix.go 45.45% <ø> (ø)
... and 121 more

... and 1 file with indirect coverage changes

@jacobbednarz jacobbednarz merged commit 68ee8c1 into cloudflare:master Aug 29, 2023
11 checks passed
@github-actions github-actions bot added this to the v0.77.0 milestone Aug 29, 2023
github-actions bot pushed a commit that referenced this pull request Aug 30, 2023
@github-actions
Copy link
Contributor

This functionality has been released in v0.77.0.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2023
@bbbshah bbbshah deleted the feature/stream-video-initiate-tus-upload branch September 13, 2023 05:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants