@payloadcms/storage-vercel-blob 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 +49 -1
- package/dist/generateURL.js.map +1 -1
- package/dist/handleDelete.js.map +1 -1
- package/dist/handleUpload.d.ts +2 -2
- package/dist/handleUpload.d.ts.map +1 -1
- package/dist/handleUpload.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/staticHandler.d.ts +3 -2
- package/dist/staticHandler.d.ts.map +1 -1
- package/dist/staticHandler.js +2 -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,49 @@
|
|
|
1
|
-
# Vercel Blob Storage
|
|
1
|
+
# Vercel Blob Storage for Payload
|
|
2
|
+
|
|
3
|
+
This package provides a simple way to use [Vercel Blob](https://vercel.com/docs/storage/vercel-blob) 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-vercel-blob
|
|
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
|
+
- Ensure you have `BLOB_READ_WRITE_TOKEN` set in your Vercel environment variables. This is usually set by Vercel automatically after adding blob storage to your project.
|
|
17
|
+
- When enabled, this package will automatically set `disableLocalStorage` to `true` for each collection.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'
|
|
21
|
+
import { Media } from './collections/Media'
|
|
22
|
+
import { MediaWithPrefix } from './collections/MediaWithPrefix'
|
|
23
|
+
|
|
24
|
+
export default buildConfig({
|
|
25
|
+
collections: [Media, MediaWithPrefix],
|
|
26
|
+
plugins: [
|
|
27
|
+
vercelBlobStorage({
|
|
28
|
+
enabled: true, // Optional, defaults to true
|
|
29
|
+
// Specify which collections should use Vercel Blob
|
|
30
|
+
collections: {
|
|
31
|
+
[Media.slug]: true,
|
|
32
|
+
[MediaWithPrefix.slug]: {
|
|
33
|
+
prefix: 'my-prefix',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
// Token provided by Vercel once Blob storage is added to your Vercel project
|
|
37
|
+
token: process.env.BLOB_READ_WRITE_TOKEN,
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
| Option | Description | Default |
|
|
44
|
+
| -------------------- | -------------------------------------------------------------------- | ----------------------------- |
|
|
45
|
+
| `enabled` | Whether or not to enable the plugin | `true` |
|
|
46
|
+
| `collections` | Collections to apply the Vercel Blob adapter to | |
|
|
47
|
+
| `addRandomSuffix` | Add a random suffix to the uploaded file name in Vercel Blob storage | `false` |
|
|
48
|
+
| `cacheControlMaxAge` | Cache-Control max-age in seconds | `365 * 24 * 60 * 60` (1 Year) |
|
|
49
|
+
| `token` | Vercel Blob storage read/write token | `''` |
|
package/dist/generateURL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ntype GenerateUrlArgs = {\n baseUrl: string\n prefix?: string\n}\n\nexport const getGenerateUrl = ({ baseUrl }: GenerateUrlArgs): GenerateURL => {\n return ({ filename, prefix = '' }) => {\n return `${baseUrl}/${path.posix.join(prefix, filename)}`\n }\n}\n"],"names":["path","getGenerateUrl","baseUrl","filename","prefix","posix","join"],"
|
|
1
|
+
{"version":3,"sources":["../src/generateURL.ts"],"sourcesContent":["import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types'\n\nimport path from 'path'\n\ntype GenerateUrlArgs = {\n baseUrl: string\n prefix?: string\n}\n\nexport const getGenerateUrl = ({ baseUrl }: GenerateUrlArgs): GenerateURL => {\n return ({ filename, prefix = '' }) => {\n return `${baseUrl}/${path.posix.join(prefix, filename)}`\n }\n}\n"],"names":["path","getGenerateUrl","baseUrl","filename","prefix","posix","join"],"mappings":"AAEA,OAAOA,UAAU,OAAM;AAOvB,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,OAAO,EAAmB;IACzD,OAAO,CAAC,EAAEC,QAAQ,EAAEC,SAAS,EAAE,EAAE;QAC/B,OAAO,CAAC,EAAEF,QAAQ,CAAC,EAAEF,KAAKK,KAAK,CAACC,IAAI,CAACF,QAAQD,UAAU,CAAC;IAC1D;AACF,EAAC"}
|
package/dist/handleDelete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\n\nimport { del } from '@vercel/blob'\nimport path from 'path'\n\ntype HandleDeleteArgs = {\n baseUrl: string\n prefix?: string\n token: string\n}\n\nexport const getHandleDelete = ({ baseUrl, token }: HandleDeleteArgs): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n const fileUrl = `${baseUrl}/${path.posix.join(prefix, filename)}`\n const deletedBlob = await del(fileUrl, { token })\n\n return deletedBlob\n }\n}\n"],"names":["del","path","getHandleDelete","baseUrl","token","doc","prefix","filename","fileUrl","posix","join","deletedBlob"],"
|
|
1
|
+
{"version":3,"sources":["../src/handleDelete.ts"],"sourcesContent":["import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types'\n\nimport { del } from '@vercel/blob'\nimport path from 'path'\n\ntype HandleDeleteArgs = {\n baseUrl: string\n prefix?: string\n token: string\n}\n\nexport const getHandleDelete = ({ baseUrl, token }: HandleDeleteArgs): HandleDelete => {\n return async ({ doc: { prefix = '' }, filename }) => {\n const fileUrl = `${baseUrl}/${path.posix.join(prefix, filename)}`\n const deletedBlob = await del(fileUrl, { token })\n\n return deletedBlob\n }\n}\n"],"names":["del","path","getHandleDelete","baseUrl","token","doc","prefix","filename","fileUrl","posix","join","deletedBlob"],"mappings":"AAEA,SAASA,GAAG,QAAQ,eAAc;AAClC,OAAOC,UAAU,OAAM;AAQvB,OAAO,MAAMC,kBAAkB,CAAC,EAAEC,OAAO,EAAEC,KAAK,EAAoB;IAClE,OAAO,OAAO,EAAEC,KAAK,EAAEC,SAAS,EAAE,EAAE,EAAEC,QAAQ,EAAE;QAC9C,MAAMC,UAAU,CAAC,EAAEL,QAAQ,CAAC,EAAEF,KAAKQ,KAAK,CAACC,IAAI,CAACJ,QAAQC,UAAU,CAAC;QACjE,MAAMI,cAAc,MAAMX,IAAIQ,SAAS;YAAEJ;QAAM;QAE/C,OAAOO;IACT;AACF,EAAC"}
|
package/dist/handleUpload.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
2
|
import type { VercelBlobStorageOptions } from './index.js';
|
|
3
|
-
type HandleUploadArgs =
|
|
3
|
+
type HandleUploadArgs = {
|
|
4
4
|
baseUrl: string;
|
|
5
5
|
prefix?: string;
|
|
6
|
-
}
|
|
6
|
+
} & Omit<VercelBlobStorageOptions, 'collections'>;
|
|
7
7
|
export declare const getHandleUpload: ({ access, addRandomSuffix, baseUrl, cacheControlMaxAge, prefix, token, }: HandleUploadArgs) => HandleUpload;
|
|
8
8
|
export {};
|
|
9
9
|
//# sourceMappingURL=handleUpload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAK1E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE1D,KAAK,gBAAgB,GAAG
|
|
1
|
+
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAK1E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAE1D,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,GAAG,IAAI,CAAC,wBAAwB,EAAE,aAAa,CAAC,CAAA;AAEjD,eAAO,MAAM,eAAe,6EAOzB,gBAAgB,KAAG,YAmBrB,CAAA"}
|
package/dist/handleUpload.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\n\nimport { put } from '@vercel/blob'\nimport path from 'path'\n\nimport type { VercelBlobStorageOptions } from './index.js'\n\ntype HandleUploadArgs =
|
|
1
|
+
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types'\n\nimport { put } from '@vercel/blob'\nimport path from 'path'\n\nimport type { VercelBlobStorageOptions } from './index.js'\n\ntype HandleUploadArgs = {\n baseUrl: string\n prefix?: string\n} & Omit<VercelBlobStorageOptions, 'collections'>\n\nexport const getHandleUpload = ({\n access = 'public',\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n prefix = '',\n token,\n}: HandleUploadArgs): HandleUpload => {\n return async ({ data, file: { buffer, filename, mimeType } }) => {\n const fileKey = path.posix.join(data.prefix || prefix, filename)\n\n const result = await put(fileKey, buffer, {\n access,\n addRandomSuffix,\n cacheControlMaxAge,\n contentType: mimeType,\n token,\n })\n\n // Get filename with suffix from returned url\n if (addRandomSuffix) {\n data.filename = result.url.replace(`${baseUrl}/`, '')\n }\n\n return data\n }\n}\n"],"names":["put","path","getHandleUpload","access","addRandomSuffix","baseUrl","cacheControlMaxAge","prefix","token","data","file","buffer","filename","mimeType","fileKey","posix","join","result","contentType","url","replace"],"mappings":"AAEA,SAASA,GAAG,QAAQ,eAAc;AAClC,OAAOC,UAAU,OAAM;AASvB,OAAO,MAAMC,kBAAkB,CAAC,EAC9BC,SAAS,QAAQ,EACjBC,eAAe,EACfC,OAAO,EACPC,kBAAkB,EAClBC,SAAS,EAAE,EACXC,KAAK,EACY;IACjB,OAAO,OAAO,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAE;QAC1D,MAAMC,UAAUb,KAAKc,KAAK,CAACC,IAAI,CAACP,KAAKF,MAAM,IAAIA,QAAQK;QAEvD,MAAMK,SAAS,MAAMjB,IAAIc,SAASH,QAAQ;YACxCR;YACAC;YACAE;YACAY,aAAaL;YACbL;QACF;QAEA,6CAA6C;QAC7C,IAAIJ,iBAAiB;YACnBK,KAAKG,QAAQ,GAAGK,OAAOE,GAAG,CAACC,OAAO,CAAC,CAAC,EAAEf,QAAQ,CAAC,CAAC,EAAE;QACpD;QAEA,OAAOI;IACT;AACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { Plugin } from 'payload
|
|
2
|
+
import type { Plugin } from 'payload';
|
|
3
3
|
export type VercelBlobStorageOptions = {
|
|
4
4
|
/**
|
|
5
|
-
* Access control level
|
|
5
|
+
* Access control level. Currently, only 'public' is supported.
|
|
6
|
+
* Vercel plans on adding support for private blobs in the future.
|
|
6
7
|
*
|
|
7
8
|
* @default 'public'
|
|
8
9
|
*/
|
|
9
10
|
access?: 'public';
|
|
10
11
|
/**
|
|
11
|
-
* Add a random suffix to the uploaded file name
|
|
12
|
+
* Add a random suffix to the uploaded file name in Vercel Blob storage
|
|
12
13
|
*
|
|
13
14
|
* @default false
|
|
14
15
|
*/
|
|
@@ -16,7 +17,7 @@ export type VercelBlobStorageOptions = {
|
|
|
16
17
|
/**
|
|
17
18
|
* Cache-Control max-age in seconds
|
|
18
19
|
*
|
|
19
|
-
* @
|
|
20
|
+
* @defaultvalue 365 * 24 * 60 * 60 (1 Year)
|
|
20
21
|
*/
|
|
21
22
|
cacheControlMaxAge?: number;
|
|
22
23
|
/**
|
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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAA;AAS7C,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IAEjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAA;IAEtE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AASD,KAAK,uBAAuB,GAAG,CAAC,qBAAqB,EAAE,wBAAwB,KAAK,MAAM,CAAA;AAE1F,eAAO,MAAM,iBAAiB,EAAE,uBAgE7B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
2
2
|
import { getGenerateUrl } from './generateURL.js';
|
|
3
3
|
import { getHandleDelete } from './handleDelete.js';
|
|
4
4
|
import { getHandleUpload } from './handleUpload.js';
|
|
@@ -54,7 +54,7 @@ export const vercelBlobStorage = (options)=>(incomingConfig)=>{
|
|
|
54
54
|
};
|
|
55
55
|
})
|
|
56
56
|
};
|
|
57
|
-
return
|
|
57
|
+
return cloudStoragePlugin({
|
|
58
58
|
collections: collectionsWithAdapter
|
|
59
59
|
})(config);
|
|
60
60
|
};
|
|
@@ -62,6 +62,7 @@ function vercelBlobStorageInternal(options) {
|
|
|
62
62
|
return ({ collection, prefix })=>{
|
|
63
63
|
const { access, addRandomSuffix, baseUrl, cacheControlMaxAge, token } = options;
|
|
64
64
|
return {
|
|
65
|
+
name: 'vercel-blob',
|
|
65
66
|
generateURL: getGenerateUrl({
|
|
66
67
|
baseUrl,
|
|
67
68
|
prefix
|
|
@@ -81,6 +82,7 @@ function vercelBlobStorageInternal(options) {
|
|
|
81
82
|
}),
|
|
82
83
|
staticHandler: getStaticHandler({
|
|
83
84
|
baseUrl,
|
|
85
|
+
cacheControlMaxAge,
|
|
84
86
|
token
|
|
85
87
|
}, collection)
|
|
86
88
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import 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 { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { getGenerateUrl } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getStaticHandler } from './staticHandler.js'\n\nexport type VercelBlobStorageOptions = {\n /**\n * Access control level. Currently, only 'public' is supported.\n * Vercel plans on adding support for private blobs in the future.\n *\n * @default 'public'\n */\n access?: 'public'\n\n /**\n * Add a random suffix to the uploaded file name in Vercel Blob storage\n *\n * @default false\n */\n addRandomSuffix?: boolean\n\n /**\n * Cache-Control max-age in seconds\n *\n * @defaultvalue 365 * 24 * 60 * 60 (1 Year)\n */\n cacheControlMaxAge?: number\n\n /**\n * Collections to apply the Vercel Blob adapter to\n */\n collections: Record<string, Omit<CollectionOptions, 'adapter'> | true>\n\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n\n /**\n * Vercel Blob storage read/write token\n *\n * Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel\n */\n token: string\n}\n\nconst defaultUploadOptions: Partial<VercelBlobStorageOptions> = {\n access: 'public',\n addRandomSuffix: false,\n cacheControlMaxAge: 60 * 60 * 24 * 365, // 1 year\n enabled: true,\n}\n\ntype VercelBlobStoragePlugin = (vercelBlobStorageOpts: VercelBlobStorageOptions) => Plugin\n\nexport const vercelBlobStorage: VercelBlobStoragePlugin =\n (options: VercelBlobStorageOptions) =>\n (incomingConfig: Config): Config => {\n if (options.enabled === false) {\n return incomingConfig\n }\n\n if (!options.token) {\n throw new Error('The token argument is required for the Vercel Blob adapter.')\n }\n\n // Parse storeId from token\n const storeId = options.token.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]?.toLowerCase()\n\n if (!storeId) {\n throw new Error(\n 'Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.',\n )\n }\n\n const optionsWithDefaults = {\n ...defaultUploadOptions,\n ...options,\n }\n\n const baseUrl = `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`\n\n const adapter = vercelBlobStorageInternal({ ...optionsWithDefaults, baseUrl })\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.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 vercelBlobStorageInternal(\n options: { baseUrl: string } & VercelBlobStorageOptions,\n): Adapter {\n return ({ collection, prefix }): GeneratedAdapter => {\n const { access, addRandomSuffix, baseUrl, cacheControlMaxAge, token } = options\n return {\n name: 'vercel-blob',\n generateURL: getGenerateUrl({ baseUrl, prefix }),\n handleDelete: getHandleDelete({ baseUrl, prefix, token: options.token }),\n handleUpload: getHandleUpload({\n access,\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n prefix,\n token,\n }),\n staticHandler: getStaticHandler({ baseUrl, cacheControlMaxAge, token }, collection),\n }\n }\n}\n"],"names":["cloudStoragePlugin","getGenerateUrl","getHandleDelete","getHandleUpload","getStaticHandler","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","incomingConfig","token","Error","storeId","match","toLowerCase","optionsWithDefaults","baseUrl","adapter","vercelBlobStorageInternal","collectionsWithAdapter","Object","entries","collections","reduce","acc","slug","collOptions","config","map","collection","upload","disableLocalStorage","prefix","name","generateURL","handleDelete","handleUpload","staticHandler"],"mappings":"AAQA,SAASA,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,gBAAgB,QAAQ,qBAAoB;AA6CrD,MAAMC,uBAA0D;IAC9DC,QAAQ;IACRC,iBAAiB;IACjBC,oBAAoB,KAAK,KAAK,KAAK;IACnCC,SAAS;AACX;AAIA,OAAO,MAAMC,oBACX,CAACC,UACD,CAACC;QACC,IAAID,QAAQF,OAAO,KAAK,OAAO;YAC7B,OAAOG;QACT;QAEA,IAAI,CAACD,QAAQE,KAAK,EAAE;YAClB,MAAM,IAAIC,MAAM;QAClB;QAEA,2BAA2B;QAC3B,MAAMC,UAAUJ,QAAQE,KAAK,CAACG,KAAK,CAAC,0CAA0C,CAAC,EAAE,EAAEC;QAEnF,IAAI,CAACF,SAAS;YACZ,MAAM,IAAID,MACR;QAEJ;QAEA,MAAMI,sBAAsB;YAC1B,GAAGb,oBAAoB;YACvB,GAAGM,OAAO;QACZ;QAEA,MAAMQ,UAAU,CAAC,QAAQ,EAAEJ,QAAQ,CAAC,EAAEG,oBAAoBZ,MAAM,CAAC,wBAAwB,CAAC;QAE1F,MAAMc,UAAUC,0BAA0B;YAAE,GAAGH,mBAAmB;YAAEC;QAAQ;QAE5E,+CAA+C;QAC/C,MAAMG,yBAAmEC,OAAOC,OAAO,CACrFb,QAAQc,WAAW,EACnBC,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,GAAGlB,cAAc;YACjBa,aAAa,AAACb,CAAAA,eAAea,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,OAAOlC,mBAAmB;YACxByB,aAAaH;QACf,GAAGQ;IACL,EAAC;AAEH,SAAST,0BACPV,OAAuD;IAEvD,OAAO,CAAC,EAAEqB,UAAU,EAAEG,MAAM,EAAE;QAC5B,MAAM,EAAE7B,MAAM,EAAEC,eAAe,EAAEY,OAAO,EAAEX,kBAAkB,EAAEK,KAAK,EAAE,GAAGF;QACxE,OAAO;YACLyB,MAAM;YACNC,aAAapC,eAAe;gBAAEkB;gBAASgB;YAAO;YAC9CG,cAAcpC,gBAAgB;gBAAEiB;gBAASgB;gBAAQtB,OAAOF,QAAQE,KAAK;YAAC;YACtE0B,cAAcpC,gBAAgB;gBAC5BG;gBACAC;gBACAY;gBACAX;gBACA2B;gBACAtB;YACF;YACA2B,eAAepC,iBAAiB;gBAAEe;gBAASX;gBAAoBK;YAAM,GAAGmB;QAC1E;IACF;AACF"}
|
package/dist/staticHandler.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { CollectionConfig } from 'payload
|
|
2
|
+
import type { CollectionConfig } from 'payload';
|
|
3
3
|
type StaticHandlerArgs = {
|
|
4
4
|
baseUrl: string;
|
|
5
|
+
cacheControlMaxAge?: number;
|
|
5
6
|
token: string;
|
|
6
7
|
};
|
|
7
|
-
export declare const getStaticHandler: ({ baseUrl, token }: StaticHandlerArgs, collection: CollectionConfig) => StaticHandler;
|
|
8
|
+
export declare const getStaticHandler: ({ baseUrl, cacheControlMaxAge, token }: StaticHandlerArgs, collection: CollectionConfig) => StaticHandler;
|
|
8
9
|
export {};
|
|
9
10
|
//# sourceMappingURL=staticHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,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,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAM/C,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,gBAAgB,2CACiB,iBAAiB,cACjD,gBAAgB,KAC3B,aAoCF,CAAA"}
|
package/dist/staticHandler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
2
2
|
import { head } from '@vercel/blob';
|
|
3
3
|
import path from 'path';
|
|
4
|
-
export const getStaticHandler = ({ baseUrl, token }, collection)=>{
|
|
4
|
+
export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, collection)=>{
|
|
5
5
|
return async (req, { params: { filename } })=>{
|
|
6
6
|
try {
|
|
7
7
|
const prefix = await getFilePrefix({
|
|
@@ -31,6 +31,7 @@ export const getStaticHandler = ({ baseUrl, token }, collection)=>{
|
|
|
31
31
|
const bodyBuffer = await blob.arrayBuffer();
|
|
32
32
|
return new Response(bodyBuffer, {
|
|
33
33
|
headers: new Headers({
|
|
34
|
+
'Cache-Control': `public, max-age=${cacheControlMaxAge}`,
|
|
34
35
|
'Content-Disposition': contentDisposition,
|
|
35
36
|
'Content-Length': String(size),
|
|
36
37
|
'Content-Type': contentType
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig } from 'payload'\n\nimport { getFilePrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { head } from '@vercel/blob'\nimport path from 'path'\n\ntype StaticHandlerArgs = {\n baseUrl: string\n cacheControlMaxAge?: number\n token: string\n}\n\nexport const getStaticHandler = (\n { baseUrl, cacheControlMaxAge = 0, token }: StaticHandlerArgs,\n collection: CollectionConfig,\n): StaticHandler => {\n return async (req, { params: { filename } }) => {\n try {\n const prefix = await getFilePrefix({ collection, filename, req })\n\n const fileUrl = `${baseUrl}/${path.posix.join(prefix, filename)}`\n\n const blobMetadata = await head(fileUrl, { token })\n if (!blobMetadata) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\n\n const { contentDisposition, contentType, size } = blobMetadata\n const response = await fetch(fileUrl)\n const blob = await response.blob()\n\n if (!blob) {\n return new Response(null, { status: 204, statusText: 'No Content' })\n }\n\n const bodyBuffer = await blob.arrayBuffer()\n\n return new Response(bodyBuffer, {\n headers: new Headers({\n 'Cache-Control': `public, max-age=${cacheControlMaxAge}`,\n 'Content-Disposition': contentDisposition,\n 'Content-Length': String(size),\n 'Content-Type': contentType,\n }),\n status: 200,\n })\n } catch (err: unknown) {\n req.payload.logger.error({ err, msg: 'Unexpected error in staticHandler' })\n return new Response('Internal Server Error', { status: 500 })\n }\n }\n}\n"],"names":["getFilePrefix","head","path","getStaticHandler","baseUrl","cacheControlMaxAge","token","collection","req","params","filename","prefix","fileUrl","posix","join","blobMetadata","Response","status","statusText","contentDisposition","contentType","size","response","fetch","blob","bodyBuffer","arrayBuffer","headers","Headers","String","err","payload","logger","error","msg"],"mappings":"AAGA,SAASA,aAAa,QAAQ,6CAA4C;AAC1E,SAASC,IAAI,QAAQ,eAAc;AACnC,OAAOC,UAAU,OAAM;AAQvB,OAAO,MAAMC,mBAAmB,CAC9B,EAAEC,OAAO,EAAEC,qBAAqB,CAAC,EAAEC,KAAK,EAAqB,EAC7DC;IAEA,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAE;QACzC,IAAI;YACF,MAAMC,SAAS,MAAMX,cAAc;gBAAEO;gBAAYG;gBAAUF;YAAI;YAE/D,MAAMI,UAAU,CAAC,EAAER,QAAQ,CAAC,EAAEF,KAAKW,KAAK,CAACC,IAAI,CAACH,QAAQD,UAAU,CAAC;YAEjE,MAAMK,eAAe,MAAMd,KAAKW,SAAS;gBAAEN;YAAM;YACjD,IAAI,CAACS,cAAc;gBACjB,OAAO,IAAIC,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAY;YACnE;YAEA,MAAM,EAAEC,kBAAkB,EAAEC,WAAW,EAAEC,IAAI,EAAE,GAAGN;YAClD,MAAMO,WAAW,MAAMC,MAAMX;YAC7B,MAAMY,OAAO,MAAMF,SAASE,IAAI;YAEhC,IAAI,CAACA,MAAM;gBACT,OAAO,IAAIR,SAAS,MAAM;oBAAEC,QAAQ;oBAAKC,YAAY;gBAAa;YACpE;YAEA,MAAMO,aAAa,MAAMD,KAAKE,WAAW;YAEzC,OAAO,IAAIV,SAASS,YAAY;gBAC9BE,SAAS,IAAIC,QAAQ;oBACnB,iBAAiB,CAAC,gBAAgB,EAAEvB,mBAAmB,CAAC;oBACxD,uBAAuBc;oBACvB,kBAAkBU,OAAOR;oBACzB,gBAAgBD;gBAClB;gBACAH,QAAQ;YACV;QACF,EAAE,OAAOa,KAAc;YACrBtB,IAAIuB,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;gBAAEH;gBAAKI,KAAK;YAAoC;YACzE,OAAO,IAAIlB,SAAS,yBAAyB;gBAAEC,QAAQ;YAAI;QAC7D;IACF;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-vercel-blob",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.130",
|
|
4
4
|
"description": "Payload storage adapter for Vercel Blob 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-vercel-blob"
|
|
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
|
"@vercel/blob": "^0.22.3",
|
|
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
|
}
|