@payloadcms/storage-gcs 3.0.0-beta.13 → 3.0.0-beta.130
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/LICENSE.md +17 -17
- package/README.md +51 -1
- package/dist/generateURL.js.map +1 -1
- package/dist/handleDelete.js.map +1 -1
- package/dist/handleUpload.d.ts +1 -1
- package/dist/handleUpload.d.ts.map +1 -1
- package/dist/handleUpload.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/staticHandler.d.ts +1 -1
- package/dist/staticHandler.d.ts.map +1 -1
- package/dist/staticHandler.js.map +1 -1
- package/package.json +27 -18
package/LICENSE.md
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-
|
|
4
|
-
Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>
|
|
5
4
|
|
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
-
of this software and associated documentation files (the
|
|
8
|
-
in the Software without restriction, including
|
|
9
|
-
to use, copy, modify, merge, publish,
|
|
10
|
-
copies of the Software, and to
|
|
11
|
-
furnished to do so, subject to
|
|
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
12
|
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
|
14
|
-
copies or substantial portions of the Software.
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
15
|
|
|
16
|
-
THE SOFTWARE IS PROVIDED
|
|
17
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
-
|
|
22
|
-
SOFTWARE.
|
|
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 +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 Google Cloud Storage 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/generateURL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n getStorageClient: () => Storage\n}\n\nexport const getGenerateURL =\n ({ bucket, getStorageClient }: Args): GenerateURL =>\n ({ filename, prefix = '' }) => {\n return decodeURIComponent(\n getStorageClient().bucket(bucket).file(path.posix.join(prefix, filename)).publicUrl(),\n )\n }\n"],"names":["path","getGenerateURL","bucket","getStorageClient","filename","prefix","decodeURIComponent","file","posix","join","publicUrl"],"
|
|
1
|
+
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n getStorageClient: () => Storage\n}\n\nexport const getGenerateURL =\n ({ bucket, getStorageClient }: Args): GenerateURL =>\n ({ filename, prefix = '' }) => {\n return decodeURIComponent(\n getStorageClient().bucket(bucket).file(path.posix.join(prefix, filename)).publicUrl(),\n )\n }\n"],"names":["path","getGenerateURL","bucket","getStorageClient","filename","prefix","decodeURIComponent","file","posix","join","publicUrl"],"mappings":"AAGA,OAAOA,UAAU,OAAM;AAOvB,OAAO,MAAMC,iBACX,CAAC,EAAEC,MAAM,EAAEC,gBAAgB,EAAQ,GACnC,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAE,EAAE;QACxB,OAAOC,mBACLH,mBAAmBD,MAAM,CAACA,QAAQK,IAAI,CAACP,KAAKQ,KAAK,CAACC,IAAI,CAACJ,QAAQD,WAAWM,SAAS;IAEvF,EAAC"}
|
package/dist/handleDelete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n getStorageClient: () => Storage\n}\n\nexport const getHandleDelete = ({ bucket, getStorageClient }: Args): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n await getStorageClient().bucket(bucket).file(path.posix.join(prefix, filename)).delete({\n ignoreNotFound: true,\n })\n }\n}\n"],"names":["path","getHandleDelete","bucket","getStorageClient","doc","prefix","filename","file","posix","join","delete","ignoreNotFound"],"
|
|
1
|
+
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ninterface Args {\n bucket: string\n getStorageClient: () => Storage\n}\n\nexport const getHandleDelete = ({ bucket, getStorageClient }: Args): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n await getStorageClient().bucket(bucket).file(path.posix.join(prefix, filename)).delete({\n ignoreNotFound: true,\n })\n }\n}\n"],"names":["path","getHandleDelete","bucket","getStorageClient","doc","prefix","filename","file","posix","join","delete","ignoreNotFound"],"mappings":"AAGA,OAAOA,UAAU,OAAM;AAOvB,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,MAAM,EAAEC,gBAAgB,EAAQ;IAChE,OAAO,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAE,EAAE,EAAEC,QAAQ,EAAE;QAC9C,MAAMH,mBAAmBD,MAAM,CAACA,QAAQK,IAAI,CAACP,KAAKQ,KAAK,CAACC,IAAI,CAACJ,QAAQC,WAAWI,MAAM,CAAC;YACrFC,gBAAgB;QAClB;IACF;AACF,EAAC"}
|
package/dist/handleUpload.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Storage } from '@google-cloud/storage';
|
|
2
2
|
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { CollectionConfig } from 'payload
|
|
3
|
+
import type { CollectionConfig } from 'payload';
|
|
4
4
|
interface Args {
|
|
5
5
|
acl?: 'Private' | 'Public';
|
|
6
6
|
bucket: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI/C,UAAU,IAAI;IACZ,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,OAAO,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,eAAO,MAAM,eAAe,+CAKzB,IAAI,KAAG,YAiBT,CAAA"}
|
package/dist/handleUpload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport path from 'path'\n\ninterface Args {\n acl?: 'Private' | 'Public'\n bucket: string\n collection: CollectionConfig\n getStorageClient: () => Storage\n prefix?: string\n}\n\nexport const getHandleUpload = ({\n acl,\n bucket,\n getStorageClient,\n prefix = '',\n}: Args): HandleUpload => {\n return async ({ data, file }) => {\n const fileKey = path.posix.join(data.prefix || prefix, file.filename)\n\n const gcsFile = getStorageClient().bucket(bucket).file(fileKey)\n await gcsFile.save(file.buffer, {\n metadata: {\n contentType: file.mimeType,\n },\n })\n\n if (acl) {\n await gcsFile[`make${acl}`]()\n }\n\n return data\n }\n}\n"],"names":["path","getHandleUpload","acl","bucket","getStorageClient","prefix","data","file","fileKey","posix","join","filename","gcsFile","save","buffer","metadata","contentType","mimeType"],"mappings":"AAIA,OAAOA,UAAU,OAAM;AAUvB,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,GAAG,EACHC,MAAM,EACNC,gBAAgB,EAChBC,SAAS,EAAE,EACN;IACL,OAAO,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QAC1B,MAAMC,UAAUR,KAAKS,KAAK,CAACC,IAAI,CAACJ,KAAKD,MAAM,IAAIA,QAAQE,KAAKI,QAAQ;QAEpE,MAAMC,UAAUR,mBAAmBD,MAAM,CAACA,QAAQI,IAAI,CAACC;QACvD,MAAMI,QAAQC,IAAI,CAACN,KAAKO,MAAM,EAAE;YAC9BC,UAAU;gBACRC,aAAaT,KAAKU,QAAQ;YAC5B;QACF;QAEA,IAAIf,KAAK;YACP,MAAMU,OAAO,CAAC,CAAC,IAAI,EAAEV,IAAI,CAAC,CAAC;QAC7B;QAEA,OAAOI;IACT;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StorageOptions } from '@google-cloud/storage';
|
|
2
2
|
import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { Plugin } from 'payload
|
|
3
|
+
import type { Plugin } from 'payload';
|
|
4
4
|
export interface GcsStorageOptions {
|
|
5
5
|
acl?: 'Private' | 'Public';
|
|
6
6
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAA;AAU7C,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;IAE1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IACtE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,OAAO,EAAE,cAAc,CAAA;CACxB;AAED,KAAK,gBAAgB,GAAG,CAAC,cAAc,EAAE,iBAAiB,KAAK,MAAM,CAAA;AAErE,eAAO,MAAM,UAAU,EAAE,gBA4CtB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Storage } from '@google-cloud/storage';
|
|
2
|
-
import {
|
|
2
|
+
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
3
3
|
import { getGenerateURL } from './generateURL.js';
|
|
4
4
|
import { getHandleDelete } from './handleDelete.js';
|
|
5
5
|
import { getHandleUpload } from './handleUpload.js';
|
|
@@ -33,7 +33,7 @@ export const gcsStorage = (gcsStorageOptions)=>(incomingConfig)=>{
|
|
|
33
33
|
};
|
|
34
34
|
})
|
|
35
35
|
};
|
|
36
|
-
return
|
|
36
|
+
return cloudStoragePlugin({
|
|
37
37
|
collections: collectionsWithAdapter
|
|
38
38
|
})(config);
|
|
39
39
|
};
|
|
@@ -41,11 +41,14 @@ function gcsStorageInternal({ acl, bucket, options }) {
|
|
|
41
41
|
return ({ collection, prefix })=>{
|
|
42
42
|
let storageClient = null;
|
|
43
43
|
const getStorageClient = ()=>{
|
|
44
|
-
if (storageClient)
|
|
44
|
+
if (storageClient) {
|
|
45
|
+
return storageClient;
|
|
46
|
+
}
|
|
45
47
|
storageClient = new Storage(options);
|
|
46
48
|
return storageClient;
|
|
47
49
|
};
|
|
48
50
|
return {
|
|
51
|
+
name: 'gcs',
|
|
49
52
|
generateURL: getGenerateURL({
|
|
50
53
|
bucket,
|
|
51
54
|
getStorageClient
|
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
|
|
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'\n\nimport { Storage } from '@google-cloud/storage'\nimport { cloudStoragePlugin } 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 cloudStoragePlugin({\n collections: collectionsWithAdapter,\n })(config)\n }\n\nfunction gcsStorageInternal({ acl, bucket, options }: GcsStorageOptions): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n let storageClient: null | Storage = null\n\n const getStorageClient = (): Storage => {\n if (storageClient) {\n return storageClient\n }\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","cloudStoragePlugin","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"],"mappings":"AASA,SAASA,OAAO,QAAQ,wBAAuB;AAC/C,SAASC,kBAAkB,QAAQ,mCAAkC;AAErE,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,mBAAmB;YACxBc,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;gBACjB,OAAOA;YACT;YACAA,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/dist/staticHandler.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Storage } from '@google-cloud/storage';
|
|
2
2
|
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
3
|
-
import type { CollectionConfig } from 'payload
|
|
3
|
+
import type { CollectionConfig } from 'payload';
|
|
4
4
|
interface Args {
|
|
5
5
|
bucket: string;
|
|
6
6
|
collection: CollectionConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAK/C,UAAU,IAAI;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,EAAE,MAAM,OAAO,CAAA;CAChC;AAED,eAAO,MAAM,UAAU,6CAA8C,IAAI,KAAG,aAqC3E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { Storage } from '@google-cloud/storage'\nimport type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport path from 'path'\n\ninterface Args {\n bucket: string\n collection: CollectionConfig\n getStorageClient: () => Storage\n}\n\nexport const getHandler = ({ bucket, collection, getStorageClient }: Args): StaticHandler => {\n return async (req, { params: { filename } }) => {\n try {\n const prefix = await getFilePrefix({ collection, filename, req })\n const file = getStorageClient().bucket(bucket).file(path.posix.join(prefix, filename))\n\n const [metadata] = await file.getMetadata()\n\n // Manually create a ReadableStream for the web from a Node.js stream.\n const readableStream = new ReadableStream({\n start(controller) {\n const nodeStream = file.createReadStream()\n nodeStream.on('data', (chunk) => {\n controller.enqueue(new Uint8Array(chunk))\n })\n nodeStream.on('end', () => {\n controller.close()\n })\n nodeStream.on('error', (err) => {\n controller.error(err)\n })\n },\n })\n\n return new Response(readableStream, {\n headers: new Headers({\n 'Content-Length': String(metadata.size),\n 'Content-Type': String(metadata.contentType),\n ETag: String(metadata.etag),\n }),\n status: 200,\n })\n } catch (err: unknown) {\n req.payload.logger.error(err)\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getFilePrefix","path","getHandler","bucket","collection","getStorageClient","req","params","filename","prefix","file","posix","join","metadata","getMetadata","readableStream","ReadableStream","start","controller","nodeStream","createReadStream","on","chunk","enqueue","Uint8Array","close","err","error","Response","headers","Headers","String","size","contentType","ETag","etag","status","payload","logger"],"mappings":"AAIA,SAASA,aAAa,QAAQ,6CAA4C;AAC1E,OAAOC,UAAU,OAAM;AAQvB,OAAO,MAAMC,aAAa,CAAC,EAAEC,MAAM,EAAEC,UAAU,EAAEC,gBAAgB,EAAQ;IACvE,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAE;QACzC,IAAI;YACF,MAAMC,SAAS,MAAMT,cAAc;gBAAEI;gBAAYI;gBAAUF;YAAI;YAC/D,MAAMI,OAAOL,mBAAmBF,MAAM,CAACA,QAAQO,IAAI,CAACT,KAAKU,KAAK,CAACC,IAAI,CAACH,QAAQD;YAE5E,MAAM,CAACK,SAAS,GAAG,MAAMH,KAAKI,WAAW;YAEzC,sEAAsE;YACtE,MAAMC,iBAAiB,IAAIC,eAAe;gBACxCC,OAAMC,UAAU;oBACd,MAAMC,aAAaT,KAAKU,gBAAgB;oBACxCD,WAAWE,EAAE,CAAC,QAAQ,CAACC;wBACrBJ,WAAWK,OAAO,CAAC,IAAIC,WAAWF;oBACpC;oBACAH,WAAWE,EAAE,CAAC,OAAO;wBACnBH,WAAWO,KAAK;oBAClB;oBACAN,WAAWE,EAAE,CAAC,SAAS,CAACK;wBACtBR,WAAWS,KAAK,CAACD;oBACnB;gBACF;YACF;YAEA,OAAO,IAAIE,SAASb,gBAAgB;gBAClCc,SAAS,IAAIC,QAAQ;oBACnB,kBAAkBC,OAAOlB,SAASmB,IAAI;oBACtC,gBAAgBD,OAAOlB,SAASoB,WAAW;oBAC3CC,MAAMH,OAAOlB,SAASsB,IAAI;gBAC5B;gBACAC,QAAQ;YACV;QACF,EAAE,OAAOV,KAAc;YACrBpB,IAAI+B,OAAO,CAACC,MAAM,CAACX,KAAK,CAACD;YACzB,OAAO,IAAIE,SAAS,yBAAyB;gBAAEQ,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-gcs",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.130",
|
|
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
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
13
|
+
"maintainers": [
|
|
14
|
+
{
|
|
15
|
+
"name": "Payload",
|
|
16
|
+
"email": "info@payloadcms.com",
|
|
17
|
+
"url": "https://payloadcms.com"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
15
20
|
"type": "module",
|
|
16
21
|
"exports": {
|
|
17
22
|
".": {
|
|
18
23
|
"import": "./dist/index.js",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"default": "./dist/index.js"
|
|
21
26
|
}
|
|
22
27
|
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
23
33
|
"dependencies": {
|
|
24
34
|
"@google-cloud/storage": "^7.7.0",
|
|
25
|
-
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.
|
|
35
|
+
"@payloadcms/plugin-cloud-storage": "3.0.0-beta.130"
|
|
26
36
|
},
|
|
27
37
|
"devDependencies": {
|
|
28
|
-
"payload": "3.0.0-beta.
|
|
38
|
+
"payload": "3.0.0-beta.130"
|
|
29
39
|
},
|
|
30
40
|
"peerDependencies": {
|
|
31
|
-
"payload": "3.0.0-beta.
|
|
41
|
+
"payload": "3.0.0-beta.130"
|
|
32
42
|
},
|
|
33
43
|
"engines": {
|
|
34
|
-
"node": "
|
|
44
|
+
"node": "^18.20.2 || >=20.9.0"
|
|
35
45
|
},
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
46
|
"scripts": {
|
|
40
|
-
"build": "pnpm build:
|
|
41
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
42
|
-
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
47
|
+
"build": "pnpm build:types && pnpm build:swc",
|
|
43
48
|
"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
|
-
"
|
|
49
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
50
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
51
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"lint:fix": "eslint . --fix"
|
|
45
54
|
}
|
|
46
55
|
}
|