nuxt-hub / core

Build full-stack applications with Nuxt on CloudFlare, with zero configuration.
https://hub.nuxt.com
Apache License 2.0
802 stars 35 forks source link

feat(blob)!: change API for consistency #187

Closed Atinux closed 4 days ago

Atinux commented 4 days ago

This brings two breaking changes for hubBlob()

Custom Metadata

As we get the custom metadata in the customMetadata object, it makes sense to define them in the key as well.

Before:

hubBlob().put(file.name, file, {
  addRandomSuffix: true,
  hello: 'world'
})
/*
{
  contentType: 'image/jped',
  pathname: 'something-87652rfg.jpg',
  size: 154451,
  uploadedAt:  '2024-06-21T00:57:41.740Z',
  customMetadata: {
    hello: 'world'
  }
}
*/

After:

hubBlob().put(file.name, file, {
  addRandomSuffix: true,
  customMetadata: {
    hello: 'world'
  }
})
/*
{
  contentType: 'image/jped',
  pathname: 'something-87652rfg.jpg',
  size: 154451,
  uploadedAt:  '2024-06-21T00:57:41.740Z',
  customMetadata: {
    hello: 'world'
  }
}
*/

handleUpload

Before, we could give at the same level the options of put(), ensure() and handleUpload(), making it a bit confusing.

Now you need to set the options with the command prefix:

Before:

export default eventHandler(async (event) => {
  return hubBlob().handleUpload(event, {
    multiple: false,
    contentType: ['image/jpeg', 'images/png'],
    addRandomSuffix: true
  })
})

After:

export default eventHandler(async (event) => {
  return hubBlob().handleUpload(event, {
    multiple: false,
    ensure: {
      contentType: ['image/jpeg', 'images/png'],
    },
    put: {
      addRandomSuffix: true
    }
  })
})
pkg-pr-new[bot] commented 4 days ago

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

commit: 2d86b08

@nuxthub/core

``` npm i https://pkg.pr.new/nuxt-hub/core/@nuxthub/core@187 ```


templates

- [default](https://pkg.pr.new/template/1d134c3f-246f-458c-9650-fa4010acef46)

cloudflare-pages[bot] commented 4 days ago

Deploying nuxthub-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9f18a93
Status: ✅  Deploy successful!
Preview URL: https://aa3f57cb.nuxthub-module.pages.dev
Branch Preview URL: https://feat-blob-improvements.nuxthub-module.pages.dev

View logs