@payloadcms/plugin-cloud-storage 1.0.15 → 1.0.17-beta.0

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.
Files changed (214) hide show
  1. package/.editorconfig +10 -10
  2. package/.eslintrc.js +14 -14
  3. package/.gitignore +248 -248
  4. package/.prettierignore +1 -1
  5. package/.prettierrc.js +8 -8
  6. package/.vscode/launch.json +40 -28
  7. package/.vscode/settings.json +9 -9
  8. package/LICENSE.md +22 -22
  9. package/README.md +196 -178
  10. package/azure.d.ts +1 -1
  11. package/azure.js +1 -1
  12. package/dev/.env +11 -15
  13. package/dev/.env.example +21 -21
  14. package/dev/nodemon.json +8 -8
  15. package/dev/package.json +34 -32
  16. package/dev/src/collections/Media.ts +56 -56
  17. package/dev/src/collections/Users.ts +23 -23
  18. package/dev/src/mocks/fsMock.js +1 -1
  19. package/dev/src/mocks/promisifyMock.js +1 -1
  20. package/dev/src/payload.config.ts +111 -111
  21. package/dev/src/server.ts +26 -26
  22. package/dev/tsconfig.json +20 -20
  23. package/dist/adapters/azure/fileStub.d.ts +2 -2
  24. package/dist/adapters/azure/fileStub.js +3 -3
  25. package/dist/adapters/azure/generateURL.d.ts +7 -7
  26. package/dist/adapters/azure/generateURL.js +15 -15
  27. package/dist/adapters/azure/handleDelete.d.ts +9 -9
  28. package/dist/adapters/azure/handleDelete.js +63 -63
  29. package/dist/adapters/azure/handleUpload.d.ts +10 -10
  30. package/dist/adapters/azure/handleUpload.js +80 -80
  31. package/dist/adapters/azure/index.d.ts +8 -8
  32. package/dist/adapters/azure/index.js +42 -42
  33. package/dist/adapters/azure/index.js.map +1 -1
  34. package/dist/adapters/azure/mock.d.ts +13 -13
  35. package/dist/adapters/azure/mock.js +12 -12
  36. package/dist/adapters/azure/staticHandler.d.ts +9 -9
  37. package/dist/adapters/azure/staticHandler.js +81 -81
  38. package/dist/adapters/azure/webpack.d.ts +2 -2
  39. package/dist/adapters/azure/webpack.js +24 -24
  40. package/dist/adapters/azure/webpack.js.map +1 -1
  41. package/dist/adapters/gcs/generateURL.d.ts +8 -8
  42. package/dist/adapters/gcs/generateURL.js +15 -15
  43. package/dist/adapters/gcs/handleDelete.d.ts +8 -8
  44. package/dist/adapters/gcs/handleDelete.js +62 -62
  45. package/dist/adapters/gcs/handleUpload.d.ts +12 -12
  46. package/dist/adapters/gcs/handleUpload.js +72 -72
  47. package/dist/adapters/gcs/index.d.ts +8 -8
  48. package/dist/adapters/gcs/index.js +35 -35
  49. package/dist/adapters/gcs/mock.d.ts +1 -1
  50. package/dist/adapters/gcs/mock.js +4 -4
  51. package/dist/adapters/gcs/staticHandler.d.ts +10 -10
  52. package/dist/adapters/gcs/staticHandler.js +76 -76
  53. package/dist/adapters/gcs/webpack.d.ts +2 -2
  54. package/dist/adapters/gcs/webpack.js +24 -24
  55. package/dist/adapters/gcs/webpack.js.map +1 -1
  56. package/dist/adapters/s3/fileStub.d.ts +2 -2
  57. package/dist/adapters/s3/fileStub.js +3 -3
  58. package/dist/adapters/s3/generateURL.d.ts +8 -8
  59. package/dist/adapters/s3/generateURL.js +15 -15
  60. package/dist/adapters/s3/handleDelete.d.ts +8 -8
  61. package/dist/adapters/s3/handleDelete.js +63 -63
  62. package/dist/adapters/s3/handleUpload.d.ts +12 -12
  63. package/dist/adapters/s3/handleUpload.js +93 -93
  64. package/dist/adapters/s3/index.d.ts +8 -8
  65. package/dist/adapters/s3/index.js +59 -59
  66. package/dist/adapters/s3/mock.d.ts +8 -8
  67. package/dist/adapters/s3/mock.js +9 -9
  68. package/dist/adapters/s3/staticHandler.d.ts +10 -10
  69. package/dist/adapters/s3/staticHandler.js +81 -80
  70. package/dist/adapters/s3/staticHandler.js.map +1 -1
  71. package/dist/adapters/s3/webpack.d.ts +2 -2
  72. package/dist/adapters/s3/webpack.js +24 -24
  73. package/dist/adapters/s3/webpack.js.map +1 -1
  74. package/dist/fields/getFields.d.ts +11 -11
  75. package/dist/fields/getFields.js +118 -118
  76. package/dist/hooks/afterDelete.d.ts +10 -10
  77. package/dist/hooks/afterDelete.js +91 -88
  78. package/dist/hooks/afterDelete.js.map +1 -1
  79. package/dist/hooks/afterRead.d.ts +12 -12
  80. package/dist/hooks/afterRead.js +79 -79
  81. package/dist/hooks/beforeChange.d.ts +10 -10
  82. package/dist/hooks/beforeChange.js +105 -77
  83. package/dist/hooks/beforeChange.js.map +1 -1
  84. package/dist/index.d.ts +1 -1
  85. package/dist/index.js +5 -5
  86. package/dist/plugin.d.ts +3 -3
  87. package/dist/plugin.js +130 -124
  88. package/dist/plugin.js.map +1 -1
  89. package/dist/types.d.ts +68 -62
  90. package/dist/types.js +2 -2
  91. package/dist/utilities/getFilePrefix.d.ts +5 -5
  92. package/dist/utilities/getFilePrefix.js +80 -80
  93. package/dist/utilities/getIncomingFiles.d.ts +7 -7
  94. package/dist/utilities/getIncomingFiles.js +37 -37
  95. package/dist/utilities/getRangeFromHeader.d.ts +6 -6
  96. package/dist/utilities/getRangeFromHeader.js +66 -66
  97. package/dist/webpack.d.ts +9 -9
  98. package/dist/webpack.js +39 -39
  99. package/docs/local-dev.md +47 -47
  100. package/eslint-config/index.js +15 -15
  101. package/eslint-config/rules/import.js +38 -38
  102. package/eslint-config/rules/prettier.js +7 -7
  103. package/eslint-config/rules/style.js +21 -21
  104. package/eslint-config/rules/typescript.js +628 -628
  105. package/gcs.d.ts +1 -1
  106. package/gcs.js +1 -1
  107. package/package.json +67 -67
  108. package/s3.d.ts +1 -1
  109. package/s3.js +1 -1
  110. package/src/adapters/azure/emulator/docker-compose.yml +16 -16
  111. package/src/adapters/azure/fileStub.js +1 -1
  112. package/src/adapters/azure/generateURL.ts +13 -13
  113. package/src/adapters/azure/handleDelete.ts +16 -16
  114. package/src/adapters/azure/handleUpload.ts +41 -41
  115. package/src/adapters/azure/index.ts +48 -47
  116. package/src/adapters/azure/mock.js +13 -13
  117. package/src/adapters/azure/staticHandler.ts +38 -38
  118. package/src/adapters/azure/webpack.ts +24 -20
  119. package/src/adapters/gcs/emulator/docker-compose.yml +15 -15
  120. package/src/adapters/gcs/generateURL.ts +16 -16
  121. package/src/adapters/gcs/handleDelete.ts +16 -16
  122. package/src/adapters/gcs/handleUpload.ts +34 -34
  123. package/src/adapters/gcs/index.ts +37 -37
  124. package/src/adapters/gcs/mock.js +3 -3
  125. package/src/adapters/gcs/staticHandler.ts +34 -34
  126. package/src/adapters/gcs/webpack.ts +21 -17
  127. package/src/adapters/s3/emulator/.localstack/cache/machine.json +1 -0
  128. package/src/adapters/s3/emulator/.localstack/cache/server.test.pem +127 -0
  129. package/src/adapters/s3/emulator/.localstack/cache/server.test.pem.crt +99 -0
  130. package/src/adapters/s3/emulator/.localstack/cache/server.test.pem.key +28 -0
  131. package/src/adapters/s3/emulator/.localstack/cache/service-catalog-2_1_1_dev-1_29_149.pickle +0 -0
  132. package/src/adapters/s3/emulator/docker-compose.yml +15 -15
  133. package/src/adapters/s3/generateURL.ts +14 -14
  134. package/src/adapters/s3/handleDelete.ts +17 -17
  135. package/src/adapters/s3/index.ts +38 -38
  136. package/src/adapters/s3/mock.js +9 -9
  137. package/src/adapters/s3/staticHandler.ts +41 -40
  138. package/src/adapters/s3/webpack.ts +4 -0
  139. package/src/fields/getFields.ts +155 -155
  140. package/src/hooks/afterDelete.ts +35 -35
  141. package/src/hooks/afterRead.ts +38 -38
  142. package/src/hooks/beforeChange.ts +59 -30
  143. package/src/index.ts +1 -1
  144. package/src/plugin.ts +101 -94
  145. package/src/types.ts +79 -73
  146. package/src/utilities/getFilePrefix.ts +26 -26
  147. package/src/utilities/getIncomingFiles.ts +44 -44
  148. package/src/utilities/getRangeFromHeader.ts +27 -27
  149. package/src/webpack.ts +46 -46
  150. package/tsconfig.json +23 -23
  151. package/yarn-error.log +8163 -0
  152. package/yarn.lock +8062 -8155
  153. package/.idea/.gitignore +0 -5
  154. package/.idea/httpRequests/2023-04-07T152957.206.png +0 -0
  155. package/.idea/httpRequests/2023-04-07T153025.403.html +0 -10
  156. package/.idea/httpRequests/2023-04-07T153146.200.png +0 -0
  157. package/.idea/httpRequests/http-client.cookies +0 -1
  158. package/.idea/httpRequests/http-requests-log.http +0 -74
  159. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  160. package/.idea/jsLinters/eslint.xml +0 -6
  161. package/.idea/modules.xml +0 -8
  162. package/.idea/plugin-cloud-storage.iml +0 -12
  163. package/.idea/vcs.xml +0 -6
  164. package/.idea/workspace.xml +0 -269
  165. package/dev/build/127.d2c2ffcfff69fabfdd1b.js +0 -1
  166. package/dev/build/16.17dbe03b1d0a96f3e564.js +0 -2
  167. package/dev/build/16.17dbe03b1d0a96f3e564.js.LICENSE.txt +0 -8
  168. package/dev/build/171.bbcbae3ea90468ad0cad.js +0 -2
  169. package/dev/build/171.bbcbae3ea90468ad0cad.js.LICENSE.txt +0 -8
  170. package/dev/build/18.e50c27edff6716f930d9.js +0 -1
  171. package/dev/build/205.33c7a29683ba98de93e0.js +0 -1
  172. package/dev/build/2211c49456cd07331ea9.woff +0 -0
  173. package/dev/build/234.79395f82c18207c13766.js +0 -1
  174. package/dev/build/266.9d4a240b3e0985bd7dd5.js +0 -1
  175. package/dev/build/296.4c5d646257b42c915834.js +0 -1
  176. package/dev/build/304.40dbe690de322c8f7c0d.js +0 -2
  177. package/dev/build/304.40dbe690de322c8f7c0d.js.LICENSE.txt +0 -37
  178. package/dev/build/349.446c12bffd3905085fdb.js +0 -1
  179. package/dev/build/354.5acd04b85b96a9839125.js +0 -1
  180. package/dev/build/40ad7515b8674bb854a1.woff2 +0 -0
  181. package/dev/build/422.086542466cdc9f6a2437.js +0 -2
  182. package/dev/build/422.086542466cdc9f6a2437.js.LICENSE.txt +0 -6
  183. package/dev/build/491.0bfe1bb0ecfe383179aa.js +0 -1
  184. package/dev/build/4d8845b830f4e8e2affb.png +0 -0
  185. package/dev/build/51922ceb71da289688d3.woff2 +0 -0
  186. package/dev/build/522443364fda49e9e0ed.woff2 +0 -0
  187. package/dev/build/531.1c6f53f3b44a3c45b444.js +0 -2
  188. package/dev/build/531.1c6f53f3b44a3c45b444.js.LICENSE.txt +0 -6
  189. package/dev/build/570.f2d9b99706765fbf0225.js +0 -1
  190. package/dev/build/599.570a04990d5806004f61.js +0 -1
  191. package/dev/build/5b718d9772de251a8c0a.woff2 +0 -0
  192. package/dev/build/778.41ae26bcd617861ad586.js +0 -1
  193. package/dev/build/783.0117995f2ff6036d6746.js +0 -1
  194. package/dev/build/787999a6af6a17efbc7c.woff +0 -0
  195. package/dev/build/78b8935fb481e11c92ce.woff +0 -0
  196. package/dev/build/860.7688681d3269f3f16e9a.js +0 -1
  197. package/dev/build/892.1a4ca5ac67d81038ceec.js +0 -1
  198. package/dev/build/896.d8cb1160388dc29d6364.js +0 -1
  199. package/dev/build/8b4ddd0d08500553efde.woff +0 -0
  200. package/dev/build/8f612153248094525d9d.woff +0 -0
  201. package/dev/build/995.cc11e738ff81a85821b4.js +0 -1
  202. package/dev/build/9c7dfd0036f7bd24b053.woff2 +0 -0
  203. package/dev/build/a1cfdc5b5250b7c4b481.woff2 +0 -0
  204. package/dev/build/d7aeda9e48ce098e7b48.woff +0 -0
  205. package/dev/build/e009f21405b4d7e89367.woff2 +0 -0
  206. package/dev/build/e7caa9e17af6ac87d182.woff +0 -0
  207. package/dev/build/ebcc1430049fddb274f8.svg +0 -15
  208. package/dev/build/efe8f6a3b46446cc9135.woff +0 -0
  209. package/dev/build/f53bb8d4b29adc903703.woff2 +0 -0
  210. package/dev/build/index.html +0 -1
  211. package/dev/build/main.a2003d502fbb9aaa3e8d.js +0 -2
  212. package/dev/build/main.a2003d502fbb9aaa3e8d.js.LICENSE.txt +0 -57
  213. package/dev/build/styles.css +0 -1
  214. package/dev/build/styles.fa29d16b0baf5b98a1cf.js +0 -1
package/LICENSE.md CHANGED
@@ -1,22 +1,22 @@
1
- (The MIT License)
2
-
3
- Copyright (c) 2018-20223 Payload CMS, INC <info@payloadcms.com>
4
-
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
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
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.
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2018-20223 Payload CMS, INC <info@payloadcms.com>
4
+
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
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
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,178 +1,196 @@
1
- # Payload Cloud Storage Plugin
2
-
3
- This repository contains the officially supported Payload Cloud Storage plugin. It extends Payload to allow you to store all uploaded media in third-party permanent storage.
4
-
5
- #### Requirements
6
-
7
- - Payload version `1.0.19` or higher is required
8
-
9
- ## Installation
10
-
11
- `yarn add @payloadcms/plugin-cloud-storage` or `npm install @payloadcms/plugin-cloud-storage`
12
-
13
- ## Usage
14
-
15
- Add this package into your dependencies executing this code in your command line:
16
-
17
- `yarn add @payloadcms/plugin-cloud-storage`
18
-
19
- Now install this plugin within your Payload as follows:
20
-
21
- ```ts
22
- import { buildConfig } from 'payload/config';
23
- import path from 'path';
24
- import { cloudStorage } from '@payloadcms/plugin-cloud-storage';
25
-
26
- export default buildConfig({
27
- plugins: [
28
- cloudStorage({
29
- collections: {
30
- 'my-collection-slug': {
31
- adapter: theAdapterToUse, // see docs for the adapter you want to use
32
- },
33
- },
34
- }),
35
- ],
36
- // The rest of your config goes here
37
- });
38
- ```
39
-
40
- ## Features
41
-
42
- **Adapter-based Implementation**
43
-
44
- This plugin supports the following adapters:
45
-
46
- - [Azure Blob Storage](#azure-blob-storage-adapter)
47
- - [AWS S3-style Storage](#s3-adapter)
48
- - [Google Cloud Storage](#gcs-adapter)
49
-
50
- However, you can create your own adapter for any third-party service you would like to use.
51
-
52
- All adapters are implemented `dev` directory's [Payload Config](https://github.com/payloadcms/plugin-cloud-storage/blob/master/dev/src/payload.config.ts). See this file for examples.
53
-
54
- ## Plugin options
55
-
56
- This plugin is configurable to work across many different Payload collections. A `*` denotes that the property is required.
57
-
58
- | Option | Type | Description |
59
- |-------------------------|-----------------------------------------| ----------- |
60
- | `collections` * | Record<string, [CollectionOptions](https://github.com/payloadcms/plugin-cloud-storage/blob/c4a492a62abc2f21b4cd6a7c97778acd8e831212/src/types.ts#L48)> | Object with keys set to the slug of collections you want to enable the plugin for, and values set to collection-specific options. |
61
-
62
- **Collection-specific options:**
63
-
64
- | Option | Type | Description |
65
- |-------------------------------|----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
66
- | `adapter` * | [Adapter](https://github.com/payloadcms/plugin-cloud-storage/blob/master/src/types.ts#L51) | Pass in the adapter that you'd like to use for this collection. You can also set this field to `null` for local development if you'd like to bypass cloud storage in certain scenarios and use local storage. |
67
- | `disableLocalStorage` | `boolean` | Choose to disable local storage on this collection. Defaults to `true`. |
68
- | `disablePayloadAccessControl` | `true` | Set to `true` to disable Payload's access control. [More](#payload-access-control) |
69
- | `prefix` | `string` | Set to `media/images` to upload files inside `media/images` folder in the bucket. |
70
- | `generateFileURL` | [GenerateFileURL](https://github.com/payloadcms/plugin-cloud-storage/blob/master/src/types.ts#L53) | Override the generated file URL with one that you create. |
71
-
72
- ### Azure Blob Storage Adapter
73
-
74
- To use the Azure Blob Storage adapter, you need to have `@azure/storage-blob` installed in your project dependencies. To do so, run `yarn add @azure/storage-blob`.
75
-
76
- From there, create the adapter, passing in all of its required properties:
77
-
78
- ```js
79
- import { azureBlobStorageAdapter } from '@payloadcms/plugin-cloud-storage/azure';
80
-
81
- const adapter = azureBlobStorageAdapter({
82
- connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
83
- containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
84
- allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
85
- baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
86
- })
87
-
88
- // Now you can pass this adapter to the plugin
89
- ```
90
-
91
- ### S3 Adapter
92
-
93
- To use the S3 adapter, some peer dependencies need to be installed:
94
-
95
- `yarn add @aws-sdk/client-s3 @aws-sdk/lib-storage`.
96
-
97
- From there, create the adapter, passing in all of its required properties:
98
-
99
- ```js
100
- import { s3Adapter } from '@payloadcms/plugin-cloud-storage/s3';
101
-
102
- const adapter = s3Adapter({
103
- config: {
104
- credentials: {
105
- accessKeyId: process.env.S3_ACCESS_KEY_ID,
106
- secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
107
- }
108
- // ... Other S3 configuration
109
- },
110
- bucket: process.env.S3_BUCKET,
111
- })
112
-
113
- // Now you can pass this adapter to the plugin
114
- ```
115
-
116
- Other S3 Client configuration is documented [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html).
117
-
118
- Any upload over 50MB will automatically be uploaded using S3's multi-part upload.
119
-
120
- #### Other S3-Compatible Storage
121
-
122
- If you're running an S3-compatible object storage such as MinIO or Digital Ocean Spaces, you'll have to set the `endpoint` appropriately for the provider.
123
-
124
- ```js
125
- import { s3Adapter } from '@payloadcms/plugin-cloud-storage/s3';
126
-
127
- const adapter = s3Adapter({
128
- config: {
129
- endpoint: process.env.S3_ENDPOINT, // Configure for your provider
130
- // ...
131
- },
132
- // ...
133
- })
134
- ```
135
-
136
- ### GCS Adapter
137
-
138
- To use the GCS adapter, you need to have `@google-cloud/storage` installed in your project dependencies. To do so, run `yarn add @google-cloud/storage`.
139
-
140
- From there, create the adapter, passing in all of its required properties:
141
-
142
- ```js
143
- import { gcsAdapter } from '@payloadcms/plugin-cloud-storage/gcs';
144
-
145
- const adapter = gcsAdapter({
146
- options: {
147
- // you can choose any method for authentication, and authorization which is being provided by `@google-cloud/storage`
148
- keyFilename: './gcs-credentials.json',
149
- //OR
150
- credentials: JSON.parse(process.env.GCS_CREDENTIALS) // this env variable will have stringify version of your credentials.json file
151
- },
152
- bucket: process.env.GCS_BUCKET,
153
- })
154
-
155
- // Now you can pass this adapter to the plugin
156
- ```
157
-
158
- ### Payload Access Control
159
-
160
- Payload ships with access control that runs _even on statically served files_. The same `read` access control property on your `upload`-enabled collections is used, and it allows you to restrict who can request your uploaded files.
161
-
162
- To preserve this feature, by default, this plugin _keeps all file URLs exactly the same_. Your file URLs won't be updated to point directly to your cloud storage source, as in that case, Payload's access control will be completely bypassed and you would need public readability on your cloud-hosted files.
163
-
164
- Instead, all uploads will still be reached from the default `/collectionSlug/staticURL/filename` path. This plugin will "pass through" all files that are hosted on your third-party cloud service—with the added benefit of keeping your existing access control in place.
165
-
166
- If this does not apply to you (your upload collection has `read: () => true` or similar) you can disable this functionality by setting `disablePayloadAccessControl` to `true`. When this setting is in place, this plugin will update your file URLs to point directly to your cloud host.
167
-
168
- ## Local development
169
-
170
- For instructions regarding how to develop with this plugin locally, [click here](https://github.com/payloadcms/plugin-cloud-storage/blob/master/docs/local-dev.md).
171
-
172
- ## Questions
173
-
174
- Please contact [Payload](dev@payloadcms.com) with any questions about using this plugin.
175
-
176
- ## Credit
177
-
178
- This plugin was created with significant help, and code, from [Alex Bechmann](https://github.com/alexbechmann) and [Richard VanBergen](https://github.com/richardvanbergen). Thank you!!
1
+ # Payload Cloud Storage Plugin
2
+
3
+ This repository contains the officially supported Payload Cloud Storage plugin. It extends Payload to allow you to store all uploaded media in third-party permanent storage.
4
+
5
+ #### Requirements
6
+
7
+ - Payload version `1.0.19` or higher is required
8
+
9
+ ## Installation
10
+
11
+ `yarn add @payloadcms/plugin-cloud-storage` or `npm install @payloadcms/plugin-cloud-storage`
12
+
13
+ ## Usage
14
+
15
+ Add this package into your dependencies executing this code in your command line:
16
+
17
+ `yarn add @payloadcms/plugin-cloud-storage`
18
+
19
+ Now install this plugin within your Payload as follows:
20
+
21
+ ```ts
22
+ import { buildConfig } from 'payload/config';
23
+ import path from 'path';
24
+ import { cloudStorage } from '@payloadcms/plugin-cloud-storage';
25
+
26
+ export default buildConfig({
27
+ plugins: [
28
+ cloudStorage({
29
+ collections: {
30
+ 'my-collection-slug': {
31
+ adapter: theAdapterToUse, // see docs for the adapter you want to use
32
+ },
33
+ },
34
+ }),
35
+ ],
36
+ // The rest of your config goes here
37
+ });
38
+ ```
39
+
40
+ ### Conditionally Enabling/Disabling
41
+
42
+ The proper way to conditionally enable/disable this plugin is to use the `enabled` property.
43
+
44
+ ```ts
45
+ cloudStorage({
46
+ enabled: process.env.MY_CONDITION === 'true',
47
+ collections: {
48
+ 'my-collection-slug': {
49
+ adapter: theAdapterToUse, // see docs for the adapter you want to use
50
+ },
51
+ },
52
+ }),
53
+ ```
54
+
55
+ If the code is included *in any way in your config* but conditionally disabled in another fashion, you may run into issues such as `Webpack Build Error: Can't Resolve 'fs' and 'stream'` or similar because the plugin must be run at all times in order to properly extend the webpack config.
56
+
57
+ ## Features
58
+
59
+ **Adapter-based Implementation**
60
+
61
+ This plugin supports the following adapters:
62
+
63
+ - [Azure Blob Storage](#azure-blob-storage-adapter)
64
+ - [AWS S3-style Storage](#s3-adapter)
65
+ - [Google Cloud Storage](#gcs-adapter)
66
+
67
+ However, you can create your own adapter for any third-party service you would like to use.
68
+
69
+ All adapters are implemented `dev` directory's [Payload Config](https://github.com/payloadcms/plugin-cloud-storage/blob/master/dev/src/payload.config.ts). See this file for examples.
70
+
71
+ ## Plugin options
72
+
73
+ This plugin is configurable to work across many different Payload collections. A `*` denotes that the property is required.
74
+
75
+ | Option | Type | Description |
76
+ |-------------------------|-----------------------------------------| ----------- |
77
+ | `collections` * | Record<string, [CollectionOptions](https://github.com/payloadcms/plugin-cloud-storage/blob/c4a492a62abc2f21b4cd6a7c97778acd8e831212/src/types.ts#L48)> | Object with keys set to the slug of collections you want to enable the plugin for, and values set to collection-specific options. |
78
+ | `enabled` | | `boolean` to conditionally enable/disable plugin. Default: true. |
79
+
80
+ **Collection-specific options:**
81
+
82
+ | Option | Type | Description |
83
+ |-------------------------------|----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
84
+ | `adapter` * | [Adapter](https://github.com/payloadcms/plugin-cloud-storage/blob/master/src/types.ts#L51) | Pass in the adapter that you'd like to use for this collection. You can also set this field to `null` for local development if you'd like to bypass cloud storage in certain scenarios and use local storage. |
85
+ | `disableLocalStorage` | `boolean` | Choose to disable local storage on this collection. Defaults to `true`. |
86
+ | `disablePayloadAccessControl` | `true` | Set to `true` to disable Payload's access control. [More](#payload-access-control) |
87
+ | `prefix` | `string` | Set to `media/images` to upload files inside `media/images` folder in the bucket. |
88
+ | `generateFileURL` | [GenerateFileURL](https://github.com/payloadcms/plugin-cloud-storage/blob/master/src/types.ts#L53) | Override the generated file URL with one that you create. |
89
+
90
+ ### Azure Blob Storage Adapter
91
+
92
+ To use the Azure Blob Storage adapter, you need to have `@azure/storage-blob` installed in your project dependencies. To do so, run `yarn add @azure/storage-blob`.
93
+
94
+ From there, create the adapter, passing in all of its required properties:
95
+
96
+ ```js
97
+ import { azureBlobStorageAdapter } from '@payloadcms/plugin-cloud-storage/azure';
98
+
99
+ const adapter = azureBlobStorageAdapter({
100
+ connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
101
+ containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
102
+ allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
103
+ baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
104
+ })
105
+
106
+ // Now you can pass this adapter to the plugin
107
+ ```
108
+
109
+ ### S3 Adapter
110
+
111
+ To use the S3 adapter, some peer dependencies need to be installed:
112
+
113
+ `yarn add @aws-sdk/client-s3 @aws-sdk/lib-storage`.
114
+
115
+ From there, create the adapter, passing in all of its required properties:
116
+
117
+ ```js
118
+ import { s3Adapter } from '@payloadcms/plugin-cloud-storage/s3';
119
+
120
+ const adapter = s3Adapter({
121
+ config: {
122
+ credentials: {
123
+ accessKeyId: process.env.S3_ACCESS_KEY_ID,
124
+ secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
125
+ }
126
+ // ... Other S3 configuration
127
+ },
128
+ bucket: process.env.S3_BUCKET,
129
+ })
130
+
131
+ // Now you can pass this adapter to the plugin
132
+ ```
133
+
134
+ Other S3 Client configuration is documented [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/interfaces/s3clientconfig.html).
135
+
136
+ Any upload over 50MB will automatically be uploaded using S3's multi-part upload.
137
+
138
+ #### Other S3-Compatible Storage
139
+
140
+ If you're running an S3-compatible object storage such as MinIO or Digital Ocean Spaces, you'll have to set the `endpoint` appropriately for the provider.
141
+
142
+ ```js
143
+ import { s3Adapter } from '@payloadcms/plugin-cloud-storage/s3';
144
+
145
+ const adapter = s3Adapter({
146
+ config: {
147
+ endpoint: process.env.S3_ENDPOINT, // Configure for your provider
148
+ // ...
149
+ },
150
+ // ...
151
+ })
152
+ ```
153
+
154
+ ### GCS Adapter
155
+
156
+ To use the GCS adapter, you need to have `@google-cloud/storage` installed in your project dependencies. To do so, run `yarn add @google-cloud/storage`.
157
+
158
+ From there, create the adapter, passing in all of its required properties:
159
+
160
+ ```js
161
+ import { gcsAdapter } from '@payloadcms/plugin-cloud-storage/gcs';
162
+
163
+ const adapter = gcsAdapter({
164
+ options: {
165
+ // you can choose any method for authentication, and authorization which is being provided by `@google-cloud/storage`
166
+ keyFilename: './gcs-credentials.json',
167
+ //OR
168
+ credentials: JSON.parse(process.env.GCS_CREDENTIALS) // this env variable will have stringify version of your credentials.json file
169
+ },
170
+ bucket: process.env.GCS_BUCKET,
171
+ })
172
+
173
+ // Now you can pass this adapter to the plugin
174
+ ```
175
+
176
+ ### Payload Access Control
177
+
178
+ Payload ships with access control that runs *even on statically served files*. The same `read` access control property on your `upload`-enabled collections is used, and it allows you to restrict who can request your uploaded files.
179
+
180
+ To preserve this feature, by default, this plugin *keeps all file URLs exactly the same*. Your file URLs won't be updated to point directly to your cloud storage source, as in that case, Payload's access control will be completely bypassed and you would need public readability on your cloud-hosted files.
181
+
182
+ Instead, all uploads will still be reached from the default `/collectionSlug/staticURL/filename` path. This plugin will "pass through" all files that are hosted on your third-party cloud service—with the added benefit of keeping your existing access control in place.
183
+
184
+ If this does not apply to you (your upload collection has `read: () => true` or similar) you can disable this functionality by setting `disablePayloadAccessControl` to `true`. When this setting is in place, this plugin will update your file URLs to point directly to your cloud host.
185
+
186
+ ## Local development
187
+
188
+ For instructions regarding how to develop with this plugin locally, [click here](https://github.com/payloadcms/plugin-cloud-storage/blob/master/docs/local-dev.md).
189
+
190
+ ## Questions
191
+
192
+ Please contact [Payload](dev@payloadcms.com) with any questions about using this plugin.
193
+
194
+ ## Credit
195
+
196
+ This plugin was created with significant help, and code, from [Alex Bechmann](https://github.com/alexbechmann) and [Richard VanBergen](https://github.com/richardvanbergen). Thank you!!
package/azure.d.ts CHANGED
@@ -1 +1 @@
1
- export * from './dist/adapters/azure'
1
+ export * from './dist/adapters/azure'
package/azure.js CHANGED
@@ -1 +1 @@
1
- exports.azureBlobStorageAdapter = require('./dist/adapters/azure').azureBlobStorageAdapter
1
+ exports.azureBlobStorageAdapter = require('./dist/adapters/azure').azureBlobStorageAdapter
package/dev/.env CHANGED
@@ -1,25 +1,21 @@
1
- MONGODB_URI=mongodb://127.0.0.1/payload-plugin-cloud-storage
1
+ MONGODB_URI=mongodb://localhost/payload-plugin-cloud-storage
2
2
  PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
3
3
  PAYLOAD_SECRET=45ligj345ligj4wl5igj4lw5igj45ligj45wlijl
4
4
  PAYLOAD_CONFIG_PATH=src/payload.config.ts
5
5
 
6
- AZURE_STORAGE_CONNECTION_STRING=BlobEndpoint=https://testpayloadplugin999.blob.core.windows.net/;QueueEndpoint=https://testpayloadplugin999.queue.core.windows.net/;FileEndpoint=https://testpayloadplugin999.file.core.windows.net/;TableEndpoint=https://testpayloadplugin999.table.core.windows.net/;SharedAccessSignature=sv=2021-06-08&ss=bfqt&srt=co&sp=rwdlacupiytfx&se=2023-11-30T22:41:29Z&st=2022-08-08T13:41:29Z&spr=https&sig=rYvOxhnnKkHXkOK%2B16HfD5zOT2zj75GgQXvox16K%2B6Q%3D
7
- AZURE_STORAGE_CONTAINER_NAME=media
6
+ AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;
7
+ AZURE_STORAGE_CONTAINER_NAME=az-media
8
8
  AZURE_STORAGE_ALLOW_CONTAINER_CREATE=true
9
- AZURE_STORAGE_ACCOUNT_BASEURL=https://testpayloadplugin999.blob.core.windows.net/
9
+ AZURE_STORAGE_ACCOUNT_BASEURL=http://localhost:10000/devstoreaccount1
10
10
 
11
-
12
- S3_ENDPOINT=https://s3.amazonaws.com
13
-
14
- S3_ACCESS_KEY_ID=AKIAYSEO7NJYNX35SVGC
15
- S3_SECRET_ACCESS_KEY=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
16
- S3_BUCKET=plugin-cloud-storage-test
11
+ S3_ENDPOINT=http://localhost:4566
12
+ S3_ACCESS_KEY_ID=payloadAccessKey
13
+ S3_SECRET_ACCESS_KEY=alwiejglaiwhewlihgawe
14
+ S3_BUCKET=payload-bucket
17
15
  S3_FORCE_PATH_STYLE=true
18
16
 
19
- # GCS_ENDPOINT=http://127.0.0.1:4443
20
- GCS_ENDPOINT=https://storage.googleapis.com
21
- GCS_PROJECT_ID=my-project-72803-360420
22
- GCS_BUCKET=project-72803
23
-
17
+ GCS_ENDPOINT=http://localhost:4443
18
+ GCS_PROJECT_ID=test
19
+ GCS_BUCKET=payload-bucket
24
20
 
25
21
  PAYLOAD_DROP_DATABASE=true
package/dev/.env.example CHANGED
@@ -1,21 +1,21 @@
1
- MONGODB_URI=mongodb://localhost/payload-plugin-cloud-storage
2
- PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
3
- PAYLOAD_SECRET=45ligj345ligj4wl5igj4lw5igj45ligj45wlijl
4
- PAYLOAD_CONFIG_PATH=src/payload.config.ts
5
-
6
- AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;
7
- AZURE_STORAGE_CONTAINER_NAME=az-media
8
- AZURE_STORAGE_ALLOW_CONTAINER_CREATE=true
9
- AZURE_STORAGE_ACCOUNT_BASEURL=http://localhost:10000/devstoreaccount1
10
-
11
- S3_ENDPOINT=http://localhost:4566
12
- S3_ACCESS_KEY_ID=payloadAccessKey
13
- S3_SECRET_ACCESS_KEY=alwiejglaiwhewlihgawe
14
- S3_BUCKET=payload-bucket
15
- S3_FORCE_PATH_STYLE=true
16
-
17
- GCS_ENDPOINT=http://localhost:4443
18
- GCS_PROJECT_ID=test
19
- GCS_BUCKET=payload-bucket
20
-
21
- PAYLOAD_DROP_DATABASE=true
1
+ MONGODB_URI=mongodb://localhost/payload-plugin-cloud-storage
2
+ PAYLOAD_PUBLIC_SERVER_URL=http://localhost:3000
3
+ PAYLOAD_SECRET=45ligj345ligj4wl5igj4lw5igj45ligj45wlijl
4
+ PAYLOAD_CONFIG_PATH=src/payload.config.ts
5
+
6
+ AZURE_STORAGE_CONNECTION_STRING=DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://localhost:10000/devstoreaccount1;QueueEndpoint=http://localhost:10001/devstoreaccount1;
7
+ AZURE_STORAGE_CONTAINER_NAME=az-media
8
+ AZURE_STORAGE_ALLOW_CONTAINER_CREATE=true
9
+ AZURE_STORAGE_ACCOUNT_BASEURL=http://localhost:10000/devstoreaccount1
10
+
11
+ S3_ENDPOINT=http://localhost:4566
12
+ S3_ACCESS_KEY_ID=payloadAccessKey
13
+ S3_SECRET_ACCESS_KEY=alwiejglaiwhewlihgawe
14
+ S3_BUCKET=payload-bucket
15
+ S3_FORCE_PATH_STYLE=true
16
+
17
+ GCS_ENDPOINT=http://localhost:4443
18
+ GCS_PROJECT_ID=test
19
+ GCS_BUCKET=payload-bucket
20
+
21
+ PAYLOAD_DROP_DATABASE=true
package/dev/nodemon.json CHANGED
@@ -1,8 +1,8 @@
1
- {
2
- "ext": "ts",
3
- "exec": "ts-node src/server.ts",
4
- "watch": [
5
- "src/**/*.ts",
6
- "../src/**/*.ts"
7
- ]
8
- }
1
+ {
2
+ "ext": "ts",
3
+ "exec": "node --trace-warnings -r ts-node/register -r ./src/server.ts",
4
+ "watch": [
5
+ "src/**/*.ts",
6
+ "../src/**/*.ts"
7
+ ]
8
+ }
package/dev/package.json CHANGED
@@ -1,32 +1,34 @@
1
- {
2
- "name": "payload-plugin-cloud-storage-demo",
3
- "version": "1.0.0",
4
- "main": "dist/server.js",
5
- "license": "MIT",
6
- "private": true,
7
- "scripts": {
8
- "dev:azure": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=azure nodemon",
9
- "dev:s3": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=s3 nodemon",
10
- "dev:gcs": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=gcs nodemon",
11
- "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
12
- "build:server": "tsc",
13
- "build": "yarn build:payload && yarn build:server",
14
- "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
15
- "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
16
- },
17
- "dependencies": {
18
- "@aws-sdk/client-s3": "^3.142.0",
19
- "@azure/storage-blob": "^12.11.0",
20
- "@google-cloud/storage": "^6.4.2",
21
- "dotenv": "^8.2.0",
22
- "express": "^4.17.1",
23
- "payload": "^1.6.6"
24
- },
25
- "devDependencies": {
26
- "@types/express": "^4.17.9",
27
- "cross-env": "^7.0.3",
28
- "nodemon": "^2.0.6",
29
- "ts-node": "^9.1.1",
30
- "typescript": "^4.1.3"
31
- }
32
- }
1
+ {
2
+ "name": "payload-plugin-cloud-storage-demo",
3
+ "version": "1.0.0",
4
+ "main": "dist/server.js",
5
+ "license": "MIT",
6
+ "private": true,
7
+ "scripts": {
8
+ "dev:azure": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=azure nodemon",
9
+ "dev:s3": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=s3 nodemon",
10
+ "dev:gcs": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=gcs nodemon",
11
+ "build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
12
+ "build:server": "tsc",
13
+ "build": "yarn build:payload && yarn build:server",
14
+ "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js",
15
+ "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types"
16
+ },
17
+ "dependencies": {
18
+ "@aws-sdk/client-s3": "^3.142.0",
19
+ "@azure/storage-blob": "^12.11.0",
20
+ "@google-cloud/storage": "^6.4.2",
21
+ "dotenv": "^8.2.0",
22
+ "express": "^4.17.1",
23
+ "image-size": "^1.0.2",
24
+ "payload": "^1.7.2",
25
+ "probe-image-size": "^7.2.3"
26
+ },
27
+ "devDependencies": {
28
+ "@types/express": "^4.17.9",
29
+ "cross-env": "^7.0.3",
30
+ "nodemon": "^2.0.6",
31
+ "ts-node": "^9.1.1",
32
+ "typescript": "^4.1.3"
33
+ }
34
+ }