Skip to content

feat(plugin-cloud-storage): implement storage packages - #5928

Merged
denolfe merged 11 commits into
betafrom
feat/storage-adapter-packages
Apr 22, 2024
Merged

denolfe merged 11 commits into
betafrom
feat/storage-adapter-packages

Conversation

@denolfe

@denolfe denolfe commented Apr 19, 2024 •

Copy link
Copy Markdown
Member

Description

This will have an accompanying breaking change before release to remove the existing adapters from @payloadcms/plugin-cloud-storage in favor of these packages.

Splitting out each adapter into their own standalone, functional packages. This was needed because there were a lack of warnings when enforcing optional peer dependency version ranges. The experience will also be much nicer.

The goal is to have the user only install the storage package that they need, and not need to install @payloadcms/plugin-cloud-storage or peer dependencies directly - it will be used internally within the storage packages.

All existing cloud-storage adapters will be removed from @payloadcms/plugin-cloud-storage

Usage before:

Required peer dependencies to be installed

import { cloudStorage } from '@payloadcms/plugin-cloud-storage'
import { s3Adapter } from '@payloadcms/plugin-cloud-storage/s3'

plugins: [
    cloudStorage({
      collections: {
        [mediaSlug]: {
          adapter: s3Adapter({
            bucket: process.env.S3_BUCKET,
            config: {
              credentials: {
                accessKeyId: process.env.S3_ACCESS_KEY_ID,
                secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
              },
              region: process.env.S3_REGION,
            },
          }),
        },
      },
    }),
  ],

Usage after:

No peer dependencies

import { s3Storage } from '@payloadcms/storage-s3'

plugins: [
    s3Storage({
      collections: {
        [mediaSlug]: true,
      },
      bucket: process.env.S3_BUCKET,
      config: {
        credentials: {
          accessKeyId: process.env.S3_ACCESS_KEY_ID,
          secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
        },
        region: process.env.S3_REGION,
      },
    }),
  ],

@denolfe denolfe changed the title feat: implement storage packages feat!: implement storage packages Apr 19, 2024
@denolfe denolfe changed the title feat!: implement storage packages feat(plugin-cloud-storage)!: implement storage packages Apr 20, 2024
@denolfe
denolfe force-pushed the feat/storage-adapter-packages branch from 843a4e4 to a0bcc3a Compare April 21, 2024 12:45
@denolfe
denolfe force-pushed the feat/storage-adapter-packages branch from e88b421 to f27f169 Compare April 22, 2024 02:51
@denolfe denolfe changed the title feat(plugin-cloud-storage)!: implement storage packages feat(plugin-cloud-storage): implement storage packages Apr 22, 2024
@denolfe
denolfe marked this pull request as ready for review April 22, 2024 12:26
@denolfe
denolfe merged commit c23984c into beta Apr 22, 2024
@denolfe
denolfe deleted the feat/storage-adapter-packages branch April 22, 2024 18:31
nathanlentz added a commit that referenced this pull request Oct 23, 2026
…RandomSuffix (#18920)

Stacked on #18913. Review and merge #18388 and #18913 first. This PR
does not depend on their changes. It is in the stack because #18921
changes the same adapter code.

Fixes #9589.

## Summary

With `addRandomSuffix: true`, Vercel Blob uploads the main file and each
image size in parallel. Every upload wrote its suffixed name to the same
`data.filename`. As a result, the document filename could point to an
image size, and no image size got its suffixed name. Every image-size
URL returned 404.

Now each upload writes its suffixed name only to its own entry: an image
size updates `sizes.<name>.filename`, and the main file updates
`filename`.

## How

- After each upload finishes, the adapter finds the image size whose
filename matches the uploaded file. If no size matches, the file is the
main file.
- Two image sizes with the same dimensions get the same filename. The
adapter finds the entry after the upload, so a size that an earlier
upload renamed does not match again. Each size gets its own entry.
- `storage-uploadthing` already uses this pattern for its per-file keys.
- `plugin-cloud-storage` does not change.

## Tests

- A unit test checks that the main file and an image size each update
only their own filename.
- A unit test uploads two image sizes with the same filename in
parallel. It checks that each size gets its own suffixed filename. This
test failed before this change.
- An integration test uploads an image with one image size and
`addRandomSuffix: true`. It checks that every filename on the document
has an object in storage, and that the main object size is equal to the
document `filesize`. This test failed on every run before this change.

## Related work

- Stack: #18388 → #18913 → this PR → #18921

- The bug started in #5928, the first version of the storage packages.
- Not in scope: #18384 (the create response has a `url` without the
suffix) and #18804 (focal point with a new filename).

---------

Co-authored-by: Jarrod Flesch <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants