@payloadcms/storage-s3 3.0.0-beta.13 → 3.0.0-beta.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +17 -17
- package/README.md +50 -1
- package/dist/generateURL.js.map +1 -1
- package/dist/handleDelete.js.map +1 -1
- package/dist/handleUpload.d.ts +1 -1
- package/dist/handleUpload.d.ts.map +1 -1
- package/dist/handleUpload.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/staticHandler.d.ts +1 -1
- package/dist/staticHandler.d.ts.map +1 -1
- package/dist/staticHandler.js.map +1 -1
- package/package.json +29 -20
package/LICENSE.md
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-
|
|
4
|
-
Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>
|
|
5
4
|
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
-
of this software and associated documentation files (the
|
|
8
|
-
in the Software without restriction, including
|
|
9
|
-
to use, copy, modify, merge, publish,
|
|
10
|
-
copies of the Software, and to
|
|
11
|
-
furnished to do so, subject to
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
'Software'), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
12
|
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
copies or substantial portions of the Software.
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
15
|
|
|
16
|
-
THE SOFTWARE IS PROVIDED
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
|
|
22
|
-
SOFTWARE.
|
|
16
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# S3 Storage for Payload
|
|
2
|
+
|
|
3
|
+
This package provides a simple way to use S3 with Payload.
|
|
4
|
+
|
|
5
|
+
**NOTE:** This package removes the need to use `@payloadcms/plugin-cloud-storage` as was needed in Payload 2.x.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @payloadcms/storage-s3
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
- Configure the `collections` object to specify which collections should use the AWS S3 adapter. The slug _must_ match one of your existing collection slugs.
|
|
16
|
+
- The `config` object can be any [`S3ClientConfig`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3) object (from [`@aws-sdk/client-s3`](https://github.com/aws/aws-sdk-js-v3)). _This is highly dependent on your AWS setup_. Check the AWS documentation for more information.
|
|
17
|
+
- When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { s3Storage } from '@payloadcms/storage-s3'
|
|
21
|
+
import { Media } from './collections/Media'
|
|
22
|
+
import { MediaWithPrefix } from './collections/MediaWithPrefix'
|
|
23
|
+
|
|
24
|
+
export default buildConfig({
|
|
25
|
+
collections: [Media, MediaWithPrefix],
|
|
26
|
+
plugins: [
|
|
27
|
+
s3Storage({
|
|
28
|
+
collections: {
|
|
29
|
+
[mediaSlug]: true,
|
|
30
|
+
[mediaWithPrefixSlug]: {
|
|
31
|
+
prefix,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
bucket: process.env.S3_BUCKET,
|
|
35
|
+
config: {
|
|
36
|
+
credentials: {
|
|
37
|
+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
|
38
|
+
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
|
39
|
+
},
|
|
40
|
+
region: process.env.S3_REGION,
|
|
41
|
+
// ... Other S3 configuration
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Configuration Options
|
|
49
|
+
|
|
50
|
+
See the the [AWS SDK Package](https://github.com/aws/aws-sdk-js-v3) and [`S3ClientConfig`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3) object for guidance on AWS S3 configuration.
|
package/dist/generateURL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n config: AWS.S3ClientConfig\n}\n\nexport const getGenerateURL =\n ({ bucket, config: { endpoint } }: Args): GenerateURL =>\n ({ filename, prefix = '' }) => {\n const stringifiedEndpoint = typeof endpoint === 'string' ? endpoint : endpoint?.toString()\n return `${stringifiedEndpoint}/${bucket}/${path.posix.join(prefix, filename)}`\n }\n"],"names":["path","getGenerateURL","bucket","config","endpoint","filename","prefix","stringifiedEndpoint","toString","posix","join"],"
|
|
1
|
+
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n config: AWS.S3ClientConfig\n}\n\nexport const getGenerateURL =\n ({ bucket, config: { endpoint } }: Args): GenerateURL =>\n ({ filename, prefix = '' }) => {\n const stringifiedEndpoint = typeof endpoint === 'string' ? endpoint : endpoint?.toString()\n return `${stringifiedEndpoint}/${bucket}/${path.posix.join(prefix, filename)}`\n }\n"],"names":["path","getGenerateURL","bucket","config","endpoint","filename","prefix","stringifiedEndpoint","toString","posix","join"],"mappings":"AAGA,OAAOA,UAAU,OAAM;AAOvB,OAAO,MAAMC,iBACX,CAAC,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAQ,GACvC,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAE,EAAE;QACxB,MAAMC,sBAAsB,OAAOH,aAAa,WAAWA,WAAWA,UAAUI;QAChF,OAAO,CAAC,EAAED,oBAAoB,CAAC,EAAEL,OAAO,CAAC,EAAEF,KAAKS,KAAK,CAACC,IAAI,CAACJ,QAAQD,UAAU,CAAC;IAChF,EAAC"}
|
package/dist/handleDelete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n getStorageClient: () => AWS.S3\n}\n\nexport const getHandleDelete = ({ bucket, getStorageClient }: Args): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n await getStorageClient().deleteObject({\n Bucket: bucket,\n Key: path.posix.join(prefix, filename),\n })\n }\n}\n"],"names":["path","getHandleDelete","bucket","getStorageClient","doc","prefix","filename","deleteObject","Bucket","Key","posix","join"],"
|
|
1
|
+
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n getStorageClient: () => AWS.S3\n}\n\nexport const getHandleDelete = ({ bucket, getStorageClient }: Args): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n await getStorageClient().deleteObject({\n Bucket: bucket,\n Key: path.posix.join(prefix, filename),\n })\n }\n}\n"],"names":["path","getHandleDelete","bucket","getStorageClient","doc","prefix","filename","deleteObject","Bucket","Key","posix","join"],"mappings":"AAGA,OAAOA,UAAU,OAAM;AAOvB,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,MAAM,EAAEC,gBAAgB,EAAQ;IAChE,OAAO,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAE,EAAE,EAAEC,QAAQ,EAAE;QAC9C,MAAMH,mBAAmBI,YAAY,CAAC;YACpCC,QAAQN;YACRO,KAAKT,KAAKU,KAAK,CAACC,IAAI,CAACN,QAAQC;QAC/B;IACF;AACF,EAAC"}
|
package/dist/handleUpload.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as AWS from '@aws-sdk/client-s3';
|
|
2
2
|
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { CollectionConfig } from 'payload
|
|
3
|
+
import type { CollectionConfig } from 'payload';
|
|
4
4
|
interface Args {
|
|
5
5
|
acl?: 'private' | 'public-read';
|
|
6
6
|
bucket: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM/C,UAAU,IAAI;IACZ,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,GAAG,CAAC,EAAE,CAAA;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAID,eAAO,MAAM,eAAe,+CAKzB,IAAI,KAAG,YAqCT,CAAA"}
|
package/dist/handleUpload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { Upload } from '@aws-sdk/lib-storage'\nimport fs from 'fs'\nimport path from 'path'\n\ninterface Args {\n acl?: 'private' | 'public-read'\n bucket: string\n collection: CollectionConfig\n getStorageClient: () => AWS.S3\n prefix?: string\n}\n\nconst multipartThreshold = 1024 * 1024 * 50 // 50MB\n\nexport const getHandleUpload = ({\n acl,\n bucket,\n getStorageClient,\n prefix = '',\n}: Args): HandleUpload => {\n return async ({ data, file }) => {\n const fileKey = path.posix.join(data.prefix || prefix, file.filename)\n\n const fileBufferOrStream = file.tempFilePath\n ? fs.createReadStream(file.tempFilePath)\n : file.buffer\n\n if (file.buffer.length > 0 && file.buffer.length < multipartThreshold) {\n await getStorageClient().putObject({\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: file.mimeType,\n Key: fileKey,\n })\n\n return data\n }\n\n const parallelUploadS3 = new Upload({\n client: getStorageClient(),\n params: {\n ACL: acl,\n Body: fileBufferOrStream,\n Bucket: bucket,\n ContentType: file.mimeType,\n Key: fileKey,\n },\n partSize: multipartThreshold,\n queueSize: 4,\n })\n\n await parallelUploadS3.done()\n\n return data\n }\n}\n"],"names":["Upload","fs","path","multipartThreshold","getHandleUpload","acl","bucket","getStorageClient","prefix","data","file","fileKey","posix","join","filename","fileBufferOrStream","tempFilePath","createReadStream","buffer","length","putObject","ACL","Body","Bucket","ContentType","mimeType","Key","parallelUploadS3","client","params","partSize","queueSize","done"],"mappings":"AAIA,SAASA,MAAM,QAAQ,uBAAsB;AAC7C,OAAOC,QAAQ,KAAI;AACnB,OAAOC,UAAU,OAAM;AAUvB,MAAMC,qBAAqB,OAAO,OAAO,GAAG,OAAO;;AAEnD,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EAChBC,SAAS,EAAE,EACN;IACL,OAAO,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QAC1B,MAAMC,UAAUT,KAAKU,KAAK,CAACC,IAAI,CAACJ,KAAKD,MAAM,IAAIA,QAAQE,KAAKI,QAAQ;QAEpE,MAAMC,qBAAqBL,KAAKM,YAAY,GACxCf,GAAGgB,gBAAgB,CAACP,KAAKM,YAAY,IACrCN,KAAKQ,MAAM;QAEf,IAAIR,KAAKQ,MAAM,CAACC,MAAM,GAAG,KAAKT,KAAKQ,MAAM,CAACC,MAAM,GAAGhB,oBAAoB;YACrE,MAAMI,mBAAmBa,SAAS,CAAC;gBACjCC,KAAKhB;gBACLiB,MAAMP;gBACNQ,QAAQjB;gBACRkB,aAAad,KAAKe,QAAQ;gBAC1BC,KAAKf;YACP;YAEA,OAAOF;QACT;QAEA,MAAMkB,mBAAmB,IAAI3B,OAAO;YAClC4B,QAAQrB;YACRsB,QAAQ;gBACNR,KAAKhB;gBACLiB,MAAMP;gBACNQ,QAAQjB;gBACRkB,aAAad,KAAKe,QAAQ;gBAC1BC,KAAKf;YACP;YACAmB,UAAU3B;YACV4B,WAAW;QACb;QAEA,MAAMJ,iBAAiBK,IAAI;QAE3B,OAAOvB;IACT;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAA;AAE7C,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAQzC,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IAEH,GAAG,CAAC,EAAE,SAAS,GAAG,aAAa,CAAA;IAC/B;;;;OAIG;IAEH,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IACtE;;;;OAIG;IACH,MAAM,EAAE,GAAG,CAAC,cAAc,CAAA;IAE1B;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,KAAK,eAAe,GAAG,CAAC,aAAa,EAAE,gBAAgB,KAAK,MAAM,CAAA;AAElE,eAAO,MAAM,SAAS,EAAE,eA4CrB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as AWS from '@aws-sdk/client-s3';
|
|
2
|
-
import {
|
|
2
|
+
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
3
3
|
import { getGenerateURL } from './generateURL.js';
|
|
4
4
|
import { getHandleDelete } from './handleDelete.js';
|
|
5
5
|
import { getHandleUpload } from './handleUpload.js';
|
|
@@ -33,7 +33,7 @@ export const s3Storage = (s3StorageOptions)=>(incomingConfig)=>{
|
|
|
33
33
|
};
|
|
34
34
|
})
|
|
35
35
|
};
|
|
36
|
-
return
|
|
36
|
+
return cloudStoragePlugin({
|
|
37
37
|
collections: collectionsWithAdapter
|
|
38
38
|
})(config);
|
|
39
39
|
};
|
|
@@ -41,11 +41,14 @@ function s3StorageInternal({ acl, bucket, config = {} }) {
|
|
|
41
41
|
return ({ collection, prefix })=>{
|
|
42
42
|
let storageClient = null;
|
|
43
43
|
const getStorageClient = ()=>{
|
|
44
|
-
if (storageClient)
|
|
44
|
+
if (storageClient) {
|
|
45
|
+
return storageClient;
|
|
46
|
+
}
|
|
45
47
|
storageClient = new AWS.S3(config);
|
|
46
48
|
return storageClient;
|
|
47
49
|
};
|
|
48
50
|
return {
|
|
51
|
+
name: 's3',
|
|
49
52
|
generateURL: getGenerateURL({
|
|
50
53
|
bucket,
|
|
51
54
|
config
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload'\n\nimport * as AWS from '@aws-sdk/client-s3'\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport type S3StorageOptions = {\n /**\n * Access control list for uploaded files.\n */\n\n acl?: 'private' | 'public-read'\n /**\n * Bucket name to upload files to.\n *\n * Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).\n */\n\n bucket: string\n\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n /**\n * AWS S3 client configuration. Highly dependent on your AWS setup.\n *\n * [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)\n */\n config: AWS.S3ClientConfig\n\n /**\n * Whether or not to disable local storage\n *\n * @default true\n */\n disableLocalStorage?: boolean\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n}\n\ntype S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin\n\nexport const s3Storage: S3StoragePlugin =\n (s3StorageOptions: S3StorageOptions) =>\n (incomingConfig: Config): Config => {\n if (s3StorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = s3StorageInternal(s3StorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n s3StorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStoragePlugin({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction s3StorageInternal({ acl, bucket, config = {} }: S3StorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: AWS.S3 | null = null\n const getStorageClient: () => AWS.S3 = () => {\n if (storageClient) {\n return storageClient\n }\n storageClient = new AWS.S3(config)\n return storageClient\n }\n\n return {\n name: 's3',\n generateURL: getGenerateURL({ bucket, config }),\n handleDelete: getHandleDelete({ bucket, getStorageClient }),\n handleUpload: getHandleUpload({\n acl,\n bucket,\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection, getStorageClient }),\n }\n }\n}\n"],"names":["AWS","cloudStoragePlugin","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","s3Storage","s3StorageOptions","incomingConfig","enabled","adapter","s3StorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","acl","bucket","prefix","storageClient","getStorageClient","S3","name","generateURL","handleDelete","handleUpload","staticHandler"],"mappings":"AAQA,YAAYA,SAAS,qBAAoB;AACzC,SAASC,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AA4C/C,OAAO,MAAMC,YACX,CAACC,mBACD,CAACC;QACC,IAAID,iBAAiBE,OAAO,KAAK,OAAO;YACtC,OAAOD;QACT;QAEA,MAAME,UAAUC,kBAAkBJ;QAElC,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFP,iBAAiBQ,WAAW,EAC5BC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMU,SAAS;YACb,GAAGZ,cAAc;YACjBO,aAAa,AAACP,CAAAA,eAAeO,WAAW,IAAI,EAAE,AAAD,EAAGM,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACV,sBAAsB,CAACU,WAAWJ,IAAI,CAAC,EAAE;oBAC5C,OAAOI;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOvB,mBAAmB;YACxBc,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAAST,kBAAkB,EAAEc,GAAG,EAAEC,MAAM,EAAEN,SAAS,CAAC,CAAC,EAAoB;IACvE,OAAO,CAAC,EAAEE,UAAU,EAAEK,MAAM,EAAE;QAC5B,IAAIC,gBAA+B;QACnC,MAAMC,mBAAiC;YACrC,IAAID,eAAe;gBACjB,OAAOA;YACT;YACAA,gBAAgB,IAAI5B,IAAI8B,EAAE,CAACV;YAC3B,OAAOQ;QACT;QAEA,OAAO;YACLG,MAAM;YACNC,aAAa9B,eAAe;gBAAEwB;gBAAQN;YAAO;YAC7Ca,cAAc9B,gBAAgB;gBAAEuB;gBAAQG;YAAiB;YACzDK,cAAc9B,gBAAgB;gBAC5BqB;gBACAC;gBACAJ;gBACAO;gBACAF;YACF;YACAQ,eAAe9B,WAAW;gBAAEqB;gBAAQJ;gBAAYO;YAAiB;QACnE;IACF;AACF"}
|
package/dist/staticHandler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type * as AWS from '@aws-sdk/client-s3';
|
|
2
2
|
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { CollectionConfig } from 'payload
|
|
3
|
+
import type { CollectionConfig } from 'payload';
|
|
4
4
|
interface Args {
|
|
5
5
|
bucket: string;
|
|
6
6
|
collection: CollectionConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,oBAAoB,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK/C,UAAU,IAAI;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,GAAG,CAAC,EAAE,CAAA;CAC/B;AAYD,eAAO,MAAM,UAAU,6CAA8C,IAAI,KAAG,aA8B3E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type * as AWS from '@aws-sdk/client-s3'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\n\ninterface Args {\n bucket: string\n collection: CollectionConfig\n getStorageClient: () => AWS.S3\n}\n\n// Convert a stream into a promise that resolves with a Buffer\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst streamToBuffer = async (readableStream: any) => {\n const chunks = []\n for await (const chunk of readableStream) {\n chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk)\n }\n return Buffer.concat(chunks)\n}\n\nexport const getHandler = ({ bucket, collection, getStorageClient }: Args): StaticHandler => {\n return async (req, { params: { filename } }) => {\n try {\n const prefix = await getFilePrefix({ collection, filename, req })\n\n const object = await getStorageClient().getObject({\n Bucket: bucket,\n Key: path.posix.join(prefix, filename),\n })\n\n if (!object.Body) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const bodyBuffer = await streamToBuffer(object.Body)\n\n return new Response(bodyBuffer, {\n headers: new Headers({\n 'Accept-Ranges': String(object.AcceptRanges),\n 'Content-Length': String(object.ContentLength),\n 'Content-Type': String(object.ContentType),\n ETag: String(object.ETag),\n }),\n status: 200,\n })\n } catch (err) {\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getFilePrefix","path","streamToBuffer","readableStream","chunks","chunk","push","Buffer","from","concat","getHandler","bucket","collection","getStorageClient","req","params","filename","prefix","object","getObject","Bucket","Key","posix","join","Body","Response","status","statusText","bodyBuffer","headers","Headers","String","AcceptRanges","ContentLength","ContentType","ETag","err","payload","logger","error"],"mappings":"AAIA,SAASA,aAAa,QAAQ,6CAA4C;AAC1E,OAAOC,UAAU,OAAM;AAQvB,8DAA8D;AAC9D,8DAA8D;AAC9D,MAAMC,iBAAiB,OAAOC;IAC5B,MAAMC,SAAS,EAAE;IACjB,WAAW,MAAMC,SAASF,eAAgB;QACxCC,OAAOE,IAAI,CAAC,OAAOD,UAAU,WAAWE,OAAOC,IAAI,CAACH,SAASA;IAC/D;IACA,OAAOE,OAAOE,MAAM,CAACL;AACvB;AAEA,OAAO,MAAMM,aAAa,CAAC,EAAEC,MAAM,EAAEC,UAAU,EAAEC,gBAAgB,EAAQ;IACvE,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAE;QACzC,IAAI;YACF,MAAMC,SAAS,MAAMjB,cAAc;gBAAEY;gBAAYI;gBAAUF;YAAI;YAE/D,MAAMI,SAAS,MAAML,mBAAmBM,SAAS,CAAC;gBAChDC,QAAQT;gBACRU,KAAKpB,KAAKqB,KAAK,CAACC,IAAI,CAACN,QAAQD;YAC/B;YAEA,IAAI,CAACE,OAAOM,IAAI,EAAE;gBAChB,OAAO,IAAIC,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAY;YACnE;YAEA,MAAMC,aAAa,MAAM1B,eAAegB,OAAOM,IAAI;YAEnD,OAAO,IAAIC,SAASG,YAAY;gBAC9BC,SAAS,IAAIC,QAAQ;oBACnB,iBAAiBC,OAAOb,OAAOc,YAAY;oBAC3C,kBAAkBD,OAAOb,OAAOe,aAAa;oBAC7C,gBAAgBF,OAAOb,OAAOgB,WAAW;oBACzCC,MAAMJ,OAAOb,OAAOiB,IAAI;gBAC1B;gBACAT,QAAQ;YACV;QACF,EAAE,OAAOU,KAAK;YACZtB,IAAIuB,OAAO,CAACC,MAAM,CAACC,KAAK,CAACH;YACzB,OAAO,IAAIX,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,47 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-s3",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.130",
|
|
4
4
|
"description": "Payload storage adapter for Amazon S3",
|
|
5
|
+
"homepage": "https://payloadcms.com",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/payloadcms/payload.git",
|
|
8
9
|
"directory": "packages/storage-s3"
|
|
9
10
|
},
|
|
10
11
|
"license": "MIT",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
13
|
+
"maintainers": [
|
|
14
|
+
{
|
|
15
|
+
"name": "Payload",
|
|
16
|
+
"email": "info@payloadcms.com",
|
|
17
|
+
"url": "https://payloadcms.com"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
15
20
|
"type": "module",
|
|
16
21
|
"exports": {
|
|
17
22
|
".": {
|
|
18
23
|
"import": "./dist/index.js",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
21
26
|
}
|
|
22
27
|
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
23
33
|
"dependencies": {
|
|
24
|
-
"@aws-sdk/client-s3": "^3.
|
|
25
|
-
"@aws-sdk/lib-storage": "^3.
|
|
26
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.
|
|
34
|
+
"@aws-sdk/client-s3": "^3.614.0",
|
|
35
|
+
"@aws-sdk/lib-storage": "^3.614.0",
|
|
36
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.130"
|
|
27
37
|
},
|
|
28
38
|
"devDependencies": {
|
|
29
|
-
"payload": "3.0.0-beta.
|
|
39
|
+
"payload": "3.0.0-beta.130"
|
|
30
40
|
},
|
|
31
41
|
"peerDependencies": {
|
|
32
|
-
"payload": "3.0.0-beta.
|
|
42
|
+
"payload": "3.0.0-beta.130"
|
|
33
43
|
},
|
|
34
44
|
"engines": {
|
|
35
|
-
"node": "
|
|
45
|
+
"node": "^18.20.2 || >=20.9.0"
|
|
36
46
|
},
|
|
37
|
-
"files": [
|
|
38
|
-
"dist"
|
|
39
|
-
],
|
|
40
47
|
"scripts": {
|
|
41
|
-
"build": "pnpm build:
|
|
42
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
43
|
-
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
48
|
+
"build": "pnpm build:types && pnpm build:swc",
|
|
44
49
|
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
45
|
-
"
|
|
50
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
51
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
52
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"lint:fix": "eslint . --fix"
|
|
46
55
|
}
|
|
47
56
|
}
|