@payloadcms/storage-s3 3.0.0-alpha.63 → 3.0.0-alpha.64
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/package.json +4 -4
- package/src/index.ts +0 -109
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-s3",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.64",
|
|
4
4
|
"description": "Payload storage adapter for Amazon S3",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-alpha.
|
|
24
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-alpha.64"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@aws-sdk/client-s3": "^3.525.0",
|
|
28
28
|
"@aws-sdk/lib-storage": "^3.525.0",
|
|
29
|
-
"payload": "3.0.0-alpha.
|
|
29
|
+
"payload": "3.0.0-alpha.64"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"payload": "3.0.0-alpha.
|
|
32
|
+
"payload": "3.0.0-alpha.64"
|
|
33
33
|
},
|
|
34
34
|
"engines": {
|
|
35
35
|
"node": ">=18.20.2"
|
package/src/index.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Adapter,
|
|
3
|
-
PluginOptions as CloudStoragePluginOptions,
|
|
4
|
-
CollectionOptions,
|
|
5
|
-
GeneratedAdapter,
|
|
6
|
-
} from '@payloadcms/plugin-cloud-storage/types'
|
|
7
|
-
import type { Config, Plugin } from 'payload/config'
|
|
8
|
-
|
|
9
|
-
import * as AWS from '@aws-sdk/client-s3'
|
|
10
|
-
import { cloudStorage } from '@payloadcms/plugin-cloud-storage'
|
|
11
|
-
|
|
12
|
-
import { getGenerateURL } from './generateURL.js'
|
|
13
|
-
import { getHandleDelete } from './handleDelete.js'
|
|
14
|
-
import { getHandleUpload } from './handleUpload.js'
|
|
15
|
-
import { getHandler } from './staticHandler.js'
|
|
16
|
-
|
|
17
|
-
export type S3StorageOptions = {
|
|
18
|
-
/**
|
|
19
|
-
* Access control list for uploaded files.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
acl?: 'private' | 'public-read'
|
|
23
|
-
/**
|
|
24
|
-
* Bucket name to upload files to.
|
|
25
|
-
*
|
|
26
|
-
* Must follow [AWS S3 bucket naming conventions](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html).
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
bucket: string
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Collection options to apply the S3 adapter to.
|
|
33
|
-
*/
|
|
34
|
-
collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>
|
|
35
|
-
/**
|
|
36
|
-
* AWS S3 client configuration. Highly dependent on your AWS setup.
|
|
37
|
-
*
|
|
38
|
-
* [AWS.S3ClientConfig Docs](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html)
|
|
39
|
-
*/
|
|
40
|
-
config: AWS.S3ClientConfig
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Whether or not to disable local storage
|
|
44
|
-
*
|
|
45
|
-
* @default true
|
|
46
|
-
*/
|
|
47
|
-
disableLocalStorage?: boolean
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Whether or not to enable the plugin
|
|
51
|
-
*
|
|
52
|
-
* Default: true
|
|
53
|
-
*/
|
|
54
|
-
enabled?: boolean
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
type S3StoragePlugin = (storageS3Args: S3StorageOptions) => Plugin
|
|
58
|
-
|
|
59
|
-
export const s3Storage: S3StoragePlugin =
|
|
60
|
-
(s3StorageOptions: S3StorageOptions) =>
|
|
61
|
-
(incomingConfig: Config): Config => {
|
|
62
|
-
if (s3StorageOptions.enabled === false) {
|
|
63
|
-
return incomingConfig
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const adapter = s3StorageInternal(s3StorageOptions)
|
|
67
|
-
|
|
68
|
-
// Add adapter to each collection option object
|
|
69
|
-
const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(
|
|
70
|
-
s3StorageOptions.collections,
|
|
71
|
-
).reduce(
|
|
72
|
-
(acc, [slug, collOptions]) => ({
|
|
73
|
-
...acc,
|
|
74
|
-
[slug]: {
|
|
75
|
-
...(collOptions === true ? {} : collOptions),
|
|
76
|
-
adapter,
|
|
77
|
-
},
|
|
78
|
-
}),
|
|
79
|
-
{} as Record<string, CollectionOptions>,
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
return cloudStorage({
|
|
83
|
-
collections: collectionsWithAdapter,
|
|
84
|
-
})(incomingConfig)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function s3StorageInternal({ acl, bucket, config = {} }: S3StorageOptions): Adapter {
|
|
88
|
-
return ({ collection, prefix }): GeneratedAdapter => {
|
|
89
|
-
let storageClient: AWS.S3 | null = null
|
|
90
|
-
const getStorageClient: () => AWS.S3 = () => {
|
|
91
|
-
if (storageClient) return storageClient
|
|
92
|
-
storageClient = new AWS.S3(config)
|
|
93
|
-
return storageClient
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
generateURL: getGenerateURL({ bucket, config }),
|
|
98
|
-
handleDelete: getHandleDelete({ bucket, getStorageClient }),
|
|
99
|
-
handleUpload: getHandleUpload({
|
|
100
|
-
acl,
|
|
101
|
-
bucket,
|
|
102
|
-
collection,
|
|
103
|
-
getStorageClient,
|
|
104
|
-
prefix,
|
|
105
|
-
}),
|
|
106
|
-
staticHandler: getHandler({ bucket, collection, getStorageClient }),
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|