@ruya.sa/storage-vercel-blob 3.71.3
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 +22 -0
- package/README.md +51 -0
- package/dist/client/VercelBlobClientUploadHandler.d.ts +14 -0
- package/dist/client/VercelBlobClientUploadHandler.d.ts.map +1 -0
- package/dist/client/VercelBlobClientUploadHandler.js +28 -0
- package/dist/client/VercelBlobClientUploadHandler.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +3 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/generateURL.d.ts +8 -0
- package/dist/generateURL.d.ts.map +1 -0
- package/dist/generateURL.js +8 -0
- package/dist/generateURL.js.map +1 -0
- package/dist/getClientUploadRoute.d.ts +13 -0
- package/dist/getClientUploadRoute.d.ts.map +1 -0
- package/dist/getClientUploadRoute.js +35 -0
- package/dist/getClientUploadRoute.js.map +1 -0
- package/dist/handleDelete.d.ts +9 -0
- package/dist/handleDelete.d.ts.map +1 -0
- package/dist/handleDelete.js +13 -0
- package/dist/handleDelete.js.map +1 -0
- package/dist/handleUpload.d.ts +9 -0
- package/dist/handleUpload.d.ts.map +1 -0
- package/dist/handleUpload.js +21 -0
- package/dist/handleUpload.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +117 -0
- package/dist/index.js.map +1 -0
- package/dist/staticHandler.d.ts +10 -0
- package/dist/staticHandler.d.ts.map +1 -0
- package/dist/staticHandler.js +93 -0
- package/dist/staticHandler.js.map +1 -0
- package/package.json +62 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018-2025 Payload CMS, Inc. <info@payloadcms.com>
|
|
4
|
+
|
|
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
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
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
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
- When deploying to Vercel, server uploads are limited with 4.5MB. Set `clientUploads` to `true` to do uploads directly on the client.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'
|
|
22
|
+
import { Media } from './collections/Media'
|
|
23
|
+
import { MediaWithPrefix } from './collections/MediaWithPrefix'
|
|
24
|
+
|
|
25
|
+
export default buildConfig({
|
|
26
|
+
collections: [Media, MediaWithPrefix],
|
|
27
|
+
plugins: [
|
|
28
|
+
vercelBlobStorage({
|
|
29
|
+
enabled: true, // Optional, defaults to true
|
|
30
|
+
// Specify which collections should use Vercel Blob
|
|
31
|
+
collections: {
|
|
32
|
+
media: true,
|
|
33
|
+
'media-with-prefix': {
|
|
34
|
+
prefix: 'my-prefix',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
// Token provided by Vercel once Blob storage is added to your Vercel project
|
|
38
|
+
token: process.env.BLOB_READ_WRITE_TOKEN,
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
| Option | Description | Default |
|
|
45
|
+
| -------------------- | -------------------------------------------------------------------- | ----------------------------- |
|
|
46
|
+
| `enabled` | Whether or not to enable the plugin | `true` |
|
|
47
|
+
| `collections` | Collections to apply the Vercel Blob adapter to | |
|
|
48
|
+
| `addRandomSuffix` | Add a random suffix to the uploaded file name in Vercel Blob storage | `false` |
|
|
49
|
+
| `cacheControlMaxAge` | Cache-Control max-age in seconds | `365 * 24 * 60 * 60` (1 Year) |
|
|
50
|
+
| `token` | Vercel Blob storage read/write token | `''` |
|
|
51
|
+
| `clientUploads` | Do uploads directly on the client to bypass limits on Vercel | |
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type VercelBlobClientUploadHandlerExtra = {
|
|
2
|
+
addRandomSuffix: boolean;
|
|
3
|
+
baseURL: string;
|
|
4
|
+
prefix: string;
|
|
5
|
+
};
|
|
6
|
+
export declare const VercelBlobClientUploadHandler: ({ children, collectionSlug, enabled, extra, prefix, serverHandlerPath, }: {
|
|
7
|
+
children: import("react").ReactNode;
|
|
8
|
+
collectionSlug: import("@ruya.sa/payload").UploadCollectionSlug;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
extra: VercelBlobClientUploadHandlerExtra;
|
|
11
|
+
prefix?: string;
|
|
12
|
+
serverHandlerPath: `/${string}`;
|
|
13
|
+
}) => import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=VercelBlobClientUploadHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VercelBlobClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,kCAAkC,GAAG;IAC/C,eAAe,EAAE,OAAO,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,6BAA6B;;;;;;;aAkB7B,OAAO,aAYhB,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createClientUploadHandler } from '@ruya.sa/plugin-cloud-storage/client';
|
|
3
|
+
import { upload } from '@vercel/blob/client';
|
|
4
|
+
import { formatAdminURL } from '@ruya.sa/payload/shared';
|
|
5
|
+
export const VercelBlobClientUploadHandler = createClientUploadHandler({
|
|
6
|
+
handler: async ({ apiRoute, collectionSlug, extra: { addRandomSuffix, baseURL, prefix = '' }, file, serverHandlerPath, serverURL, updateFilename })=>{
|
|
7
|
+
const endpointRoute = formatAdminURL({
|
|
8
|
+
apiRoute,
|
|
9
|
+
path: serverHandlerPath,
|
|
10
|
+
serverURL
|
|
11
|
+
});
|
|
12
|
+
const result = await upload(`${prefix}${file.name}`, file, {
|
|
13
|
+
access: 'public',
|
|
14
|
+
clientPayload: collectionSlug,
|
|
15
|
+
contentType: file.type,
|
|
16
|
+
handleUploadUrl: endpointRoute
|
|
17
|
+
});
|
|
18
|
+
// Update filename with suffix from returned url
|
|
19
|
+
if (addRandomSuffix) {
|
|
20
|
+
updateFilename(result.url.replace(`${baseURL}/`, ''));
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
prefix
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=VercelBlobClientUploadHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@ruya.sa/plugin-cloud-storage/client'\nimport { upload } from '@vercel/blob/client'\nimport { formatAdminURL } from '@ruya.sa/payload/shared'\n\nexport type VercelBlobClientUploadHandlerExtra = {\n addRandomSuffix: boolean\n baseURL: string\n prefix: string\n}\n\nexport const VercelBlobClientUploadHandler =\n createClientUploadHandler<VercelBlobClientUploadHandlerExtra>({\n handler: async ({\n apiRoute,\n collectionSlug,\n extra: { addRandomSuffix, baseURL, prefix = '' },\n file,\n serverHandlerPath,\n serverURL,\n updateFilename,\n }) => {\n const endpointRoute = formatAdminURL({\n apiRoute,\n path: serverHandlerPath,\n serverURL,\n })\n const result = await upload(`${prefix}${file.name}`, file, {\n access: 'public',\n clientPayload: collectionSlug,\n contentType: file.type,\n handleUploadUrl: endpointRoute,\n })\n\n // Update filename with suffix from returned url\n if (addRandomSuffix) {\n updateFilename(result.url.replace(`${baseURL}/`, ''))\n }\n\n return { prefix }\n },\n })\n"],"names":["createClientUploadHandler","upload","formatAdminURL","VercelBlobClientUploadHandler","handler","apiRoute","collectionSlug","extra","addRandomSuffix","baseURL","prefix","file","serverHandlerPath","serverURL","updateFilename","endpointRoute","path","result","name","access","clientPayload","contentType","type","handleUploadUrl","url","replace"],"mappings":"AAAA;AACA,SAASA,yBAAyB,QAAQ,uCAAsC;AAChF,SAASC,MAAM,QAAQ,sBAAqB;AAC5C,SAASC,cAAc,QAAQ,0BAAyB;AAQxD,OAAO,MAAMC,gCACXH,0BAA8D;IAC5DI,SAAS,OAAO,EACdC,QAAQ,EACRC,cAAc,EACdC,OAAO,EAAEC,eAAe,EAAEC,OAAO,EAAEC,SAAS,EAAE,EAAE,EAChDC,IAAI,EACJC,iBAAiB,EACjBC,SAAS,EACTC,cAAc,EACf;QACC,MAAMC,gBAAgBb,eAAe;YACnCG;YACAW,MAAMJ;YACNC;QACF;QACA,MAAMI,SAAS,MAAMhB,OAAO,GAAGS,SAASC,KAAKO,IAAI,EAAE,EAAEP,MAAM;YACzDQ,QAAQ;YACRC,eAAed;YACfe,aAAaV,KAAKW,IAAI;YACtBC,iBAAiBR;QACnB;QAEA,gDAAgD;QAChD,IAAIP,iBAAiB;YACnBM,eAAeG,OAAOO,GAAG,CAACC,OAAO,CAAC,GAAGhB,QAAQ,CAAC,CAAC,EAAE;QACnD;QAEA,OAAO;YAAEC;QAAO;IAClB;AACF,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/exports/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,4CAA4C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { VercelBlobClientUploadHandler } from '../client/VercelBlobClientUploadHandler.js'\n"],"names":["VercelBlobClientUploadHandler"],"mappings":"AAAA,SAASA,6BAA6B,QAAQ,6CAA4C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GenerateURL } from '@ruya.sa/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/generateURL.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAA;AAItE,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/generateURL.ts"],"sourcesContent":["import type { GenerateURL } from '@ruya.sa/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, encodeURIComponent(filename))}`\n }\n}\n"],"names":["path","getGenerateUrl","baseUrl","filename","prefix","posix","join","encodeURIComponent"],"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,GAAGF,QAAQ,CAAC,EAAEF,KAAKK,KAAK,CAACC,IAAI,CAACF,QAAQG,mBAAmBJ,YAAY;IAC9E;AACF,EAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PayloadHandler, PayloadRequest, UploadCollectionSlug } from '@ruya.sa/payload';
|
|
2
|
+
type Args = {
|
|
3
|
+
access?: (args: {
|
|
4
|
+
collectionSlug: UploadCollectionSlug;
|
|
5
|
+
req: PayloadRequest;
|
|
6
|
+
}) => boolean | Promise<boolean>;
|
|
7
|
+
addRandomSuffix?: boolean;
|
|
8
|
+
cacheControlMaxAge?: number;
|
|
9
|
+
token: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const getClientUploadRoute: ({ access, addRandomSuffix, cacheControlMaxAge, token }: Args) => PayloadHandler;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=getClientUploadRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClientUploadRoute.d.ts","sourceRoot":"","sources":["../src/getClientUploadRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAK5F,KAAK,IAAI,GAAG;IACV,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE;QACd,cAAc,EAAE,oBAAoB,CAAA;QACpC,GAAG,EAAE,cAAc,CAAA;KACpB,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IAChC,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAID,eAAO,MAAM,oBAAoB,2DAC0C,IAAI,KAAG,cA+B/E,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { handleUpload } from '@vercel/blob/client';
|
|
2
|
+
import { APIError, Forbidden } from '@ruya.sa/payload';
|
|
3
|
+
const defaultAccess = ({ req })=>!!req.user;
|
|
4
|
+
export const getClientUploadRoute = ({ access = defaultAccess, addRandomSuffix, cacheControlMaxAge, token })=>async (req)=>{
|
|
5
|
+
const body = await req.json();
|
|
6
|
+
try {
|
|
7
|
+
const jsonResponse = await handleUpload({
|
|
8
|
+
body,
|
|
9
|
+
onBeforeGenerateToken: async (_pathname, collectionSlug)=>{
|
|
10
|
+
if (!collectionSlug) {
|
|
11
|
+
throw new APIError('No payload was provided');
|
|
12
|
+
}
|
|
13
|
+
if (!await access({
|
|
14
|
+
collectionSlug,
|
|
15
|
+
req
|
|
16
|
+
})) {
|
|
17
|
+
throw new Forbidden();
|
|
18
|
+
}
|
|
19
|
+
return Promise.resolve({
|
|
20
|
+
addRandomSuffix,
|
|
21
|
+
cacheControlMaxAge
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
onUploadCompleted: async ()=>{},
|
|
25
|
+
request: req,
|
|
26
|
+
token
|
|
27
|
+
});
|
|
28
|
+
return Response.json(jsonResponse);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
req.payload.logger.error(error);
|
|
31
|
+
throw new APIError('storage-vercel-blob client upload route error');
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=getClientUploadRoute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/getClientUploadRoute.ts"],"sourcesContent":["import type { PayloadHandler, PayloadRequest, UploadCollectionSlug } from '@ruya.sa/payload'\n\nimport { handleUpload, type HandleUploadBody } from '@vercel/blob/client'\nimport { APIError, Forbidden } from '@ruya.sa/payload'\n\ntype Args = {\n access?: (args: {\n collectionSlug: UploadCollectionSlug\n req: PayloadRequest\n }) => boolean | Promise<boolean>\n addRandomSuffix?: boolean\n cacheControlMaxAge?: number\n token: string\n}\n\nconst defaultAccess: Args['access'] = ({ req }) => !!req.user\n\nexport const getClientUploadRoute =\n ({ access = defaultAccess, addRandomSuffix, cacheControlMaxAge, token }: Args): PayloadHandler =>\n async (req) => {\n const body = (await req.json!()) as HandleUploadBody\n\n try {\n const jsonResponse = await handleUpload({\n body,\n onBeforeGenerateToken: async (_pathname: string, collectionSlug: null | string) => {\n if (!collectionSlug) {\n throw new APIError('No payload was provided')\n }\n\n if (!(await access({ collectionSlug, req }))) {\n throw new Forbidden()\n }\n\n return Promise.resolve({\n addRandomSuffix,\n cacheControlMaxAge,\n })\n },\n onUploadCompleted: async () => {},\n request: req as Request,\n token,\n })\n\n return Response.json(jsonResponse)\n } catch (error) {\n req.payload.logger.error(error)\n throw new APIError('storage-vercel-blob client upload route error')\n }\n }\n"],"names":["handleUpload","APIError","Forbidden","defaultAccess","req","user","getClientUploadRoute","access","addRandomSuffix","cacheControlMaxAge","token","body","json","jsonResponse","onBeforeGenerateToken","_pathname","collectionSlug","Promise","resolve","onUploadCompleted","request","Response","error","payload","logger"],"mappings":"AAEA,SAASA,YAAY,QAA+B,sBAAqB;AACzE,SAASC,QAAQ,EAAEC,SAAS,QAAQ,mBAAkB;AAYtD,MAAMC,gBAAgC,CAAC,EAAEC,GAAG,EAAE,GAAK,CAAC,CAACA,IAAIC,IAAI;AAE7D,OAAO,MAAMC,uBACX,CAAC,EAAEC,SAASJ,aAAa,EAAEK,eAAe,EAAEC,kBAAkB,EAAEC,KAAK,EAAQ,GAC7E,OAAON;QACL,MAAMO,OAAQ,MAAMP,IAAIQ,IAAI;QAE5B,IAAI;YACF,MAAMC,eAAe,MAAMb,aAAa;gBACtCW;gBACAG,uBAAuB,OAAOC,WAAmBC;oBAC/C,IAAI,CAACA,gBAAgB;wBACnB,MAAM,IAAIf,SAAS;oBACrB;oBAEA,IAAI,CAAE,MAAMM,OAAO;wBAAES;wBAAgBZ;oBAAI,IAAK;wBAC5C,MAAM,IAAIF;oBACZ;oBAEA,OAAOe,QAAQC,OAAO,CAAC;wBACrBV;wBACAC;oBACF;gBACF;gBACAU,mBAAmB,WAAa;gBAChCC,SAAShB;gBACTM;YACF;YAEA,OAAOW,SAAST,IAAI,CAACC;QACvB,EAAE,OAAOS,OAAO;YACdlB,IAAImB,OAAO,CAACC,MAAM,CAACF,KAAK,CAACA;YACzB,MAAM,IAAIrB,SAAS;QACrB;IACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HandleDelete } from '@ruya.sa/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/handleDelete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AAKvE,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/handleDelete.ts"],"sourcesContent":["import type { HandleDelete } from '@ruya.sa/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,GAAGL,QAAQ,CAAC,EAAEF,KAAKQ,KAAK,CAACC,IAAI,CAACJ,QAAQC,WAAW;QACjE,MAAMI,cAAc,MAAMX,IAAIQ,SAAS;YAAEJ;QAAM;QAE/C,OAAOO;IACT;AACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HandleUpload } from '@ruya.sa/plugin-cloud-storage/types';
|
|
2
|
+
import type { VercelBlobStorageOptions } from './index.js';
|
|
3
|
+
type HandleUploadArgs = {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
prefix?: string;
|
|
6
|
+
} & Omit<VercelBlobStorageOptions, 'collections'>;
|
|
7
|
+
export declare const getHandleUpload: ({ access, addRandomSuffix, baseUrl, cacheControlMaxAge, prefix, token, }: HandleUploadArgs) => HandleUpload;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=handleUpload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleUpload.d.ts","sourceRoot":"","sources":["../src/handleUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAA;AAKvE,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"}
|
|
@@ -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 = decodeURIComponent(result.url.replace(`${baseUrl}/`, ''));
|
|
16
|
+
}
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=handleUpload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handleUpload.ts"],"sourcesContent":["import type { HandleUpload } from '@ruya.sa/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 = decodeURIComponent(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","decodeURIComponent","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,GAAGO,mBAAmBF,OAAOG,GAAG,CAACC,OAAO,CAAC,GAAGhB,QAAQ,CAAC,CAAC,EAAE;QACvE;QAEA,OAAOI;IACT;AACF,EAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ClientUploadsConfig, CollectionOptions } from '@ruya.sa/plugin-cloud-storage/types';
|
|
2
|
+
import type { Plugin, UploadCollectionSlug } from '@ruya.sa/payload';
|
|
3
|
+
export type VercelBlobStorageOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Access control level. Currently, only 'public' is supported.
|
|
6
|
+
* Vercel plans on adding support for private blobs in the future.
|
|
7
|
+
*
|
|
8
|
+
* @default 'public'
|
|
9
|
+
*/
|
|
10
|
+
access?: 'public';
|
|
11
|
+
/**
|
|
12
|
+
* Add a random suffix to the uploaded file name in Vercel Blob storage
|
|
13
|
+
*
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
addRandomSuffix?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* When enabled, fields (like the prefix field) will always be inserted into
|
|
19
|
+
* the collection schema regardless of whether the plugin is enabled. This
|
|
20
|
+
* ensures a consistent schema across all environments.
|
|
21
|
+
*
|
|
22
|
+
* This will be enabled by default in Payload v4.
|
|
23
|
+
*
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
alwaysInsertFields?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Cache-Control max-age in seconds
|
|
29
|
+
*
|
|
30
|
+
* @default 365 * 24 * 60 * 60 // (1 Year)
|
|
31
|
+
*/
|
|
32
|
+
cacheControlMaxAge?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Do uploads directly on the client, to bypass limits on Vercel.
|
|
35
|
+
*/
|
|
36
|
+
clientUploads?: ClientUploadsConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Collections to apply the Vercel Blob adapter to
|
|
39
|
+
*/
|
|
40
|
+
collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether or not to enable the plugin
|
|
43
|
+
*
|
|
44
|
+
* Default: true
|
|
45
|
+
*/
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Vercel Blob storage read/write token
|
|
49
|
+
*
|
|
50
|
+
* Usually process.env.BLOB_READ_WRITE_TOKEN set by Vercel
|
|
51
|
+
*
|
|
52
|
+
* If unset, the plugin will be disabled and will fallback to local storage
|
|
53
|
+
*/
|
|
54
|
+
token: string | undefined;
|
|
55
|
+
};
|
|
56
|
+
type VercelBlobStoragePlugin = (vercelBlobStorageOpts: VercelBlobStorageOptions) => Plugin;
|
|
57
|
+
export declare const vercelBlobStorage: VercelBlobStoragePlugin;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,mBAAmB,EAEnB,iBAAiB,EAElB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,KAAK,EAAU,MAAM,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAa5E,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IAEjB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IAEnC;;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;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;CAC1B,CAAA;AASD,KAAK,uBAAuB,GAAG,CAAC,qBAAqB,EAAE,wBAAwB,KAAK,MAAM,CAAA;AAE1F,eAAO,MAAM,iBAAiB,EAAE,uBA2F7B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { cloudStoragePlugin } from '@ruya.sa/plugin-cloud-storage';
|
|
2
|
+
import { initClientUploads } from '@ruya.sa/plugin-cloud-storage/utilities';
|
|
3
|
+
import { getGenerateUrl } from './generateURL.js';
|
|
4
|
+
import { getClientUploadRoute } from './getClientUploadRoute.js';
|
|
5
|
+
import { getHandleDelete } from './handleDelete.js';
|
|
6
|
+
import { getHandleUpload } from './handleUpload.js';
|
|
7
|
+
import { getStaticHandler } from './staticHandler.js';
|
|
8
|
+
const defaultUploadOptions = {
|
|
9
|
+
access: 'public',
|
|
10
|
+
addRandomSuffix: false,
|
|
11
|
+
cacheControlMaxAge: 60 * 60 * 24 * 365,
|
|
12
|
+
enabled: true
|
|
13
|
+
};
|
|
14
|
+
export const vercelBlobStorage = (options)=>(incomingConfig)=>{
|
|
15
|
+
// Parse storeId from token
|
|
16
|
+
const storeId = options.token?.match(/^vercel_blob_rw_([a-z\d]+)_[a-z\d]+$/i)?.[1]?.toLowerCase();
|
|
17
|
+
const isPluginDisabled = options.enabled === false || !options.token;
|
|
18
|
+
// Don't throw if the plugin is disabled
|
|
19
|
+
if (!storeId && !isPluginDisabled) {
|
|
20
|
+
throw new Error('Invalid token format for Vercel Blob adapter. Should be vercel_blob_rw_<store_id>_<random_string>.');
|
|
21
|
+
}
|
|
22
|
+
const optionsWithDefaults = {
|
|
23
|
+
...defaultUploadOptions,
|
|
24
|
+
...options
|
|
25
|
+
};
|
|
26
|
+
const baseUrl = `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`;
|
|
27
|
+
initClientUploads({
|
|
28
|
+
clientHandler: '@ruya.sa/storage-vercel-blob/client#VercelBlobClientUploadHandler',
|
|
29
|
+
collections: options.collections,
|
|
30
|
+
config: incomingConfig,
|
|
31
|
+
enabled: !isPluginDisabled && Boolean(options.clientUploads),
|
|
32
|
+
extraClientHandlerProps: (collection)=>({
|
|
33
|
+
addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,
|
|
34
|
+
baseURL: baseUrl,
|
|
35
|
+
prefix: typeof collection === 'object' && collection.prefix && `${collection.prefix}/` || ''
|
|
36
|
+
}),
|
|
37
|
+
serverHandler: getClientUploadRoute({
|
|
38
|
+
access: typeof options.clientUploads === 'object' ? options.clientUploads.access : undefined,
|
|
39
|
+
addRandomSuffix: optionsWithDefaults.addRandomSuffix,
|
|
40
|
+
cacheControlMaxAge: options.cacheControlMaxAge,
|
|
41
|
+
token: options.token ?? ''
|
|
42
|
+
}),
|
|
43
|
+
serverHandlerPath: '/vercel-blob-client-upload-route'
|
|
44
|
+
});
|
|
45
|
+
// If the plugin is disabled or no token is provided, do not enable the plugin
|
|
46
|
+
if (isPluginDisabled) {
|
|
47
|
+
return incomingConfig;
|
|
48
|
+
}
|
|
49
|
+
const adapter = vercelBlobStorageInternal({
|
|
50
|
+
...optionsWithDefaults,
|
|
51
|
+
baseUrl
|
|
52
|
+
});
|
|
53
|
+
// Add adapter to each collection option object
|
|
54
|
+
const collectionsWithAdapter = Object.entries(options.collections).reduce((acc, [slug, collOptions])=>({
|
|
55
|
+
...acc,
|
|
56
|
+
[slug]: {
|
|
57
|
+
...collOptions === true ? {} : collOptions,
|
|
58
|
+
adapter
|
|
59
|
+
}
|
|
60
|
+
}), {});
|
|
61
|
+
// Set disableLocalStorage: true for collections specified in the plugin options
|
|
62
|
+
const config = {
|
|
63
|
+
...incomingConfig,
|
|
64
|
+
collections: (incomingConfig.collections || []).map((collection)=>{
|
|
65
|
+
if (!collectionsWithAdapter[collection.slug]) {
|
|
66
|
+
return collection;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...collection,
|
|
70
|
+
upload: {
|
|
71
|
+
...typeof collection.upload === 'object' ? collection.upload : {},
|
|
72
|
+
disableLocalStorage: true
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
})
|
|
76
|
+
};
|
|
77
|
+
return cloudStoragePlugin({
|
|
78
|
+
alwaysInsertFields: options.alwaysInsertFields,
|
|
79
|
+
collections: collectionsWithAdapter
|
|
80
|
+
})(config);
|
|
81
|
+
};
|
|
82
|
+
function vercelBlobStorageInternal(options) {
|
|
83
|
+
return ({ collection, prefix })=>{
|
|
84
|
+
const { access, addRandomSuffix, baseUrl, cacheControlMaxAge, clientUploads, token } = options;
|
|
85
|
+
if (!token) {
|
|
86
|
+
throw new Error('Vercel Blob storage token is required');
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
name: 'vercel-blob',
|
|
90
|
+
clientUploads,
|
|
91
|
+
generateURL: getGenerateUrl({
|
|
92
|
+
baseUrl,
|
|
93
|
+
prefix
|
|
94
|
+
}),
|
|
95
|
+
handleDelete: getHandleDelete({
|
|
96
|
+
baseUrl,
|
|
97
|
+
prefix,
|
|
98
|
+
token
|
|
99
|
+
}),
|
|
100
|
+
handleUpload: getHandleUpload({
|
|
101
|
+
access,
|
|
102
|
+
addRandomSuffix,
|
|
103
|
+
baseUrl,
|
|
104
|
+
cacheControlMaxAge,
|
|
105
|
+
prefix,
|
|
106
|
+
token
|
|
107
|
+
}),
|
|
108
|
+
staticHandler: getStaticHandler({
|
|
109
|
+
baseUrl,
|
|
110
|
+
cacheControlMaxAge,
|
|
111
|
+
token
|
|
112
|
+
}, collection)
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Adapter,\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n GeneratedAdapter,\n} from '@ruya.sa/plugin-cloud-storage/types'\nimport type { Config, Plugin, UploadCollectionSlug } from '@ruya.sa/payload'\n\nimport { cloudStoragePlugin } from '@ruya.sa/plugin-cloud-storage'\nimport { initClientUploads } from '@ruya.sa/plugin-cloud-storage/utilities'\n\nimport type { VercelBlobClientUploadHandlerExtra } from './client/VercelBlobClientUploadHandler.js'\n\nimport { getGenerateUrl } from './generateURL.js'\nimport { getClientUploadRoute } from './getClientUploadRoute.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 * When enabled, fields (like the prefix field) will always be inserted into\n * the collection schema regardless of whether the plugin is enabled. This\n * ensures a consistent schema across all environments.\n *\n * This will be enabled by default in Payload v4.\n *\n * @default false\n */\n alwaysInsertFields?: boolean\n\n /**\n * Cache-Control max-age in seconds\n *\n * @default 365 * 24 * 60 * 60 // (1 Year)\n */\n cacheControlMaxAge?: number\n\n /**\n * Do uploads directly on the client, to bypass limits on Vercel.\n */\n clientUploads?: ClientUploadsConfig\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 * If unset, the plugin will be disabled and will fallback to local storage\n */\n token: string | undefined\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 // Parse storeId from token\n const storeId = options.token\n ?.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]\n ?.toLowerCase()\n\n const isPluginDisabled = options.enabled === false || !options.token\n\n // Don't throw if the plugin is disabled\n if (!storeId && !isPluginDisabled) {\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 initClientUploads<\n VercelBlobClientUploadHandlerExtra,\n VercelBlobStorageOptions['collections'][string]\n >({\n clientHandler: '@ruya.sa/storage-vercel-blob/client#VercelBlobClientUploadHandler',\n collections: options.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(options.clientUploads),\n extraClientHandlerProps: (collection) => ({\n addRandomSuffix: !!optionsWithDefaults.addRandomSuffix,\n baseURL: baseUrl,\n prefix:\n (typeof collection === 'object' && collection.prefix && `${collection.prefix}/`) || '',\n }),\n serverHandler: getClientUploadRoute({\n access:\n typeof options.clientUploads === 'object' ? options.clientUploads.access : undefined,\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n cacheControlMaxAge: options.cacheControlMaxAge,\n token: options.token ?? '',\n }),\n serverHandlerPath: '/vercel-blob-client-upload-route',\n })\n\n // If the plugin is disabled or no token is provided, do not enable the plugin\n if (isPluginDisabled) {\n return incomingConfig\n }\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 alwaysInsertFields: options.alwaysInsertFields,\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, clientUploads, token } = options\n\n if (!token) {\n throw new Error('Vercel Blob storage token is required')\n }\n\n return {\n name: 'vercel-blob',\n clientUploads,\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, cacheControlMaxAge, token }, collection),\n }\n }\n}\n"],"names":["cloudStoragePlugin","initClientUploads","getGenerateUrl","getClientUploadRoute","getHandleDelete","getHandleUpload","getStaticHandler","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","incomingConfig","storeId","token","match","toLowerCase","isPluginDisabled","Error","optionsWithDefaults","baseUrl","clientHandler","collections","config","Boolean","clientUploads","extraClientHandlerProps","collection","baseURL","prefix","serverHandler","undefined","serverHandlerPath","adapter","vercelBlobStorageInternal","collectionsWithAdapter","Object","entries","reduce","acc","slug","collOptions","map","upload","disableLocalStorage","alwaysInsertFields","name","generateURL","handleDelete","handleUpload","staticHandler"],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StaticHandler } from '@ruya.sa/plugin-cloud-storage/types';
|
|
2
|
+
import type { CollectionConfig } from '@ruya.sa/payload';
|
|
3
|
+
type StaticHandlerArgs = {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
cacheControlMaxAge?: number;
|
|
6
|
+
token: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const getStaticHandler: ({ baseUrl, cacheControlMaxAge, token }: StaticHandlerArgs, collection: CollectionConfig) => StaticHandler;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=staticHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticHandler.d.ts","sourceRoot":"","sources":["../src/staticHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAOxD,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,aA8EF,CAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { getFilePrefix } from '@ruya.sa/plugin-cloud-storage/utilities';
|
|
2
|
+
import { BlobNotFoundError, head } from '@vercel/blob';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getRangeRequestInfo } from '@ruya.sa/payload/internal';
|
|
5
|
+
export const getStaticHandler = ({ baseUrl, cacheControlMaxAge = 0, token }, collection)=>{
|
|
6
|
+
return async (req, { headers: incomingHeaders, params: { clientUploadContext, filename } })=>{
|
|
7
|
+
try {
|
|
8
|
+
const prefix = await getFilePrefix({
|
|
9
|
+
clientUploadContext,
|
|
10
|
+
collection,
|
|
11
|
+
filename,
|
|
12
|
+
req
|
|
13
|
+
});
|
|
14
|
+
const fileKey = path.posix.join(prefix, encodeURIComponent(filename));
|
|
15
|
+
const fileUrl = `${baseUrl}/${fileKey}`;
|
|
16
|
+
const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match');
|
|
17
|
+
const blobMetadata = await head(fileUrl, {
|
|
18
|
+
token
|
|
19
|
+
});
|
|
20
|
+
const { contentDisposition, contentType, size, uploadedAt } = blobMetadata;
|
|
21
|
+
const uploadedAtString = uploadedAt.toISOString();
|
|
22
|
+
const ETag = `"${fileKey}-${uploadedAtString}"`;
|
|
23
|
+
// Handle range request
|
|
24
|
+
const rangeHeader = req.headers.get('range');
|
|
25
|
+
const rangeResult = getRangeRequestInfo({
|
|
26
|
+
fileSize: size,
|
|
27
|
+
rangeHeader
|
|
28
|
+
});
|
|
29
|
+
if (rangeResult.type === 'invalid') {
|
|
30
|
+
return new Response(null, {
|
|
31
|
+
headers: new Headers(rangeResult.headers),
|
|
32
|
+
status: rangeResult.status
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
let headers = new Headers(incomingHeaders);
|
|
36
|
+
// Add range-related headers from the result
|
|
37
|
+
for (const [key, value] of Object.entries(rangeResult.headers)){
|
|
38
|
+
headers.append(key, value);
|
|
39
|
+
}
|
|
40
|
+
headers.append('Cache-Control', `public, max-age=${cacheControlMaxAge}`);
|
|
41
|
+
headers.append('Content-Disposition', contentDisposition);
|
|
42
|
+
headers.append('Content-Type', contentType);
|
|
43
|
+
headers.append('ETag', ETag);
|
|
44
|
+
if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
|
|
45
|
+
headers = collection.upload.modifyResponseHeaders({
|
|
46
|
+
headers
|
|
47
|
+
}) || headers;
|
|
48
|
+
}
|
|
49
|
+
if (etagFromHeaders && etagFromHeaders === ETag) {
|
|
50
|
+
return new Response(null, {
|
|
51
|
+
headers,
|
|
52
|
+
status: 304
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const response = await fetch(`${fileUrl}?${uploadedAtString}`, {
|
|
56
|
+
headers: {
|
|
57
|
+
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
|
58
|
+
Pragma: 'no-cache',
|
|
59
|
+
...rangeResult.type === 'partial' && {
|
|
60
|
+
Range: `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}`
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (!response.ok || !response.body) {
|
|
65
|
+
return new Response(null, {
|
|
66
|
+
status: 204,
|
|
67
|
+
statusText: 'No Content'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
headers.append('Last-Modified', uploadedAtString);
|
|
71
|
+
return new Response(response.body, {
|
|
72
|
+
headers,
|
|
73
|
+
status: rangeResult.status
|
|
74
|
+
});
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (err instanceof BlobNotFoundError) {
|
|
77
|
+
return new Response(null, {
|
|
78
|
+
status: 404,
|
|
79
|
+
statusText: 'Not Found'
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
req.payload.logger.error({
|
|
83
|
+
err,
|
|
84
|
+
msg: 'Unexpected error in staticHandler'
|
|
85
|
+
});
|
|
86
|
+
return new Response('Internal Server Error', {
|
|
87
|
+
status: 500
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=staticHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/staticHandler.ts"],"sourcesContent":["import type { StaticHandler } from '@ruya.sa/plugin-cloud-storage/types'\nimport type { CollectionConfig } from '@ruya.sa/payload'\n\nimport { getFilePrefix } from '@ruya.sa/plugin-cloud-storage/utilities'\nimport { BlobNotFoundError, head } from '@vercel/blob'\nimport path from 'path'\nimport { getRangeRequestInfo } from '@ruya.sa/payload/internal'\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, { headers: incomingHeaders, params: { clientUploadContext, filename } }) => {\n try {\n const prefix = await getFilePrefix({ clientUploadContext, collection, filename, req })\n const fileKey = path.posix.join(prefix, encodeURIComponent(filename))\n const fileUrl = `${baseUrl}/${fileKey}`\n const etagFromHeaders = req.headers.get('etag') || req.headers.get('if-none-match')\n const blobMetadata = await head(fileUrl, { token })\n const { contentDisposition, contentType, size, uploadedAt } = blobMetadata\n const uploadedAtString = uploadedAt.toISOString()\n const ETag = `\"${fileKey}-${uploadedAtString}\"`\n\n // Handle range request\n const rangeHeader = req.headers.get('range')\n const rangeResult = getRangeRequestInfo({ fileSize: size, rangeHeader })\n\n if (rangeResult.type === 'invalid') {\n return new Response(null, {\n headers: new Headers(rangeResult.headers),\n status: rangeResult.status,\n })\n }\n\n let headers = new Headers(incomingHeaders)\n\n // Add range-related headers from the result\n for (const [key, value] of Object.entries(rangeResult.headers)) {\n headers.append(key, value)\n }\n\n headers.append('Cache-Control', `public, max-age=${cacheControlMaxAge}`)\n headers.append('Content-Disposition', contentDisposition)\n headers.append('Content-Type', contentType)\n headers.append('ETag', ETag)\n\n if (\n collection.upload &&\n typeof collection.upload === 'object' &&\n typeof collection.upload.modifyResponseHeaders === 'function'\n ) {\n headers = collection.upload.modifyResponseHeaders({ headers }) || headers\n }\n\n if (etagFromHeaders && etagFromHeaders === ETag) {\n return new Response(null, {\n headers,\n status: 304,\n })\n }\n\n const response = await fetch(`${fileUrl}?${uploadedAtString}`, {\n headers: {\n 'Cache-Control': 'no-store, no-cache, must-revalidate',\n Pragma: 'no-cache',\n ...(rangeResult.type === 'partial' && {\n Range: `bytes=${rangeResult.rangeStart}-${rangeResult.rangeEnd}`,\n }),\n },\n })\n\n if (!response.ok || !response.body) {\n return new Response(null, { status: 204, statusText: 'No Content' })\n }\n\n headers.append('Last-Modified', uploadedAtString)\n\n return new Response(response.body, {\n headers,\n status: rangeResult.status,\n })\n } catch (err: unknown) {\n if (err instanceof BlobNotFoundError) {\n return new Response(null, { status: 404, statusText: 'Not Found' })\n }\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","BlobNotFoundError","head","path","getRangeRequestInfo","getStaticHandler","baseUrl","cacheControlMaxAge","token","collection","req","headers","incomingHeaders","params","clientUploadContext","filename","prefix","fileKey","posix","join","encodeURIComponent","fileUrl","etagFromHeaders","get","blobMetadata","contentDisposition","contentType","size","uploadedAt","uploadedAtString","toISOString","ETag","rangeHeader","rangeResult","fileSize","type","Response","Headers","status","key","value","Object","entries","append","upload","modifyResponseHeaders","response","fetch","Pragma","Range","rangeStart","rangeEnd","ok","body","statusText","err","payload","logger","error","msg"],"mappings":"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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ruya.sa/storage-vercel-blob",
|
|
3
|
+
"version": "3.71.3",
|
|
4
|
+
"description": "Payload storage adapter for Vercel Blob Storage",
|
|
5
|
+
"homepage": "https://payloadcms.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
9
|
+
"directory": "packages/storage-vercel-blob"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
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
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./client": {
|
|
29
|
+
"import": "./dist/exports/client.js",
|
|
30
|
+
"types": "./dist/exports/client.d.ts",
|
|
31
|
+
"default": "./dist/exports/client.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"main": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@vercel/blob": "^0.22.3",
|
|
41
|
+
"@ruya.sa/plugin-cloud-storage": "3.71.3"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@ruya.sa/payload": "3.71.3"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@ruya.sa/payload": "3.71.3"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": "^18.20.2 || >=20.9.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "pnpm build:types && pnpm build:swc",
|
|
54
|
+
"build:clean": "find . \\( -type d \\( -name build -o -name dist -o -name .cache \\) -o -type f -name tsconfig.tsbuildinfo \\) -exec rm -rf {} + && pnpm build",
|
|
55
|
+
"build:debug": "pnpm build",
|
|
56
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
57
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
58
|
+
"clean": "rimraf -g {dist,*.tsbuildinfo}",
|
|
59
|
+
"lint": "eslint .",
|
|
60
|
+
"lint:fix": "eslint . --fix"
|
|
61
|
+
}
|
|
62
|
+
}
|