@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.
- package/.editorconfig +10 -10
- package/.eslintrc.js +14 -14
- package/.gitignore +248 -248
- package/.prettierignore +1 -1
- package/.prettierrc.js +8 -8
- package/.vscode/launch.json +40 -28
- package/.vscode/settings.json +9 -9
- package/LICENSE.md +22 -22
- package/README.md +196 -178
- package/azure.d.ts +1 -1
- package/azure.js +1 -1
- package/dev/.env +11 -15
- package/dev/.env.example +21 -21
- package/dev/nodemon.json +8 -8
- package/dev/package.json +34 -32
- package/dev/src/collections/Media.ts +56 -56
- package/dev/src/collections/Users.ts +23 -23
- package/dev/src/mocks/fsMock.js +1 -1
- package/dev/src/mocks/promisifyMock.js +1 -1
- package/dev/src/payload.config.ts +111 -111
- package/dev/src/server.ts +26 -26
- package/dev/tsconfig.json +20 -20
- package/dist/adapters/azure/fileStub.d.ts +2 -2
- package/dist/adapters/azure/fileStub.js +3 -3
- package/dist/adapters/azure/generateURL.d.ts +7 -7
- package/dist/adapters/azure/generateURL.js +15 -15
- package/dist/adapters/azure/handleDelete.d.ts +9 -9
- package/dist/adapters/azure/handleDelete.js +63 -63
- package/dist/adapters/azure/handleUpload.d.ts +10 -10
- package/dist/adapters/azure/handleUpload.js +80 -80
- package/dist/adapters/azure/index.d.ts +8 -8
- package/dist/adapters/azure/index.js +42 -42
- package/dist/adapters/azure/index.js.map +1 -1
- package/dist/adapters/azure/mock.d.ts +13 -13
- package/dist/adapters/azure/mock.js +12 -12
- package/dist/adapters/azure/staticHandler.d.ts +9 -9
- package/dist/adapters/azure/staticHandler.js +81 -81
- package/dist/adapters/azure/webpack.d.ts +2 -2
- package/dist/adapters/azure/webpack.js +24 -24
- package/dist/adapters/azure/webpack.js.map +1 -1
- package/dist/adapters/gcs/generateURL.d.ts +8 -8
- package/dist/adapters/gcs/generateURL.js +15 -15
- package/dist/adapters/gcs/handleDelete.d.ts +8 -8
- package/dist/adapters/gcs/handleDelete.js +62 -62
- package/dist/adapters/gcs/handleUpload.d.ts +12 -12
- package/dist/adapters/gcs/handleUpload.js +72 -72
- package/dist/adapters/gcs/index.d.ts +8 -8
- package/dist/adapters/gcs/index.js +35 -35
- package/dist/adapters/gcs/mock.d.ts +1 -1
- package/dist/adapters/gcs/mock.js +4 -4
- package/dist/adapters/gcs/staticHandler.d.ts +10 -10
- package/dist/adapters/gcs/staticHandler.js +76 -76
- package/dist/adapters/gcs/webpack.d.ts +2 -2
- package/dist/adapters/gcs/webpack.js +24 -24
- package/dist/adapters/gcs/webpack.js.map +1 -1
- package/dist/adapters/s3/fileStub.d.ts +2 -2
- package/dist/adapters/s3/fileStub.js +3 -3
- package/dist/adapters/s3/generateURL.d.ts +8 -8
- package/dist/adapters/s3/generateURL.js +15 -15
- package/dist/adapters/s3/handleDelete.d.ts +8 -8
- package/dist/adapters/s3/handleDelete.js +63 -63
- package/dist/adapters/s3/handleUpload.d.ts +12 -12
- package/dist/adapters/s3/handleUpload.js +93 -93
- package/dist/adapters/s3/index.d.ts +8 -8
- package/dist/adapters/s3/index.js +59 -59
- package/dist/adapters/s3/mock.d.ts +8 -8
- package/dist/adapters/s3/mock.js +9 -9
- package/dist/adapters/s3/staticHandler.d.ts +10 -10
- package/dist/adapters/s3/staticHandler.js +81 -80
- package/dist/adapters/s3/staticHandler.js.map +1 -1
- package/dist/adapters/s3/webpack.d.ts +2 -2
- package/dist/adapters/s3/webpack.js +24 -24
- package/dist/adapters/s3/webpack.js.map +1 -1
- package/dist/fields/getFields.d.ts +11 -11
- package/dist/fields/getFields.js +118 -118
- package/dist/hooks/afterDelete.d.ts +10 -10
- package/dist/hooks/afterDelete.js +91 -88
- package/dist/hooks/afterDelete.js.map +1 -1
- package/dist/hooks/afterRead.d.ts +12 -12
- package/dist/hooks/afterRead.js +79 -79
- package/dist/hooks/beforeChange.d.ts +10 -10
- package/dist/hooks/beforeChange.js +105 -77
- package/dist/hooks/beforeChange.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -5
- package/dist/plugin.d.ts +3 -3
- package/dist/plugin.js +130 -124
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +68 -62
- package/dist/types.js +2 -2
- package/dist/utilities/getFilePrefix.d.ts +5 -5
- package/dist/utilities/getFilePrefix.js +80 -80
- package/dist/utilities/getIncomingFiles.d.ts +7 -7
- package/dist/utilities/getIncomingFiles.js +37 -37
- package/dist/utilities/getRangeFromHeader.d.ts +6 -6
- package/dist/utilities/getRangeFromHeader.js +66 -66
- package/dist/webpack.d.ts +9 -9
- package/dist/webpack.js +39 -39
- package/docs/local-dev.md +47 -47
- package/eslint-config/index.js +15 -15
- package/eslint-config/rules/import.js +38 -38
- package/eslint-config/rules/prettier.js +7 -7
- package/eslint-config/rules/style.js +21 -21
- package/eslint-config/rules/typescript.js +628 -628
- package/gcs.d.ts +1 -1
- package/gcs.js +1 -1
- package/package.json +67 -67
- package/s3.d.ts +1 -1
- package/s3.js +1 -1
- package/src/adapters/azure/emulator/docker-compose.yml +16 -16
- package/src/adapters/azure/fileStub.js +1 -1
- package/src/adapters/azure/generateURL.ts +13 -13
- package/src/adapters/azure/handleDelete.ts +16 -16
- package/src/adapters/azure/handleUpload.ts +41 -41
- package/src/adapters/azure/index.ts +48 -47
- package/src/adapters/azure/mock.js +13 -13
- package/src/adapters/azure/staticHandler.ts +38 -38
- package/src/adapters/azure/webpack.ts +24 -20
- package/src/adapters/gcs/emulator/docker-compose.yml +15 -15
- package/src/adapters/gcs/generateURL.ts +16 -16
- package/src/adapters/gcs/handleDelete.ts +16 -16
- package/src/adapters/gcs/handleUpload.ts +34 -34
- package/src/adapters/gcs/index.ts +37 -37
- package/src/adapters/gcs/mock.js +3 -3
- package/src/adapters/gcs/staticHandler.ts +34 -34
- package/src/adapters/gcs/webpack.ts +21 -17
- package/src/adapters/s3/emulator/.localstack/cache/machine.json +1 -0
- package/src/adapters/s3/emulator/.localstack/cache/server.test.pem +127 -0
- package/src/adapters/s3/emulator/.localstack/cache/server.test.pem.crt +99 -0
- package/src/adapters/s3/emulator/.localstack/cache/server.test.pem.key +28 -0
- package/src/adapters/s3/emulator/.localstack/cache/service-catalog-2_1_1_dev-1_29_149.pickle +0 -0
- package/src/adapters/s3/emulator/docker-compose.yml +15 -15
- package/src/adapters/s3/generateURL.ts +14 -14
- package/src/adapters/s3/handleDelete.ts +17 -17
- package/src/adapters/s3/index.ts +38 -38
- package/src/adapters/s3/mock.js +9 -9
- package/src/adapters/s3/staticHandler.ts +41 -40
- package/src/adapters/s3/webpack.ts +4 -0
- package/src/fields/getFields.ts +155 -155
- package/src/hooks/afterDelete.ts +35 -35
- package/src/hooks/afterRead.ts +38 -38
- package/src/hooks/beforeChange.ts +59 -30
- package/src/index.ts +1 -1
- package/src/plugin.ts +101 -94
- package/src/types.ts +79 -73
- package/src/utilities/getFilePrefix.ts +26 -26
- package/src/utilities/getIncomingFiles.ts +44 -44
- package/src/utilities/getRangeFromHeader.ts +27 -27
- package/src/webpack.ts +46 -46
- package/tsconfig.json +23 -23
- package/yarn-error.log +8163 -0
- package/yarn.lock +8062 -8155
- package/.idea/.gitignore +0 -5
- package/.idea/httpRequests/2023-04-07T152957.206.png +0 -0
- package/.idea/httpRequests/2023-04-07T153025.403.html +0 -10
- package/.idea/httpRequests/2023-04-07T153146.200.png +0 -0
- package/.idea/httpRequests/http-client.cookies +0 -1
- package/.idea/httpRequests/http-requests-log.http +0 -74
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/plugin-cloud-storage.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/.idea/workspace.xml +0 -269
- package/dev/build/127.d2c2ffcfff69fabfdd1b.js +0 -1
- package/dev/build/16.17dbe03b1d0a96f3e564.js +0 -2
- package/dev/build/16.17dbe03b1d0a96f3e564.js.LICENSE.txt +0 -8
- package/dev/build/171.bbcbae3ea90468ad0cad.js +0 -2
- package/dev/build/171.bbcbae3ea90468ad0cad.js.LICENSE.txt +0 -8
- package/dev/build/18.e50c27edff6716f930d9.js +0 -1
- package/dev/build/205.33c7a29683ba98de93e0.js +0 -1
- package/dev/build/2211c49456cd07331ea9.woff +0 -0
- package/dev/build/234.79395f82c18207c13766.js +0 -1
- package/dev/build/266.9d4a240b3e0985bd7dd5.js +0 -1
- package/dev/build/296.4c5d646257b42c915834.js +0 -1
- package/dev/build/304.40dbe690de322c8f7c0d.js +0 -2
- package/dev/build/304.40dbe690de322c8f7c0d.js.LICENSE.txt +0 -37
- package/dev/build/349.446c12bffd3905085fdb.js +0 -1
- package/dev/build/354.5acd04b85b96a9839125.js +0 -1
- package/dev/build/40ad7515b8674bb854a1.woff2 +0 -0
- package/dev/build/422.086542466cdc9f6a2437.js +0 -2
- package/dev/build/422.086542466cdc9f6a2437.js.LICENSE.txt +0 -6
- package/dev/build/491.0bfe1bb0ecfe383179aa.js +0 -1
- package/dev/build/4d8845b830f4e8e2affb.png +0 -0
- package/dev/build/51922ceb71da289688d3.woff2 +0 -0
- package/dev/build/522443364fda49e9e0ed.woff2 +0 -0
- package/dev/build/531.1c6f53f3b44a3c45b444.js +0 -2
- package/dev/build/531.1c6f53f3b44a3c45b444.js.LICENSE.txt +0 -6
- package/dev/build/570.f2d9b99706765fbf0225.js +0 -1
- package/dev/build/599.570a04990d5806004f61.js +0 -1
- package/dev/build/5b718d9772de251a8c0a.woff2 +0 -0
- package/dev/build/778.41ae26bcd617861ad586.js +0 -1
- package/dev/build/783.0117995f2ff6036d6746.js +0 -1
- package/dev/build/787999a6af6a17efbc7c.woff +0 -0
- package/dev/build/78b8935fb481e11c92ce.woff +0 -0
- package/dev/build/860.7688681d3269f3f16e9a.js +0 -1
- package/dev/build/892.1a4ca5ac67d81038ceec.js +0 -1
- package/dev/build/896.d8cb1160388dc29d6364.js +0 -1
- package/dev/build/8b4ddd0d08500553efde.woff +0 -0
- package/dev/build/8f612153248094525d9d.woff +0 -0
- package/dev/build/995.cc11e738ff81a85821b4.js +0 -1
- package/dev/build/9c7dfd0036f7bd24b053.woff2 +0 -0
- package/dev/build/a1cfdc5b5250b7c4b481.woff2 +0 -0
- package/dev/build/d7aeda9e48ce098e7b48.woff +0 -0
- package/dev/build/e009f21405b4d7e89367.woff2 +0 -0
- package/dev/build/e7caa9e17af6ac87d182.woff +0 -0
- package/dev/build/ebcc1430049fddb274f8.svg +0 -15
- package/dev/build/efe8f6a3b46446cc9135.woff +0 -0
- package/dev/build/f53bb8d4b29adc903703.woff2 +0 -0
- package/dev/build/index.html +0 -1
- package/dev/build/main.a2003d502fbb9aaa3e8d.js +0 -2
- package/dev/build/main.a2003d502fbb9aaa3e8d.js.LICENSE.txt +0 -57
- package/dev/build/styles.css +0 -1
- package/dev/build/styles.fa29d16b0baf5b98a1cf.js +0 -1
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import type { CollectionConfig, Field } from 'payload/types'
|
|
3
|
-
|
|
4
|
-
const urlField: Field = {
|
|
5
|
-
name: 'url',
|
|
6
|
-
type: 'text',
|
|
7
|
-
hooks: {
|
|
8
|
-
afterRead: [
|
|
9
|
-
({ value }) => {
|
|
10
|
-
console.log('hello from hook')
|
|
11
|
-
return value
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const Media: CollectionConfig = {
|
|
18
|
-
slug: 'media',
|
|
19
|
-
upload: {
|
|
20
|
-
imageSizes: [
|
|
21
|
-
{
|
|
22
|
-
height: 400,
|
|
23
|
-
width: 400,
|
|
24
|
-
crop: 'center',
|
|
25
|
-
name: 'square',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
width: 900,
|
|
29
|
-
height: 450,
|
|
30
|
-
crop: 'center',
|
|
31
|
-
name: 'sixteenByNineMedium',
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
fields: [
|
|
36
|
-
{
|
|
37
|
-
name: 'alt',
|
|
38
|
-
label: 'Alt Text',
|
|
39
|
-
type: 'text',
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
// The following fields should be able to be merged in to default upload fields
|
|
43
|
-
urlField,
|
|
44
|
-
{
|
|
45
|
-
name: 'sizes',
|
|
46
|
-
type: 'group',
|
|
47
|
-
fields: [
|
|
48
|
-
{
|
|
49
|
-
name: 'square',
|
|
50
|
-
type: 'group',
|
|
51
|
-
fields: [urlField],
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
}
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import type { CollectionConfig, Field } from 'payload/types'
|
|
3
|
+
|
|
4
|
+
const urlField: Field = {
|
|
5
|
+
name: 'url',
|
|
6
|
+
type: 'text',
|
|
7
|
+
hooks: {
|
|
8
|
+
afterRead: [
|
|
9
|
+
({ value }) => {
|
|
10
|
+
console.log('hello from hook')
|
|
11
|
+
return value
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Media: CollectionConfig = {
|
|
18
|
+
slug: 'media',
|
|
19
|
+
upload: {
|
|
20
|
+
imageSizes: [
|
|
21
|
+
{
|
|
22
|
+
height: 400,
|
|
23
|
+
width: 400,
|
|
24
|
+
crop: 'center',
|
|
25
|
+
name: 'square',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
width: 900,
|
|
29
|
+
height: 450,
|
|
30
|
+
crop: 'center',
|
|
31
|
+
name: 'sixteenByNineMedium',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
fields: [
|
|
36
|
+
{
|
|
37
|
+
name: 'alt',
|
|
38
|
+
label: 'Alt Text',
|
|
39
|
+
type: 'text',
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// The following fields should be able to be merged in to default upload fields
|
|
43
|
+
urlField,
|
|
44
|
+
{
|
|
45
|
+
name: 'sizes',
|
|
46
|
+
type: 'group',
|
|
47
|
+
fields: [
|
|
48
|
+
{
|
|
49
|
+
name: 'square',
|
|
50
|
+
type: 'group',
|
|
51
|
+
fields: [urlField],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload/types'
|
|
2
|
-
|
|
3
|
-
const Users: CollectionConfig = {
|
|
4
|
-
slug: 'users',
|
|
5
|
-
auth: true,
|
|
6
|
-
access: {
|
|
7
|
-
read: () => true,
|
|
8
|
-
},
|
|
9
|
-
fields: [
|
|
10
|
-
{
|
|
11
|
-
name: 'avatar',
|
|
12
|
-
type: 'upload',
|
|
13
|
-
relationTo: 'media',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: 'background',
|
|
17
|
-
type: 'upload',
|
|
18
|
-
relationTo: 'media',
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default Users
|
|
1
|
+
import type { CollectionConfig } from 'payload/types'
|
|
2
|
+
|
|
3
|
+
const Users: CollectionConfig = {
|
|
4
|
+
slug: 'users',
|
|
5
|
+
auth: true,
|
|
6
|
+
access: {
|
|
7
|
+
read: () => true,
|
|
8
|
+
},
|
|
9
|
+
fields: [
|
|
10
|
+
{
|
|
11
|
+
name: 'avatar',
|
|
12
|
+
type: 'upload',
|
|
13
|
+
relationTo: 'media',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'background',
|
|
17
|
+
type: 'upload',
|
|
18
|
+
relationTo: 'media',
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default Users
|
package/dev/src/mocks/fsMock.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = { fs: { createReadStream: () => null } }
|
|
1
|
+
module.exports = { fs: { createReadStream: () => null } }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const promisify = () => {}
|
|
1
|
+
export const promisify = () => {}
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import { buildConfig } from 'payload/config'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
import Users from './collections/Users'
|
|
4
|
-
import { cloudStorage } from '../../src'
|
|
5
|
-
import { s3Adapter } from '../../src/adapters/s3'
|
|
6
|
-
import { gcsAdapter } from '../../src/adapters/gcs'
|
|
7
|
-
import { azureBlobStorageAdapter } from '../../src/adapters/azure'
|
|
8
|
-
import type { Adapter } from '../../src/types'
|
|
9
|
-
import { Media } from './collections/Media'
|
|
10
|
-
|
|
11
|
-
let adapter: Adapter
|
|
12
|
-
let uploadOptions
|
|
13
|
-
|
|
14
|
-
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'azure') {
|
|
15
|
-
adapter = azureBlobStorageAdapter({
|
|
16
|
-
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
|
|
17
|
-
containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
|
|
18
|
-
allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
|
|
19
|
-
baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
|
|
20
|
-
})
|
|
21
|
-
// uploadOptions = {
|
|
22
|
-
// useTempFiles: true,
|
|
23
|
-
// }
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 's3') {
|
|
27
|
-
// The s3 adapter supports using temp files for uploads
|
|
28
|
-
uploadOptions = {
|
|
29
|
-
useTempFiles: true,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
adapter = s3Adapter({
|
|
33
|
-
config: {
|
|
34
|
-
endpoint: process.env.S3_ENDPOINT,
|
|
35
|
-
forcePathStyle: process.env.S3_FORCE_PATH_STYLE === 'true',
|
|
36
|
-
region: process.env.S3_REGION,
|
|
37
|
-
credentials: {
|
|
38
|
-
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
|
39
|
-
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
bucket: process.env.S3_BUCKET,
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'gcs') {
|
|
47
|
-
adapter = gcsAdapter({
|
|
48
|
-
options: {
|
|
49
|
-
apiEndpoint: process.env.GCS_ENDPOINT,
|
|
50
|
-
projectId: process.env.GCS_PROJECT_ID,
|
|
51
|
-
},
|
|
52
|
-
bucket: process.env.GCS_BUCKET,
|
|
53
|
-
})
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default buildConfig({
|
|
57
|
-
serverURL: 'http://localhost:3000',
|
|
58
|
-
collections: [Media, Users],
|
|
59
|
-
upload: uploadOptions,
|
|
60
|
-
admin: {
|
|
61
|
-
// NOTE - these webpack extensions are only required
|
|
62
|
-
// for development of this plugin.
|
|
63
|
-
// No need to use these aliases within your own projects.
|
|
64
|
-
webpack: config => {
|
|
65
|
-
const newConfig = {
|
|
66
|
-
...config,
|
|
67
|
-
resolve: {
|
|
68
|
-
...(config.resolve || {}),
|
|
69
|
-
alias: {
|
|
70
|
-
...(config.resolve.alias || {}),
|
|
71
|
-
react: path.resolve(__dirname, '../node_modules/react'),
|
|
72
|
-
'@azure/storage-blob': path.resolve(__dirname, '../../src/adapters/azure/mock.js'),
|
|
73
|
-
'@aws-sdk/client-s3': path.resolve(__dirname, '../../src/adapters/s3/mock.js'),
|
|
74
|
-
'@google-cloud/storage': path.resolve(__dirname, '../../src/adapters/gcs/mock.js'),
|
|
75
|
-
fs: path.resolve(__dirname, './mocks/fsMock.js'),
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
}
|
|
79
|
-
return newConfig
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
typescript: {
|
|
83
|
-
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
|
84
|
-
},
|
|
85
|
-
plugins: [
|
|
86
|
-
// @ts-expect-error
|
|
87
|
-
cloudStorage({
|
|
88
|
-
collections: {
|
|
89
|
-
media: {
|
|
90
|
-
adapter,
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
}),
|
|
94
|
-
],
|
|
95
|
-
onInit: async payload => {
|
|
96
|
-
const users = await payload.find({
|
|
97
|
-
collection: 'users',
|
|
98
|
-
limit: 1,
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
if (!users.docs.length) {
|
|
102
|
-
await payload.create({
|
|
103
|
-
collection: 'users',
|
|
104
|
-
data: {
|
|
105
|
-
email: 'dev@payloadcms.com',
|
|
106
|
-
password: 'test',
|
|
107
|
-
},
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
})
|
|
1
|
+
import { buildConfig } from 'payload/config'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import Users from './collections/Users'
|
|
4
|
+
import { cloudStorage } from '../../src'
|
|
5
|
+
import { s3Adapter } from '../../src/adapters/s3'
|
|
6
|
+
import { gcsAdapter } from '../../src/adapters/gcs'
|
|
7
|
+
import { azureBlobStorageAdapter } from '../../src/adapters/azure'
|
|
8
|
+
import type { Adapter } from '../../src/types'
|
|
9
|
+
import { Media } from './collections/Media'
|
|
10
|
+
|
|
11
|
+
let adapter: Adapter
|
|
12
|
+
let uploadOptions
|
|
13
|
+
|
|
14
|
+
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'azure') {
|
|
15
|
+
adapter = azureBlobStorageAdapter({
|
|
16
|
+
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
|
|
17
|
+
containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
|
|
18
|
+
allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
|
|
19
|
+
baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
|
|
20
|
+
})
|
|
21
|
+
// uploadOptions = {
|
|
22
|
+
// useTempFiles: true,
|
|
23
|
+
// }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 's3') {
|
|
27
|
+
// The s3 adapter supports using temp files for uploads
|
|
28
|
+
uploadOptions = {
|
|
29
|
+
useTempFiles: true,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
adapter = s3Adapter({
|
|
33
|
+
config: {
|
|
34
|
+
endpoint: process.env.S3_ENDPOINT,
|
|
35
|
+
forcePathStyle: process.env.S3_FORCE_PATH_STYLE === 'true',
|
|
36
|
+
region: process.env.S3_REGION,
|
|
37
|
+
credentials: {
|
|
38
|
+
accessKeyId: process.env.S3_ACCESS_KEY_ID,
|
|
39
|
+
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
bucket: process.env.S3_BUCKET,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'gcs') {
|
|
47
|
+
adapter = gcsAdapter({
|
|
48
|
+
options: {
|
|
49
|
+
apiEndpoint: process.env.GCS_ENDPOINT,
|
|
50
|
+
projectId: process.env.GCS_PROJECT_ID,
|
|
51
|
+
},
|
|
52
|
+
bucket: process.env.GCS_BUCKET,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default buildConfig({
|
|
57
|
+
serverURL: 'http://localhost:3000',
|
|
58
|
+
collections: [Media, Users],
|
|
59
|
+
upload: uploadOptions,
|
|
60
|
+
admin: {
|
|
61
|
+
// NOTE - these webpack extensions are only required
|
|
62
|
+
// for development of this plugin.
|
|
63
|
+
// No need to use these aliases within your own projects.
|
|
64
|
+
webpack: config => {
|
|
65
|
+
const newConfig = {
|
|
66
|
+
...config,
|
|
67
|
+
resolve: {
|
|
68
|
+
...(config.resolve || {}),
|
|
69
|
+
alias: {
|
|
70
|
+
...(config.resolve.alias || {}),
|
|
71
|
+
react: path.resolve(__dirname, '../node_modules/react'),
|
|
72
|
+
'@azure/storage-blob': path.resolve(__dirname, '../../src/adapters/azure/mock.js'),
|
|
73
|
+
'@aws-sdk/client-s3': path.resolve(__dirname, '../../src/adapters/s3/mock.js'),
|
|
74
|
+
'@google-cloud/storage': path.resolve(__dirname, '../../src/adapters/gcs/mock.js'),
|
|
75
|
+
fs: path.resolve(__dirname, './mocks/fsMock.js'),
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
return newConfig
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
typescript: {
|
|
83
|
+
outputFile: path.resolve(__dirname, 'payload-types.ts'),
|
|
84
|
+
},
|
|
85
|
+
plugins: [
|
|
86
|
+
// @ts-expect-error Conflicting types for relative package
|
|
87
|
+
cloudStorage({
|
|
88
|
+
collections: {
|
|
89
|
+
media: {
|
|
90
|
+
adapter,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
}),
|
|
94
|
+
],
|
|
95
|
+
onInit: async payload => {
|
|
96
|
+
const users = await payload.find({
|
|
97
|
+
collection: 'users',
|
|
98
|
+
limit: 1,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
if (!users.docs.length) {
|
|
102
|
+
await payload.create({
|
|
103
|
+
collection: 'users',
|
|
104
|
+
data: {
|
|
105
|
+
email: 'dev@payloadcms.com',
|
|
106
|
+
password: 'test',
|
|
107
|
+
},
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
})
|
package/dev/src/server.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import express from 'express'
|
|
2
|
-
import payload from 'payload'
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
5
|
-
require('dotenv').config()
|
|
6
|
-
|
|
7
|
-
const app = express()
|
|
8
|
-
|
|
9
|
-
// Redirect root to Admin panel
|
|
10
|
-
app.get('/', (_, res) => {
|
|
11
|
-
res.redirect('/admin')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
// Initialize Payload
|
|
15
|
-
payload.init({
|
|
16
|
-
secret: process.env.PAYLOAD_SECRET,
|
|
17
|
-
mongoURL: process.env.MONGODB_URI,
|
|
18
|
-
express: app,
|
|
19
|
-
onInit: () => {
|
|
20
|
-
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
// Add your own express routes here
|
|
25
|
-
|
|
26
|
-
app.listen(3000)
|
|
1
|
+
import express from 'express'
|
|
2
|
+
import payload from 'payload'
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
5
|
+
require('dotenv').config()
|
|
6
|
+
|
|
7
|
+
const app = express()
|
|
8
|
+
|
|
9
|
+
// Redirect root to Admin panel
|
|
10
|
+
app.get('/', (_, res) => {
|
|
11
|
+
res.redirect('/admin')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
// Initialize Payload
|
|
15
|
+
payload.init({
|
|
16
|
+
secret: process.env.PAYLOAD_SECRET,
|
|
17
|
+
mongoURL: process.env.MONGODB_URI,
|
|
18
|
+
express: app,
|
|
19
|
+
onInit: () => {
|
|
20
|
+
payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`)
|
|
21
|
+
},
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// Add your own express routes here
|
|
25
|
+
|
|
26
|
+
app.listen(3000)
|
package/dev/tsconfig.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"lib": [
|
|
5
|
-
"dom",
|
|
6
|
-
"dom.iterable",
|
|
7
|
-
"esnext"
|
|
8
|
-
],
|
|
9
|
-
"strict": false,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"outDir": "./dist",
|
|
13
|
-
"rootDir": "../",
|
|
14
|
-
"jsx": "react",
|
|
15
|
-
"sourceMap": true
|
|
16
|
-
},
|
|
17
|
-
"ts-node": {
|
|
18
|
-
"transpileOnly": true
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"strict": false,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"outDir": "./dist",
|
|
13
|
+
"rootDir": "../",
|
|
14
|
+
"jsx": "react",
|
|
15
|
+
"sourceMap": true
|
|
16
|
+
},
|
|
17
|
+
"ts-node": {
|
|
18
|
+
"transpileOnly": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "file-stub";
|
|
2
|
-
export default _default;
|
|
1
|
+
declare const _default: "file-stub";
|
|
2
|
+
export default _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = 'file-stub';
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = 'file-stub';
|
|
4
4
|
//# sourceMappingURL=fileStub.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { GenerateURL } from '../../types';
|
|
2
|
-
interface Args {
|
|
3
|
-
containerName: string;
|
|
4
|
-
baseURL: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const getGenerateURL: ({ containerName, baseURL }: Args) => GenerateURL;
|
|
7
|
-
export {};
|
|
1
|
+
import type { GenerateURL } from '../../types';
|
|
2
|
+
interface Args {
|
|
3
|
+
containerName: string;
|
|
4
|
+
baseURL: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const getGenerateURL: ({ containerName, baseURL }: Args) => GenerateURL;
|
|
7
|
+
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getGenerateURL = void 0;
|
|
7
|
-
var path_1 = __importDefault(require("path"));
|
|
8
|
-
var getGenerateURL = function (_a) {
|
|
9
|
-
var containerName = _a.containerName, baseURL = _a.baseURL;
|
|
10
|
-
return function (_a) {
|
|
11
|
-
var filename = _a.filename, _b = _a.prefix, prefix = _b === void 0 ? '' : _b;
|
|
12
|
-
return "".concat(baseURL, "/").concat(containerName, "/").concat(path_1.default.posix.join(prefix, filename));
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
exports.getGenerateURL = getGenerateURL;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getGenerateURL = void 0;
|
|
7
|
+
var path_1 = __importDefault(require("path"));
|
|
8
|
+
var getGenerateURL = function (_a) {
|
|
9
|
+
var containerName = _a.containerName, baseURL = _a.baseURL;
|
|
10
|
+
return function (_a) {
|
|
11
|
+
var filename = _a.filename, _b = _a.prefix, prefix = _b === void 0 ? '' : _b;
|
|
12
|
+
return "".concat(baseURL, "/").concat(containerName, "/").concat(path_1.default.posix.join(prefix, filename));
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.getGenerateURL = getGenerateURL;
|
|
16
16
|
//# sourceMappingURL=generateURL.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload/types';
|
|
2
|
-
import type { ContainerClient } from '@azure/storage-blob';
|
|
3
|
-
import type { HandleDelete } from '../../types';
|
|
4
|
-
interface Args {
|
|
5
|
-
collection: CollectionConfig;
|
|
6
|
-
getStorageClient: () => ContainerClient;
|
|
7
|
-
}
|
|
8
|
-
export declare const getHandleDelete: ({ getStorageClient }: Args) => HandleDelete;
|
|
9
|
-
export {};
|
|
1
|
+
import type { CollectionConfig } from 'payload/types';
|
|
2
|
+
import type { ContainerClient } from '@azure/storage-blob';
|
|
3
|
+
import type { HandleDelete } from '../../types';
|
|
4
|
+
interface Args {
|
|
5
|
+
collection: CollectionConfig;
|
|
6
|
+
getStorageClient: () => ContainerClient;
|
|
7
|
+
}
|
|
8
|
+
export declare const getHandleDelete: ({ getStorageClient }: Args) => HandleDelete;
|
|
9
|
+
export {};
|