This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathpayload.config.ts
123 lines (116 loc) · 3.48 KB
/
payload.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { buildConfig } from 'payload/config'
import path from 'path'
import Users from './collections/Users'
import { cloudStorage } from '../../src'
import { s3Adapter } from '../../src/adapters/s3'
import { gcsAdapter } from '../../src/adapters/gcs'
import { azureBlobStorageAdapter } from '../../src/adapters/azure'
import type { Adapter } from '../../src/types'
import { Media } from './collections/Media'
let adapter: Adapter
let uploadOptions
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'azure') {
adapter = azureBlobStorageAdapter({
connectionString: process.env.AZURE_STORAGE_CONNECTION_STRING,
containerName: process.env.AZURE_STORAGE_CONTAINER_NAME,
allowContainerCreate: process.env.AZURE_STORAGE_ALLOW_CONTAINER_CREATE === 'true',
baseURL: process.env.AZURE_STORAGE_ACCOUNT_BASEURL,
})
// uploadOptions = {
// useTempFiles: true,
// }
}
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 's3') {
// The s3 adapter supports using temp files for uploads
uploadOptions = {
useTempFiles: true,
}
adapter = s3Adapter({
config: {
endpoint: process.env.S3_ENDPOINT,
forcePathStyle: process.env.S3_FORCE_PATH_STYLE === 'true',
region: process.env.S3_REGION,
credentials: {
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
},
},
bucket: process.env.S3_BUCKET,
})
}
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'gcs') {
adapter = gcsAdapter({
options: {
apiEndpoint: process.env.GCS_ENDPOINT,
projectId: process.env.GCS_PROJECT_ID,
},
bucket: process.env.GCS_BUCKET,
})
}
export default buildConfig({
serverURL: 'http://localhost:3000',
collections: [Media, Users],
upload: uploadOptions,
admin: {
// NOTE - these webpack extensions are only required
// for development of this plugin.
// No need to use these aliases within your own projects.
webpack: config => {
const newConfig = {
...config,
resolve: {
...(config.resolve || {}),
alias: {
...(config.resolve.alias || {}),
react: path.resolve(__dirname, '../node_modules/react'),
[path.resolve(__dirname, '../../src/index')]: path.resolve(
__dirname,
'../../src/admin/index.ts',
),
[path.resolve(__dirname, '../../src/adapters/s3/index')]: path.resolve(
__dirname,
'../../src/adapters/s3/mock.js',
),
[path.resolve(__dirname, '../../src/adapters/gcs/index')]: path.resolve(
__dirname,
'../../src/adapters/gcs/mock.js',
),
[path.resolve(__dirname, '../../src/adapters/azure/index')]: path.resolve(
__dirname,
'../../src/adapters/azure/mock.js',
),
},
},
}
return newConfig
},
},
typescript: {
outputFile: path.resolve(__dirname, 'payload-types.ts'),
},
plugins: [
// @ts-expect-error Conflicting types for relative package
cloudStorage({
collections: {
media: {
adapter,
},
},
}),
],
onInit: async payload => {
const users = await payload.find({
collection: 'users',
limit: 1,
})
if (!users.docs.length) {
await payload.create({
collection: 'users',
data: {
email: '[email protected]',
password: 'test',
},
})
}
},
})