@payloadcms/storage-vercel-blob 3.0.0-canary.ff8c8fd → 3.0.1-canary.34c6cc0
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/staticHandler.d.ts +2 -1
- package/dist/staticHandler.d.ts.map +1 -1
- package/dist/staticHandler.js +2 -1
- package/dist/staticHandler.js.map +1 -1
- package/package.json +14 -5
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
|
@@ -28,8 +28,8 @@ export default buildConfig({
|
|
|
28
28
|
enabled: true, // Optional, defaults to true
|
|
29
29
|
// Specify which collections should use Vercel Blob
|
|
30
30
|
collections: {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
media: true,
|
|
32
|
+
'media-with-prefix': {
|
|
33
33
|
prefix: 'my-prefix',
|
|
34
34
|
},
|
|
35
35
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type { Plugin } from 'payload';
|
|
2
|
+
import type { Plugin, UploadCollectionSlug } from 'payload';
|
|
3
3
|
export type VercelBlobStorageOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Access control level. Currently, only 'public' is supported.
|
|
@@ -23,7 +23,7 @@ export type VercelBlobStorageOptions = {
|
|
|
23
23
|
/**
|
|
24
24
|
* Collections to apply the Vercel Blob adapter to
|
|
25
25
|
*/
|
|
26
|
-
collections: Record<
|
|
26
|
+
collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>;
|
|
27
27
|
/**
|
|
28
28
|
* Whether or not to enable the plugin
|
|
29
29
|
*
|
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,EAGV,iBAAiB,EAElB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAA;
|
|
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,oBAAoB,EAAE,MAAM,SAAS,CAAA;AASnE,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,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAE7F;;;;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
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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<
|
|
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, UploadCollectionSlug } 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: Partial<Record<UploadCollectionSlug, 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
|
@@ -2,8 +2,9 @@ import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
|
2
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,SAAS,CAAA;AAM/C,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,gBAAgB,
|
|
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'\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 token: string\n}\n\nexport const getStaticHandler = (\n { baseUrl, 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 '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","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;
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-vercel-blob",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1-canary.34c6cc0",
|
|
4
4
|
"description": "Payload storage adapter for Vercel Blob Storage",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
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
|
+
],
|
|
13
20
|
"type": "module",
|
|
14
21
|
"exports": {
|
|
15
22
|
".": {
|
|
@@ -25,13 +32,13 @@
|
|
|
25
32
|
],
|
|
26
33
|
"dependencies": {
|
|
27
34
|
"@vercel/blob": "^0.22.3",
|
|
28
|
-
"@payloadcms/plugin-cloud-storage": "3.0.
|
|
35
|
+
"@payloadcms/plugin-cloud-storage": "3.0.1-canary.34c6cc0"
|
|
29
36
|
},
|
|
30
37
|
"devDependencies": {
|
|
31
|
-
"payload": "3.0.
|
|
38
|
+
"payload": "3.0.1-canary.34c6cc0"
|
|
32
39
|
},
|
|
33
40
|
"peerDependencies": {
|
|
34
|
-
"payload": "3.0.
|
|
41
|
+
"payload": "3.0.1-canary.34c6cc0"
|
|
35
42
|
},
|
|
36
43
|
"engines": {
|
|
37
44
|
"node": "^18.20.2 || >=20.9.0"
|
|
@@ -41,6 +48,8 @@
|
|
|
41
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",
|
|
42
49
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
43
50
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
44
|
-
"clean": "rimraf {dist,*.tsbuildinfo}"
|
|
51
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
52
|
+
"lint": "eslint .",
|
|
53
|
+
"lint:fix": "eslint . --fix"
|
|
45
54
|
}
|
|
46
55
|
}
|