@payloadcms/storage-gcs 3.0.0-beta.18 → 3.0.0-beta.20
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/README.md +51 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Google Cloud Storage for Payload
|
|
2
|
+
|
|
3
|
+
This package provides a simple way to use [Google Cloud Storage](https://cloud.google.com/storage) with Payload.
|
|
4
|
+
|
|
5
|
+
**NOTE:** This package removes the need to use `@payloadcms/plugin-cloud-storage` as was needed in Payload 2.x.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @payloadcms/storage-gcs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
- Configure the `collections` object to specify which collections should use the Vercel Blob adapter. The slug _must_ match one of your existing collection slugs.
|
|
16
|
+
- When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { gcsStorage } from '@payloadcms/storage-gcs'
|
|
20
|
+
import { Media } from './collections/Media'
|
|
21
|
+
import { MediaWithPrefix } from './collections/MediaWithPrefix'
|
|
22
|
+
|
|
23
|
+
export default buildConfig({
|
|
24
|
+
collections: [Media, MediaWithPrefix],
|
|
25
|
+
plugins: [
|
|
26
|
+
gcsStorage({
|
|
27
|
+
collections: {
|
|
28
|
+
[mediaSlug]: true,
|
|
29
|
+
[mediaWithPrefixSlug]: {
|
|
30
|
+
prefix,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
bucket: process.env.GCS_BUCKET,
|
|
34
|
+
options: {
|
|
35
|
+
apiEndpoint: process.env.GCS_ENDPOINT,
|
|
36
|
+
projectId: process.env.GCS_PROJECT_ID,
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Configuration Options
|
|
44
|
+
|
|
45
|
+
| Option | Description | Default |
|
|
46
|
+
| ------------- | --------------------------------------------------------------------------------------------------- | --------- |
|
|
47
|
+
| `enabled` | Whether or not to enable the plugin | `true` |
|
|
48
|
+
| `collections` | Collections to apply the storage to | |
|
|
49
|
+
| `bucket` | The name of the bucket to use | |
|
|
50
|
+
| `options` | Google Cloud Storage client configuration. See [Docs](https://github.com/googleapis/nodejs-storage) | |
|
|
51
|
+
| `acl` | Access control list for files that are uploaded | `Private` |
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { StorageOptions } from '@google-cloud/storage'\nimport type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { Storage } from '@google-cloud/storage'\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport interface GcsStorageOptions {\n acl?: 'Private' | 'Public'\n\n /**\n * The name of the bucket to use.\n */\n bucket: string\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Google Cloud Storage client configuration.\n *\n * @see https://github.com/googleapis/nodejs-storage\n */\n options: StorageOptions\n}\n\ntype GcsStoragePlugin = (gcsStorageArgs: GcsStorageOptions) => Plugin\n\nexport const gcsStorage: GcsStoragePlugin =\n (gcsStorageOptions: GcsStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (gcsStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = gcsStorageInternal(gcsStorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n gcsStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction gcsStorageInternal({ acl, bucket, options }: GcsStorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: Storage | null = null\n\n const getStorageClient = (): Storage => {\n if (storageClient) return storageClient\n storageClient = new Storage(options)\n return storageClient\n }\n\n return {\n generateURL: getGenerateURL({ bucket, getStorageClient }),\n handleDelete: getHandleDelete({ bucket, getStorageClient }),\n handleUpload: getHandleUpload({\n acl,\n bucket,\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection, getStorageClient }),\n }\n }\n}\n"],"names":["Storage","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","gcsStorage","gcsStorageOptions","incomingConfig","enabled","adapter","gcsStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","acl","bucket","options","prefix","storageClient","getStorageClient","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { StorageOptions } from '@google-cloud/storage'\nimport type {\n Adapter,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, Plugin } from 'payload/config'\n\nimport { Storage } from '@google-cloud/storage'\nimport { cloudStorage } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateURL } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getHandler } from './staticHandler.js'\n\nexport interface GcsStorageOptions {\n acl?: 'Private' | 'Public'\n\n /**\n * The name of the bucket to use.\n */\n bucket: string\n /**\n * Collection options to apply the S3 adapter to.\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Google Cloud Storage client configuration.\n *\n * @see https://github.com/googleapis/nodejs-storage\n */\n options: StorageOptions\n}\n\ntype GcsStoragePlugin = (gcsStorageArgs: GcsStorageOptions) => Plugin\n\nexport const gcsStorage: GcsStoragePlugin =\n (gcsStorageOptions: GcsStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (gcsStorageOptions.enabled === false) {\n return incomingConfig\n }\n\n const adapter = gcsStorageInternal(gcsStorageOptions)\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n gcsStorageOptions.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: {\n ...(collOptions === true ? {} : collOptions),\n adapter,\n },\n }),\n {} as Record<string, CollectionOptions>,\n )\n\n // Set disableLocalStorage: true for collections specified in the plugin options\n const config = {\n ...incomingConfig,\n collections: (incomingConfig.collections || []).map((collection) => {\n if (!collectionsWithAdapter[collection.slug]) {\n return collection\n }\n\n return {\n ...collection,\n upload: {\n ...(typeof collection.upload === 'object' ? collection.upload : {}),\n disableLocalStorage: true,\n },\n }\n }),\n }\n\n return cloudStorage({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction gcsStorageInternal({ acl, bucket, options }: GcsStorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: Storage | null = null\n\n const getStorageClient = (): Storage => {\n if (storageClient) return storageClient\n storageClient = new Storage(options)\n return storageClient\n }\n\n return {\n name: 'gcs',\n generateURL: getGenerateURL({ bucket, getStorageClient }),\n handleDelete: getHandleDelete({ bucket, getStorageClient }),\n handleUpload: getHandleUpload({\n acl,\n bucket,\n collection,\n getStorageClient,\n prefix,\n }),\n staticHandler: getHandler({ bucket, collection, getStorageClient }),\n }\n }\n}\n"],"names":["Storage","cloudStorage","getGenerateURL","getHandleDelete","getHandleUpload","getHandler","gcsStorage","gcsStorageOptions","incomingConfig","enabled","adapter","gcsStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","acl","bucket","options","prefix","storageClient","getStorageClient","name","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AASA,SAASA,OAAO,QAAQ,wBAAuB;AAC/C,SAASC,YAAY,QAAQ,mCAAkC;AAE/D,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,UAAU,QAAQ,qBAAoB;AA8B/C,OAAO,MAAMC,aACX,CAACC,oBACD,CAACC;QACC,IAAID,kBAAkBE,OAAO,KAAK,OAAO;YACvC,OAAOD;QACT;QAEA,MAAME,UAAUC,mBAAmBJ;QAEnC,+CAA+C;QAC/C,MAAMK,yBAAmEC,OAAOC,OAAO,CACrFP,kBAAkBQ,WAAW,EAC7BC,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;gBAC7B,GAAGF,GAAG;gBACN,CAACC,KAAK,EAAE;oBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;oBAC3CT;gBACF;YACF,CAAA,GACA,CAAC;QAGH,gFAAgF;QAChF,MAAMU,SAAS;YACb,GAAGZ,cAAc;YACjBO,aAAa,AAACP,CAAAA,eAAeO,WAAW,IAAI,EAAE,AAAD,EAAGM,GAAG,CAAC,CAACC;gBACnD,IAAI,CAACV,sBAAsB,CAACU,WAAWJ,IAAI,CAAC,EAAE;oBAC5C,OAAOI;gBACT;gBAEA,OAAO;oBACL,GAAGA,UAAU;oBACbC,QAAQ;wBACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;wBAClEC,qBAAqB;oBACvB;gBACF;YACF;QACF;QAEA,OAAOvB,aAAa;YAClBc,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAAST,mBAAmB,EAAEc,GAAG,EAAEC,MAAM,EAAEC,OAAO,EAAqB;IACrE,OAAO,CAAC,EAAEL,UAAU,EAAEM,MAAM,EAAE;QAC5B,IAAIC,gBAAgC;QAEpC,MAAMC,mBAAmB;YACvB,IAAID,eAAe,OAAOA;YAC1BA,gBAAgB,IAAI7B,QAAQ2B;YAC5B,OAAOE;QACT;QAEA,OAAO;YACLE,MAAM;YACNC,aAAa9B,eAAe;gBAAEwB;gBAAQI;YAAiB;YACvDG,cAAc9B,gBAAgB;gBAAEuB;gBAAQI;YAAiB;YACzDI,cAAc9B,gBAAgB;gBAC5BqB;gBACAC;gBACAJ;gBACAQ;gBACAF;YACF;YACAO,eAAe9B,WAAW;gBAAEqB;gBAAQJ;gBAAYQ;YAAiB;QACnE;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-gcs",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.20",
|
|
4
4
|
"description": "Payload storage adapter for Google Cloud Storage",
|
|
5
|
+
"homepage": "https://payloadcms.com",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "https://github.com/payloadcms/payload.git",
|
|
8
9
|
"directory": "packages/storage-gcs"
|
|
9
10
|
},
|
|
10
11
|
"license": "MIT",
|
|
11
|
-
"homepage": "https://payloadcms.com",
|
|
12
12
|
"author": "Payload CMS, Inc.",
|
|
13
|
-
"main": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
13
|
"type": "module",
|
|
16
14
|
"exports": {
|
|
17
15
|
".": {
|
|
@@ -20,27 +18,29 @@
|
|
|
20
18
|
"types": "./dist/index.d.ts"
|
|
21
19
|
}
|
|
22
20
|
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
23
26
|
"dependencies": {
|
|
24
27
|
"@google-cloud/storage": "^7.7.0",
|
|
25
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.
|
|
28
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.20"
|
|
26
29
|
},
|
|
27
30
|
"devDependencies": {
|
|
28
|
-
"payload": "3.0.0-beta.
|
|
31
|
+
"payload": "3.0.0-beta.20"
|
|
29
32
|
},
|
|
30
33
|
"peerDependencies": {
|
|
31
|
-
"payload": "3.0.0-beta.
|
|
34
|
+
"payload": "3.0.0-beta.20"
|
|
32
35
|
},
|
|
33
36
|
"engines": {
|
|
34
37
|
"node": ">=18.20.2"
|
|
35
38
|
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "pnpm build:swc && pnpm build:types",
|
|
41
|
+
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
41
42
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
42
43
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
43
|
-
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
44
44
|
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
45
45
|
}
|
|
46
46
|
}
|