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

Refactor Storage download & upload (flow) implementation #729

Merged
merged 15 commits into from
Sep 17, 2024

Conversation

jan-tennert
Copy link
Collaborator

@jan-tennert jan-tennert commented Sep 16, 2024

What kind of change does this PR introduce?

Internal refactor and public API improvements

What is the current behavior?

The current implementation is very complex/messy and the flow variants are even worse (calling BucketApiImpl methods, that shouldn't be in a public extension function).

What is the new behavior?

Public API

Every upload and download method now has a options DSL. This makes it possible to add configuration options in the future without filling up the parameter list (e.g. file metadata)
For downloads, there are currently only two things to configure:

  1. Image transformation (moved down)
  2. Http request overrides. This is important for the flow variants to attach download listeners.

Example of the new syntax:

supabase.storage.from("test").downloadAuthenticated("test.jpg") {
    transform {
        size(100, 100)
    }
}

For uploads, you can configure:

  1. Whether to upsert or not (moved down)
  2. The content type (will be inferred if null, wasn't configurable before)
  3. Also Http request overrides for flow variants.

Example of the new syntax:

supabase.storage.from("test").upload("test.txt", "Hello World!".encodeToByteArray()) {
    contentType = ContentType.Text.Plain
    upsert = true
}

Every upload/update/download variant has this new builder including the flow variants.

BucketItem has been renamed to FileObject to match the JS lib.

Internal implementation

For non-flow-variants I cleaned up the code to minimize duplications & improve readability.
The same approach was used for the flow variants, which no longer call internal methods from BucketApiImpl and instead use the new httpOverride option.

Additional context

Add any other context or screenshots.

@jan-tennert jan-tennert added the enhancement New feature or request label Sep 16, 2024
@jan-tennert jan-tennert self-assigned this Sep 16, 2024
@jan-tennert
Copy link
Collaborator Author

jan-tennert commented Sep 16, 2024

Note that there are some commits from #694 because I backported and improved some of the changes, but file metadata and exists/info support is not being added in this PR.

Copy link
Member

@dshukertjr dshukertjr left a comment

Choose a reason for hiding this comment

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

I love the new public API! Just to check, these updates are being included in another major version bump, correct?

@jan-tennert
Copy link
Collaborator Author

jan-tennert commented Sep 17, 2024

Yes, I originally wanted to only refactor some internal stuff, but now the changes are getting very breaking alongside the WASM support. I can probably include #622 too.
I plan to release 3.0.0.

@jan-tennert jan-tennert merged commit 6689099 into master Sep 17, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request storage tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants