@payloadcms/plugin-cloud-storage 3.0.0-beta.6 → 3.0.0-beta.7
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 +15 -0
- package/dist/adapters/vercelBlob/generateURL.d.ts +8 -0
- package/dist/adapters/vercelBlob/generateURL.d.ts.map +1 -0
- package/dist/adapters/vercelBlob/generateURL.js +8 -0
- package/dist/adapters/vercelBlob/generateURL.js.map +1 -0
- package/dist/adapters/vercelBlob/handleDelete.d.ts +9 -0
- package/dist/adapters/vercelBlob/handleDelete.d.ts.map +1 -0
- package/dist/adapters/vercelBlob/handleDelete.js +13 -0
- package/dist/adapters/vercelBlob/handleDelete.js.map +1 -0
- package/dist/adapters/vercelBlob/handleUpload.d.ts +10 -0
- package/dist/adapters/vercelBlob/handleUpload.d.ts.map +1 -0
- package/dist/adapters/vercelBlob/handleUpload.js +21 -0
- package/dist/adapters/vercelBlob/handleUpload.js.map +1 -0
- package/dist/adapters/vercelBlob/index.d.ts +32 -0
- package/dist/adapters/vercelBlob/index.d.ts.map +1 -0
- package/dist/adapters/vercelBlob/index.js +49 -0
- package/dist/adapters/vercelBlob/index.js.map +1 -0
- package/dist/adapters/vercelBlob/staticHandler.d.ts +9 -0
- package/dist/adapters/vercelBlob/staticHandler.d.ts.map +1 -0
- package/dist/adapters/vercelBlob/staticHandler.js +51 -0
- package/dist/adapters/vercelBlob/staticHandler.js.map +1 -0
- package/dist/exports/utilities.d.ts +2 -0
- package/dist/exports/utilities.d.ts.map +1 -0
- package/dist/exports/utilities.js +3 -0
- package/dist/exports/utilities.js.map +1 -0
- package/dist/exports/vercelBlob.d.ts +2 -0
- package/dist/exports/vercelBlob.d.ts.map +1 -0
- package/dist/exports/vercelBlob.js +3 -0
- package/dist/exports/vercelBlob.js.map +1 -0
- package/package.json +9 -4
- package/azure.d.ts +0 -2
- package/azure.js +0 -3
- package/gcs.d.ts +0 -2
- package/gcs.js +0 -3
- package/s3.d.ts +0 -2
- package/s3.js +0 -3
package/README.md
CHANGED
|
@@ -63,6 +63,7 @@ This plugin supports the following adapters:
|
|
|
63
63
|
- [Azure Blob Storage](#azure-blob-storage-adapter)
|
|
64
64
|
- [AWS S3-style Storage](#s3-adapter)
|
|
65
65
|
- [Google Cloud Storage](#gcs-adapter)
|
|
66
|
+
- [Vercel Blob Storage](#vercel-blob-adapter)
|
|
66
67
|
|
|
67
68
|
However, you can create your own adapter for any third-party service you would like to use.
|
|
68
69
|
|
|
@@ -176,6 +177,20 @@ const adapter = gcsAdapter({
|
|
|
176
177
|
// Now you can pass this adapter to the plugin
|
|
177
178
|
```
|
|
178
179
|
|
|
180
|
+
### Vercel Blob Adapter
|
|
181
|
+
|
|
182
|
+
To use the Vercel Blob adapter, you need to have `@vercel/blob` installed in your project dependencies.
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
import { vercelBlobAdapter } from '@payloadcms/plugin-cloud-storage/vercelBlob'
|
|
186
|
+
|
|
187
|
+
const adapter = vercelBlobAdapter({
|
|
188
|
+
token: process.env.BLOB_READ_WRITE_TOKEN || '',
|
|
189
|
+
})
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Credit to @JarvisPrestidge for the original implementation of this plugin.
|
|
193
|
+
|
|
179
194
|
### Payload Access Control
|
|
180
195
|
|
|
181
196
|
Payload ships with access control that runs _even on statically served files_. The same `read` access control property on your `upload`-enabled collections is used, and it allows you to restrict who can request your uploaded files.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GenerateURL } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
type GenerateUrlArgs = {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
prefix?: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const getGenerateUrl: ({ baseUrl }: GenerateUrlArgs) => GenerateURL;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=generateURL.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateURL.d.ts","sourceRoot":"","sources":["../../../src/adapters/vercelBlob/generateURL.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAA;AAIzE,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,cAAc,gBAAiB,eAAe,KAAG,WAI7D,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/vercelBlob/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"],"rangeMappings":";;;;;","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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HandleDelete } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
type HandleDeleteArgs = {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
prefix?: string;
|
|
5
|
+
token: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const getHandleDelete: ({ baseUrl, token }: HandleDeleteArgs) => HandleDelete;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=handleDelete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleDelete.d.ts","sourceRoot":"","sources":["../../../src/adapters/vercelBlob/handleDelete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAK1E,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,eAAe,uBAAwB,gBAAgB,KAAG,YAOtE,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { del } from '@vercel/blob';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export const getHandleDelete = ({ baseUrl, token })=>{
|
|
4
|
+
return async ({ doc: { prefix = '' }, filename })=>{
|
|
5
|
+
const fileUrl = `${baseUrl}/${path.posix.join(prefix, filename)}`;
|
|
6
|
+
const deletedBlob = await del(fileUrl, {
|
|
7
|
+
token
|
|
8
|
+
});
|
|
9
|
+
return deletedBlob;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=handleDelete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/vercelBlob/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"],"rangeMappings":";;;;;;;;;;","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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HandleUpload } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { VercelBlobAdapterUploadOptions } from './index.js';
|
|
3
|
+
type HandleUploadArgs = VercelBlobAdapterUploadOptions & {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
token: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const getHandleUpload: ({ access, addRandomSuffix, baseUrl, cacheControlMaxAge, prefix, token, }: HandleUploadArgs) => HandleUpload;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=handleUpload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../../../src/adapters/vercelBlob/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAA;AAK1E,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAA;AAEhE,KAAK,gBAAgB,GAAG,8BAA8B,GAAG;IACvD,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,eAAe,6EAOzB,gBAAgB,KAAG,YAmBrB,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { put } from '@vercel/blob';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
export const getHandleUpload = ({ access = 'public', addRandomSuffix, baseUrl, cacheControlMaxAge, prefix = '', token })=>{
|
|
4
|
+
return async ({ data, file: { buffer, filename, mimeType } })=>{
|
|
5
|
+
const fileKey = path.posix.join(data.prefix || prefix, filename);
|
|
6
|
+
const result = await put(fileKey, buffer, {
|
|
7
|
+
access,
|
|
8
|
+
addRandomSuffix,
|
|
9
|
+
cacheControlMaxAge,
|
|
10
|
+
contentType: mimeType,
|
|
11
|
+
token
|
|
12
|
+
});
|
|
13
|
+
// Get filename with suffix from returned url
|
|
14
|
+
if (addRandomSuffix) {
|
|
15
|
+
data.filename = result.url.replace(`${baseUrl}/`, '');
|
|
16
|
+
}
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=handleUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/vercelBlob/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 { VercelBlobAdapterUploadOptions } from './index.js'\n\ntype HandleUploadArgs = VercelBlobAdapterUploadOptions & {\n baseUrl: string\n prefix?: string\n token: string\n}\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"],"rangeMappings":";;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,GAAG,QAAQ,eAAc;AAClC,OAAOC,UAAU,OAAM;AAUvB,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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Adapter } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
export interface VercelBlobAdapterArgs {
|
|
3
|
+
options?: VercelBlobAdapterUploadOptions;
|
|
4
|
+
/**
|
|
5
|
+
* Vercel Blob storage read/write token
|
|
6
|
+
*
|
|
7
|
+
* Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel
|
|
8
|
+
*/
|
|
9
|
+
token: string;
|
|
10
|
+
}
|
|
11
|
+
export interface VercelBlobAdapterUploadOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Access control level
|
|
14
|
+
*
|
|
15
|
+
* @default 'public'
|
|
16
|
+
*/
|
|
17
|
+
access?: 'public';
|
|
18
|
+
/**
|
|
19
|
+
* Add a random suffix to the uploaded file name
|
|
20
|
+
*
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
addRandomSuffix?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Cache-Control max-age in seconds
|
|
26
|
+
*
|
|
27
|
+
* @default 31536000 (1 year)
|
|
28
|
+
*/
|
|
29
|
+
cacheControlMaxAge?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare const vercelBlobAdapter: ({ options, token }: VercelBlobAdapterArgs) => Adapter;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/vercelBlob/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAoB,MAAM,wCAAwC,CAAA;AAOvF,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,8BAA8B,CAAA;IAExC;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IACjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAQD,eAAO,MAAM,iBAAiB,uBACF,qBAAqB,KAAG,OAmCjD,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { getGenerateUrl } from './generateURL.js';
|
|
2
|
+
import { getHandleDelete } from './handleDelete.js';
|
|
3
|
+
import { getHandleUpload } from './handleUpload.js';
|
|
4
|
+
import { getStaticHandler } from './staticHandler.js';
|
|
5
|
+
const defaultUploadOptions = {
|
|
6
|
+
access: 'public',
|
|
7
|
+
addRandomSuffix: false,
|
|
8
|
+
cacheControlMaxAge: 60 * 60 * 24 * 365
|
|
9
|
+
};
|
|
10
|
+
export const vercelBlobAdapter = ({ options = {}, token })=>({ collection, prefix })=>{
|
|
11
|
+
if (!token) {
|
|
12
|
+
throw new Error('The token argument is required for the Vercel Blob adapter.');
|
|
13
|
+
}
|
|
14
|
+
// Parse storeId from token
|
|
15
|
+
const storeId = token.match(/^vercel_blob_rw_([a-z\d]+)_[a-z\d]+$/i)?.[1].toLowerCase();
|
|
16
|
+
if (!storeId) {
|
|
17
|
+
throw new Error('Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.');
|
|
18
|
+
}
|
|
19
|
+
const { access, addRandomSuffix, cacheControlMaxAge } = {
|
|
20
|
+
...defaultUploadOptions,
|
|
21
|
+
...options
|
|
22
|
+
};
|
|
23
|
+
const baseUrl = `https://${storeId}.${access}.blob.vercel-storage.com`;
|
|
24
|
+
return {
|
|
25
|
+
generateURL: getGenerateUrl({
|
|
26
|
+
baseUrl,
|
|
27
|
+
prefix
|
|
28
|
+
}),
|
|
29
|
+
handleDelete: getHandleDelete({
|
|
30
|
+
baseUrl,
|
|
31
|
+
prefix,
|
|
32
|
+
token
|
|
33
|
+
}),
|
|
34
|
+
handleUpload: getHandleUpload({
|
|
35
|
+
access,
|
|
36
|
+
addRandomSuffix,
|
|
37
|
+
baseUrl,
|
|
38
|
+
cacheControlMaxAge,
|
|
39
|
+
prefix,
|
|
40
|
+
token
|
|
41
|
+
}),
|
|
42
|
+
staticHandler: getStaticHandler({
|
|
43
|
+
baseUrl,
|
|
44
|
+
token
|
|
45
|
+
}, collection)
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/vercelBlob/index.ts"],"sourcesContent":["import type { Adapter, GeneratedAdapter } from '@payloadcms/plugin-cloud-storage/types'\n\nimport { getGenerateUrl } from './generateURL.js'\nimport { getHandleDelete } from './handleDelete.js'\nimport { getHandleUpload } from './handleUpload.js'\nimport { getStaticHandler } from './staticHandler.js'\n\nexport interface VercelBlobAdapterArgs {\n options?: VercelBlobAdapterUploadOptions\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\nexport interface VercelBlobAdapterUploadOptions {\n /**\n * Access control level\n *\n * @default 'public'\n */\n access?: 'public'\n /**\n * Add a random suffix to the uploaded file name\n *\n * @default false\n */\n addRandomSuffix?: boolean\n /**\n * Cache-Control max-age in seconds\n *\n * @default 31536000 (1 year)\n */\n cacheControlMaxAge?: number\n}\n\nconst defaultUploadOptions: VercelBlobAdapterUploadOptions = {\n access: 'public',\n addRandomSuffix: false,\n cacheControlMaxAge: 60 * 60 * 24 * 365, // 1 year\n}\n\nexport const vercelBlobAdapter =\n ({ options = {}, token }: VercelBlobAdapterArgs): Adapter =>\n ({ collection, prefix }): GeneratedAdapter => {\n if (!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 = 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 { access, addRandomSuffix, cacheControlMaxAge } = {\n ...defaultUploadOptions,\n ...options,\n }\n\n const baseUrl = `https://${storeId}.${access}.blob.vercel-storage.com`\n\n return {\n generateURL: getGenerateUrl({ baseUrl, prefix }),\n handleDelete: getHandleDelete({ baseUrl, prefix, token }),\n handleUpload: getHandleUpload({\n access,\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n prefix,\n token,\n }),\n staticHandler: getStaticHandler({ baseUrl, token }, collection),\n }\n }\n"],"names":["getGenerateUrl","getHandleDelete","getHandleUpload","getStaticHandler","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","vercelBlobAdapter","options","token","collection","prefix","Error","storeId","match","toLowerCase","baseUrl","generateURL","handleDelete","handleUpload","staticHandler"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,mBAAkB;AACjD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,eAAe,QAAQ,oBAAmB;AACnD,SAASC,gBAAgB,QAAQ,qBAAoB;AAkCrD,MAAMC,uBAAuD;IAC3DC,QAAQ;IACRC,iBAAiB;IACjBC,oBAAoB,KAAK,KAAK,KAAK;AACrC;AAEA,OAAO,MAAMC,oBACX,CAAC,EAAEC,UAAU,CAAC,CAAC,EAAEC,KAAK,EAAyB,GAC/C,CAAC,EAAEC,UAAU,EAAEC,MAAM,EAAE;QACrB,IAAI,CAACF,OAAO;YACV,MAAM,IAAIG,MAAM;QAClB;QAEA,2BAA2B;QAC3B,MAAMC,UAAUJ,MAAMK,KAAK,CAAC,0CAA0C,CAAC,EAAE,CAACC;QAE1E,IAAI,CAACF,SAAS;YACZ,MAAM,IAAID,MACR;QAEJ;QAEA,MAAM,EAAER,MAAM,EAAEC,eAAe,EAAEC,kBAAkB,EAAE,GAAG;YACtD,GAAGH,oBAAoB;YACvB,GAAGK,OAAO;QACZ;QAEA,MAAMQ,UAAU,CAAC,QAAQ,EAAEH,QAAQ,CAAC,EAAET,OAAO,wBAAwB,CAAC;QAEtE,OAAO;YACLa,aAAalB,eAAe;gBAAEiB;gBAASL;YAAO;YAC9CO,cAAclB,gBAAgB;gBAAEgB;gBAASL;gBAAQF;YAAM;YACvDU,cAAclB,gBAAgB;gBAC5BG;gBACAC;gBACAW;gBACAV;gBACAK;gBACAF;YACF;YACAW,eAAelB,iBAAiB;gBAAEc;gBAASP;YAAM,GAAGC;QACtD;IACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
+
import type { CollectionConfig } from 'payload/types';
|
|
3
|
+
type StaticHandlerArgs = {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
token: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const getStaticHandler: ({ baseUrl, token }: StaticHandlerArgs, collection: CollectionConfig) => StaticHandler;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=staticHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../../../src/adapters/vercelBlob/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,KAAK,EAAE,gBAAgB,EAAgC,MAAM,eAAe,CAAA;AAOnF,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,gBAAgB,uBACP,iBAAiB,cACzB,gBAAgB,KAC3B,aAmCF,CAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { head } from '@vercel/blob';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getFilePrefix } from '../../utilities/getFilePrefix.js';
|
|
4
|
+
export const getStaticHandler = ({ baseUrl, token }, collection)=>{
|
|
5
|
+
return async (req, { params: { filename } })=>{
|
|
6
|
+
try {
|
|
7
|
+
const prefix = await getFilePrefix({
|
|
8
|
+
collection,
|
|
9
|
+
req
|
|
10
|
+
});
|
|
11
|
+
const fileUrl = `${baseUrl}/${path.posix.join(prefix, filename)}`;
|
|
12
|
+
const blobMetadata = await head(fileUrl, {
|
|
13
|
+
token
|
|
14
|
+
});
|
|
15
|
+
if (!blobMetadata) {
|
|
16
|
+
return new Response(null, {
|
|
17
|
+
status: 404,
|
|
18
|
+
statusText: 'Not Found'
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
const { contentDisposition, contentType, size } = blobMetadata;
|
|
22
|
+
const response = await fetch(fileUrl);
|
|
23
|
+
const blob = await response.blob();
|
|
24
|
+
if (!blob) {
|
|
25
|
+
return new Response(null, {
|
|
26
|
+
status: 204,
|
|
27
|
+
statusText: 'No Content'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
const bodyBuffer = await blob.arrayBuffer();
|
|
31
|
+
return new Response(bodyBuffer, {
|
|
32
|
+
headers: new Headers({
|
|
33
|
+
'Content-Disposition': contentDisposition,
|
|
34
|
+
'Content-Length': String(size),
|
|
35
|
+
'Content-Type': contentType
|
|
36
|
+
}),
|
|
37
|
+
status: 200
|
|
38
|
+
});
|
|
39
|
+
} catch (err) {
|
|
40
|
+
req.payload.logger.error({
|
|
41
|
+
err,
|
|
42
|
+
msg: 'Unexpected error in staticHandler'
|
|
43
|
+
});
|
|
44
|
+
return new Response('Internal Server Error', {
|
|
45
|
+
status: 500
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=staticHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/vercelBlob/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@payloadcms/plugin-cloud-storage/types'\nimport type { CollectionConfig, PayloadRequest, UploadConfig } from 'payload/types'\n\nimport { head } from '@vercel/blob'\nimport path from 'path'\n\nimport { getFilePrefix } from '../../utilities/getFilePrefix.js'\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, 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":["head","path","getFilePrefix","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,IAAI,QAAQ,eAAc;AACnC,OAAOC,UAAU,OAAM;AAEvB,SAASC,aAAa,QAAQ,mCAAkC;AAOhE,OAAO,MAAMC,mBAAmB,CAC9B,EAAEC,OAAO,EAAEC,KAAK,EAAqB,EACrCC;IAEA,OAAO,OAAOC,KAAK,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,EAAE;QACzC,IAAI;YACF,MAAMC,SAAS,MAAMR,cAAc;gBAAEI;gBAAYC;YAAI;YAErD,MAAMI,UAAU,CAAC,EAAEP,QAAQ,CAAC,EAAEH,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,uBAAuBT;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../../src/exports/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/utilities.ts"],"sourcesContent":["export { getFilePrefix } from '../utilities/getFilePrefix.js'\n"],"names":["getFilePrefix"],"rangeMappings":"","mappings":"AAAA,SAASA,aAAa,QAAQ,gCAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vercelBlob.d.ts","sourceRoot":"","sources":["../../src/exports/vercelBlob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/vercelBlob.ts"],"sourcesContent":["export { vercelBlobAdapter } from '../adapters/vercelBlob/index.js'\n"],"names":["vercelBlobAdapter"],"rangeMappings":"","mappings":"AAAA,SAASA,iBAAiB,QAAQ,kCAAiC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-cloud-storage",
|
|
3
3
|
"description": "The official cloud storage plugin for Payload CMS",
|
|
4
|
-
"version": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.7",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"@azure/abort-controller": "^1.0.0",
|
|
19
19
|
"@azure/storage-blob": "^12.11.0",
|
|
20
20
|
"@google-cloud/storage": "^7.7.0",
|
|
21
|
-
"
|
|
21
|
+
"@vercel/blob": "^0.22.3",
|
|
22
|
+
"payload": "3.0.0-beta.7"
|
|
22
23
|
},
|
|
23
24
|
"peerDependenciesMeta": {
|
|
24
25
|
"@aws-sdk/client-s3": {
|
|
@@ -35,6 +36,9 @@
|
|
|
35
36
|
},
|
|
36
37
|
"@google-cloud/storage": {
|
|
37
38
|
"optional": true
|
|
39
|
+
},
|
|
40
|
+
"@vercel/blob": {
|
|
41
|
+
"optional": true
|
|
38
42
|
}
|
|
39
43
|
},
|
|
40
44
|
"files": [
|
|
@@ -48,7 +52,8 @@
|
|
|
48
52
|
"@azure/storage-blob": "^12.11.0",
|
|
49
53
|
"@google-cloud/storage": "^7.7.0",
|
|
50
54
|
"@types/find-node-modules": "^2.1.2",
|
|
51
|
-
"
|
|
55
|
+
"@vercel/blob": "^0.22.3",
|
|
56
|
+
"payload": "3.0.0-beta.7"
|
|
52
57
|
},
|
|
53
58
|
"dependencies": {
|
|
54
59
|
"find-node-modules": "^2.1.3",
|
|
@@ -75,7 +80,7 @@
|
|
|
75
80
|
"registry": "https://registry.npmjs.org/"
|
|
76
81
|
},
|
|
77
82
|
"scripts": {
|
|
78
|
-
"build": "pnpm build:swc && pnpm build:types
|
|
83
|
+
"build": "pnpm build:swc && pnpm build:types",
|
|
79
84
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
|
80
85
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
81
86
|
"clean": "rimraf {dist,*.tsbuildinfo}",
|
package/azure.d.ts
DELETED
package/azure.js
DELETED
package/gcs.d.ts
DELETED
package/gcs.js
DELETED
package/s3.d.ts
DELETED
package/s3.js
DELETED