Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 9d87533

Browse files
committed
Merge branch 'master' of github.com:payloadcms/plugin-cloud-storage
2 parents 9705e35 + c8d8f1f commit 9d87533

22 files changed

Lines changed: 922 additions & 103 deletions

.DS_Store

-6 KB
Binary file not shown.

.gitignore

Lines changed: 176 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1+
# Created by https://www.gitignore.io/api/node,macos,windows,webstorm,sublimetext,visualstudiocode
2+
3+
### macOS ###
4+
*.DS_Store
5+
.AppleDouble
6+
.LSOverride
7+
8+
# Thumbnails
9+
._*
10+
11+
# Files that might appear in the root of a volume
12+
.DocumentRevisions-V100
13+
.fseventsd
14+
.Spotlight-V100
15+
.TemporaryItems
16+
.Trashes
17+
.VolumeIcon.icns
18+
.com.apple.timemachine.donotpresent
19+
20+
# Directories potentially created on remote AFP share
21+
.AppleDB
22+
.AppleDesktop
23+
Network Trash Folder
24+
Temporary Items
25+
.apdisk
26+
27+
### Node ###
128
# Logs
229
logs
330
*.log
431
npm-debug.log*
532
yarn-debug.log*
633
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
1134

1235
# Runtime data
1336
pids
@@ -20,12 +43,11 @@ lib-cov
2043

2144
# Coverage directory used by tools like istanbul
2245
coverage
23-
*.lcov
2446

2547
# nyc test coverage
2648
.nyc_output
2749

28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
50+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2951
.grunt
3052

3153
# Bower dependency directory (https://bower.io/)
@@ -34,31 +56,22 @@ bower_components
3456
# node-waf configuration
3557
.lock-wscript
3658

37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
59+
# Compiled binary addons (http://nodejs.org/api/addons.html)
3860
build/Release
3961

4062
# Dependency directories
4163
node_modules/
4264
jspm_packages/
4365

44-
# TypeScript v1 declaration files
66+
# Typescript v1 declaration files
4567
typings/
4668

47-
# TypeScript cache
48-
*.tsbuildinfo
49-
5069
# Optional npm cache directory
5170
.npm
5271

5372
# Optional eslint cache
5473
.eslintcache
5574

56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
6275
# Optional REPL history
6376
.node_repl_history
6477

@@ -68,40 +81,159 @@ typings/
6881
# Yarn Integrity file
6982
.yarn-integrity
7083

84+
# Yarn Berry
85+
.yarn/*
86+
!.yarn/patches
87+
!.yarn/plugins
88+
!.yarn/releases
89+
!.yarn/sdks
90+
!.yarn/versions
91+
.pnp.*
92+
7193
# dotenv environment variables file
7294
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
8095

81-
# Nuxt.js build / generate output
82-
.nuxt
83-
dist
8496

85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
97+
### SublimeText ###
98+
# cache files for sublime text
99+
*.tmlanguage.cache
100+
*.tmPreferences.cache
101+
*.stTheme.cache
102+
103+
# workspace files are user-specific
104+
*.sublime-workspace
105+
106+
# project files should be checked into the repository, unless a significant
107+
# proportion of contributors will probably not be using SublimeText
108+
# *.sublime-project
109+
110+
# sftp configuration file
111+
sftp-config.json
112+
113+
# Package control specific files
114+
Package Control.last-run
115+
Package Control.ca-list
116+
Package Control.ca-bundle
117+
Package Control.system-ca-bundle
118+
Package Control.cache/
119+
Package Control.ca-certs/
120+
Package Control.merged-ca-bundle
121+
Package Control.user-ca-bundle
122+
oscrypto-ca-bundle.crt
123+
bh_unicode_properties.cache
90124

91-
# vuepress build output
92-
.vuepress/dist
125+
# Sublime-github package stores a github token in this file
126+
# https://packagecontrol.io/packages/sublime-github
127+
GitHub.sublime-settings
128+
129+
### VisualStudioCode ###
130+
.vscode/*
131+
!.vscode/tasks.json
132+
!.vscode/launch.json
133+
!.vscode/extensions.json
134+
.history
135+
136+
### WebStorm ###
137+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
138+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
139+
140+
.idea/*
141+
# User-specific stuff:
142+
.idea/**/workspace.xml
143+
.idea/**/tasks.xml
144+
.idea/dictionaries
145+
146+
# Sensitive or high-churn files:
147+
.idea/**/dataSources/
148+
.idea/**/dataSources.ids
149+
.idea/**/dataSources.xml
150+
.idea/**/dataSources.local.xml
151+
.idea/**/sqlDataSources.xml
152+
.idea/**/dynamic.xml
153+
.idea/**/uiDesigner.xml
154+
155+
# Gradle:
156+
.idea/**/gradle.xml
157+
.idea/**/libraries
158+
159+
# CMake
160+
cmake-build-debug/
161+
162+
# Mongo Explorer plugin:
163+
.idea/**/mongoSettings.xml
164+
165+
## File-based project format:
166+
*.iws
167+
168+
## Plugin-specific files:
169+
170+
# IntelliJ
171+
/out/
172+
173+
# mpeltonen/sbt-idea plugin
174+
.idea_modules/
175+
176+
# JIRA plugin
177+
atlassian-ide-plugin.xml
178+
179+
# Cursive Clojure plugin
180+
.idea/replstate.xml
181+
182+
# Ruby plugin and RubyMine
183+
/.rakeTasks
184+
185+
# Crashlytics plugin (for Android Studio and IntelliJ)
186+
com_crashlytics_export_strings.xml
187+
crashlytics.properties
188+
crashlytics-build.properties
189+
fabric.properties
190+
191+
### WebStorm Patch ###
192+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
193+
194+
# *.iml
195+
# modules.xml
196+
# .idea/misc.xml
197+
# *.ipr
198+
199+
# Sonarlint plugin
200+
.idea/sonarlint
201+
202+
### Windows ###
203+
# Windows thumbnail cache files
204+
Thumbs.db
205+
ehthumbs.db
206+
ehthumbs_vista.db
207+
208+
# Folder config file
209+
Desktop.ini
210+
211+
# Recycle Bin used on file shares
212+
$RECYCLE.BIN/
213+
214+
# Windows Installer files
215+
*.cab
216+
*.msi
217+
*.msm
218+
*.msp
219+
220+
# Windows shortcuts
221+
*.lnk
93222

94-
# Serverless directories
95-
.serverless/
223+
# End of https://www.gitignore.io/api/node,macos,windows,webstorm,sublimetext,visualstudiocode
96224

97-
# FuseBox cache
98-
.fusebox/
225+
# Ignore all uploads
226+
demo/upload
227+
demo/media
228+
demo/files
99229

100-
# DynamoDB Local files
101-
.dynamodb/
230+
# Ignore build folder
231+
build
102232

103-
# TernJS port file
104-
.tern-port
233+
# Ignore built components
234+
components/index.js
235+
components/styles.css
105236

106-
src/adapters/azure/emulator/azurestoragedata
107-
src/adapters/s3/emulator/.localstack
237+
# Ignore generated
238+
demo/generated-types.ts
239+
demo/generated-schema.graphql

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ This plugin supports the following adapters:
3737

3838
- [Azure Blob Storage](#azure-blob-storage-adapter)
3939
- [AWS S3-style Storage](#s3-adapter)
40+
- [Google Cloud Storage](#gcs-adapter)
4041

4142
However, you can create your own adapter for any third-party service you would like to use.
4243

@@ -98,6 +99,28 @@ const adapter = s3Adapter({
9899
// Now you can pass this adapter to the plugin
99100
```
100101

102+
### GCS Adapter
103+
104+
To use the GCS adapter, you need to have `@google-cloud/storage` installed in your project dependencies. To do so, run `yarn add @google-storage/cloud`.
105+
106+
From there, create the adapter, passing in all of its required properties:
107+
108+
```js
109+
import { gcsAdapter } from '@payloadcms/plugin-cloud-storage/gcs';
110+
111+
const adapter = gcsAdapter({
112+
options: {
113+
// you can choose any method for authentication, and authorization which is being provided by `@google-cloud/storage`
114+
keyFilename: './gcs-credentials.json',
115+
//OR
116+
credentials: JSON.parse(process.env.GCS_CREDENTIALS) // this env variable will have stringify version of your credentials.json file
117+
},
118+
bucket: process.env.GCS_BUCKET,
119+
})
120+
121+
// Now you can pass this adapter to the plugin
122+
```
123+
101124
### Payload Access Control
102125

103126
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.

dev/.DS_Store

-6 KB
Binary file not shown.

dev/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ S3_SECRET_ACCESS_KEY=alwiejglaiwhewlihgawe
1414
S3_BUCKET=payload-bucket
1515
S3_FORCE_PATH_STYLE=true
1616

17+
GCS_ENDPOINT=http://localhost:4443
18+
GCS_PROJECT_ID=test
19+
GCS_BUCKET=payload-bucket
20+
1721
PAYLOAD_DROP_DATABASE=true

dev/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"dev:azure": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=azure nodemon",
88
"dev:s3": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=s3 nodemon",
9+
"dev:gcs": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER=gcs nodemon",
910
"build:payload": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload build",
1011
"build:server": "tsc",
1112
"build": "yarn build:payload && yarn build:server",
@@ -15,9 +16,10 @@
1516
"dependencies": {
1617
"@aws-sdk/client-s3": "^3.142.0",
1718
"@azure/storage-blob": "^12.11.0",
19+
"@google-cloud/storage": "^6.4.1",
1820
"dotenv": "^8.2.0",
1921
"express": "^4.17.1",
20-
"payload": "^1.0.19"
22+
"payload": "^1.0.27"
2123
},
2224
"devDependencies": {
2325
"@types/express": "^4.17.9",

dev/src/payload.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path'
33
import Users from './collections/Users'
44
import { cloudStorage } from '../../src'
55
import { s3Adapter } from '../../src/adapters/s3'
6+
import { gcsAdapter } from '../../src/adapters/gcs'
67
import { azureBlobStorageAdapter } from '../../src/adapters/azure'
78
import type { Adapter } from '../../src/types'
89
import { Media } from './collections/Media'
@@ -32,6 +33,16 @@ if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 's3') {
3233
})
3334
}
3435

36+
if (process.env.PAYLOAD_PUBLIC_CLOUD_STORAGE_ADAPTER === 'gcs') {
37+
adapter = gcsAdapter({
38+
options: {
39+
apiEndpoint: process.env.GCS_ENDPOINT,
40+
projectId: process.env.GCS_PROJECT_ID,
41+
},
42+
bucket: process.env.GCS_BUCKET,
43+
})
44+
}
45+
3546
export default buildConfig({
3647
serverURL: 'http://localhost:3000',
3748
collections: [Media, Users],
@@ -49,6 +60,7 @@ export default buildConfig({
4960
react: path.resolve(__dirname, '../node_modules/react'),
5061
'@azure/storage-blob': path.resolve(__dirname, '../../src/adapters/azure/mock.js'),
5162
'@aws-sdk/client-s3': path.resolve(__dirname, '../../src/adapters/s3/mock.js'),
63+
'@google-cloud/storage': path.resolve(__dirname, '../../src/adapters/gcs/mock.js'),
5264
},
5365
},
5466
}

0 commit comments

Comments
 (0)