@payloadcms/storage-vercel-blob 4.0.0-internal.d21c039 → 4.0.0-internal.d3909a9
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 +10 -8
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +19 -7
- package/dist/adapter.js.map +1 -1
- package/dist/authorizeFileOverwrite.js +4 -4
- package/dist/authorizeFileOverwrite.js.map +1 -1
- package/dist/client/VercelBlobClientUploadHandler.d.ts.map +1 -1
- package/dist/client/VercelBlobClientUploadHandler.js +3 -9
- package/dist/client/VercelBlobClientUploadHandler.js.map +1 -1
- package/dist/copyFile.d.ts +12 -0
- package/dist/copyFile.d.ts.map +1 -0
- package/dist/copyFile.js +86 -0
- package/dist/copyFile.js.map +1 -0
- package/dist/getFile.d.ts +3 -2
- package/dist/getFile.d.ts.map +1 -1
- package/dist/getFile.js +12 -6
- package/dist/getFile.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +16 -18
package/README.md
CHANGED
|
@@ -41,11 +41,13 @@ export default buildConfig({
|
|
|
41
41
|
})
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
| Option | Description
|
|
45
|
-
| -------------------- |
|
|
46
|
-
| `enabled` | Whether or not to enable the plugin
|
|
47
|
-
| `collections` | Collections to apply the Vercel Blob adapter to
|
|
48
|
-
| `addRandomSuffix` |
|
|
49
|
-
| `cacheControlMaxAge` | Cache-Control max-age in seconds
|
|
50
|
-
| `token` | Vercel Blob storage read/write token
|
|
51
|
-
| `clientUploads` | Upload directly to Vercel Blob instead of through Payload.
|
|
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` | Must be `false` or omitted; enabled adapters with configured collections reject `true`. | `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` | Upload directly to Vercel Blob instead of through Payload. | |
|
|
52
|
+
|
|
53
|
+
Set `addRandomSuffix` to `false` or omit it. Payload requires exact storage paths for reads, rollback, and deletion, and already allocates unique `_objectKey` folders for managed uploads. Enabled adapters with configured collections reject `true` during initialization. Disabled adapters retain their existing behavior. Changing this option does not rename existing blobs; migrate any mismatched stored paths and saved metadata together.
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,mBAAmB,EAGpB,MAAM,wCAAwC,CAAA;AAU/C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAA;AAS7E,UAAU,2BAA2B;IACnC,MAAM,EAAE,QAAQ,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC,iBAAiB,EAAE,0BAA0B,EAAE,CAAA;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,wBAAgB,uBAAuB,CAAC,EACtC,MAAM,EACN,eAAe,EACf,OAAO,EACP,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,KAAK,EACL,oBAA4B,GAC7B,EAAE,2BAA2B,GAAG,OAAO,CAoJvC"}
|
package/dist/adapter.js
CHANGED
|
@@ -3,14 +3,29 @@ import { generateClientTokenFromReadWriteToken } from '@vercel/blob/client';
|
|
|
3
3
|
import { Forbidden } from 'payload';
|
|
4
4
|
import { assertClientUploadAllowed, createClientUploadReceipt } from 'payload/internal';
|
|
5
5
|
import { authorizeClientOverwrite } from './authorizeFileOverwrite.js';
|
|
6
|
+
import { copyVercelBlobFile } from './copyFile.js';
|
|
6
7
|
import { deleteFile } from './deleteFile.js';
|
|
7
8
|
import { generateURL } from './generateURL.js';
|
|
8
9
|
import { getFile } from './getFile.js';
|
|
9
10
|
import { uploadFile } from './uploadFile.js';
|
|
10
11
|
export function createVercelBlobAdapter({ access, addRandomSuffix, baseUrl, cacheControlMaxAge, clientUploads, collectionSources, token, useCompositePrefixes = false }) {
|
|
11
12
|
const clientUploadsAccess = typeof clientUploads === 'object' ? clientUploads.access : undefined;
|
|
13
|
+
const deleteStoredFile = ({ storageFilePath })=>deleteFile({
|
|
14
|
+
baseUrl,
|
|
15
|
+
storageFilePath,
|
|
16
|
+
token
|
|
17
|
+
});
|
|
12
18
|
return ({ collection, prefix = '' })=>({
|
|
13
19
|
name: 'vercel-blob',
|
|
20
|
+
copyFile: ({ from, req, to })=>copyVercelBlobFile({
|
|
21
|
+
access,
|
|
22
|
+
cacheControlMaxAge,
|
|
23
|
+
from,
|
|
24
|
+
req,
|
|
25
|
+
to,
|
|
26
|
+
token
|
|
27
|
+
}),
|
|
28
|
+
deleteFile: deleteStoredFile,
|
|
14
29
|
uploadInstructions: {
|
|
15
30
|
adminHandler: {
|
|
16
31
|
path: '@payloadcms/storage-vercel-blob/client#VercelBlobClientUploadHandler'
|
|
@@ -34,7 +49,7 @@ export function createVercelBlobAdapter({ access, addRandomSuffix, baseUrl, cach
|
|
|
34
49
|
filename,
|
|
35
50
|
useCompositePrefixes
|
|
36
51
|
});
|
|
37
|
-
const allowOverwrite = await authorizeClientOverwrite({
|
|
52
|
+
const allowOverwrite = collection.versions ? false : await authorizeClientOverwrite({
|
|
38
53
|
collectionPrefix: prefix,
|
|
39
54
|
collectionSources,
|
|
40
55
|
overrideAccess,
|
|
@@ -101,11 +116,7 @@ export function createVercelBlobAdapter({ access, addRandomSuffix, baseUrl, cach
|
|
|
101
116
|
prefix: urlPrefix,
|
|
102
117
|
useCompositePrefixes
|
|
103
118
|
}),
|
|
104
|
-
handleDelete:
|
|
105
|
-
baseUrl,
|
|
106
|
-
storageFilePath,
|
|
107
|
-
token
|
|
108
|
-
}),
|
|
119
|
+
handleDelete: deleteStoredFile,
|
|
109
120
|
handleUpload: async ({ data, file: { buffer, mimeType }, storageFilePath })=>{
|
|
110
121
|
const result = await uploadFile({
|
|
111
122
|
access,
|
|
@@ -121,7 +132,7 @@ export function createVercelBlobAdapter({ access, addRandomSuffix, baseUrl, cach
|
|
|
121
132
|
}
|
|
122
133
|
return data;
|
|
123
134
|
},
|
|
124
|
-
staticHandler: (req, { doc, headers, params: { filename, uploadReference } })=>getFile({
|
|
135
|
+
staticHandler: (req, { doc, headers, params: { filename, operation, uploadReference } })=>getFile({
|
|
125
136
|
baseUrl,
|
|
126
137
|
cacheControlMaxAge,
|
|
127
138
|
collection,
|
|
@@ -129,6 +140,7 @@ export function createVercelBlobAdapter({ access, addRandomSuffix, baseUrl, cach
|
|
|
129
140
|
doc,
|
|
130
141
|
filename,
|
|
131
142
|
incomingHeaders: headers,
|
|
143
|
+
operation,
|
|
132
144
|
req,
|
|
133
145
|
token,
|
|
134
146
|
uploadReference,
|
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type {\n Adapter,\n ClientUploadsConfig,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\n\nimport {\n buildUploadStoragePathData,\n resolveSignedURLKey,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { generateClientTokenFromReadWriteToken } from '@vercel/blob/client'\nimport { Forbidden } from 'payload'\nimport { assertClientUploadAllowed, createClientUploadReceipt } from 'payload/internal'\n\nimport type { VercelBlobCollectionSource } from './authorizeFileOverwrite.js'\n\nimport { authorizeClientOverwrite } from './authorizeFileOverwrite.js'\nimport { deleteFile } from './deleteFile.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateVercelBlobAdapterArgs {\n access: 'public'\n addRandomSuffix?: boolean\n baseUrl: string\n cacheControlMaxAge: number\n clientUploads?: ClientUploadsConfig\n collectionSources: VercelBlobCollectionSource[]\n token: string\n useCompositePrefixes?: boolean\n}\n\nexport function createVercelBlobAdapter({\n access,\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n clientUploads,\n collectionSources,\n token,\n useCompositePrefixes = false,\n}: CreateVercelBlobAdapterArgs): Adapter {\n const clientUploadsAccess = typeof clientUploads === 'object' ? clientUploads.access : undefined\n\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'vercel-blob',\n\n uploadInstructions: {\n adminHandler: {\n path: '@payloadcms/storage-vercel-blob/client#VercelBlobClientUploadHandler',\n },\n enabled: Boolean(clientUploads),\n generate: async ({\n collectionSlug,\n docPrefix,\n filename,\n filesize,\n mimeType,\n overrideAccess,\n req,\n }) => {\n if (\n !overrideAccess &&\n (clientUploadsAccess ? !(await clientUploadsAccess({ collectionSlug, req })) : !req.user)\n ) {\n throw new Forbidden(req.t)\n }\n\n assertClientUploadAllowed({ collection, filename, mimeType })\n\n const requested = buildUploadStoragePathData({\n collectionPrefix: prefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n const allowOverwrite = await authorizeClientOverwrite({\n
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type {\n Adapter,\n ClientUploadsConfig,\n DeleteFile,\n GeneratedAdapter,\n} from '@payloadcms/plugin-cloud-storage/types'\n\nimport {\n buildUploadStoragePathData,\n resolveSignedURLKey,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { generateClientTokenFromReadWriteToken } from '@vercel/blob/client'\nimport { Forbidden } from 'payload'\nimport { assertClientUploadAllowed, createClientUploadReceipt } from 'payload/internal'\n\nimport type { VercelBlobCollectionSource } from './authorizeFileOverwrite.js'\n\nimport { authorizeClientOverwrite } from './authorizeFileOverwrite.js'\nimport { copyVercelBlobFile } from './copyFile.js'\nimport { deleteFile } from './deleteFile.js'\nimport { generateURL } from './generateURL.js'\nimport { getFile } from './getFile.js'\nimport { uploadFile } from './uploadFile.js'\n\ninterface CreateVercelBlobAdapterArgs {\n access: 'public'\n addRandomSuffix?: boolean\n baseUrl: string\n cacheControlMaxAge: number\n clientUploads?: ClientUploadsConfig\n collectionSources: VercelBlobCollectionSource[]\n token: string\n useCompositePrefixes?: boolean\n}\n\nexport function createVercelBlobAdapter({\n access,\n addRandomSuffix,\n baseUrl,\n cacheControlMaxAge,\n clientUploads,\n collectionSources,\n token,\n useCompositePrefixes = false,\n}: CreateVercelBlobAdapterArgs): Adapter {\n const clientUploadsAccess = typeof clientUploads === 'object' ? clientUploads.access : undefined\n const deleteStoredFile: DeleteFile = ({ storageFilePath }) =>\n deleteFile({ baseUrl, storageFilePath, token })\n\n return ({ collection, prefix = '' }): GeneratedAdapter => ({\n name: 'vercel-blob',\n\n copyFile: ({ from, req, to }) =>\n copyVercelBlobFile({ access, cacheControlMaxAge, from, req, to, token }),\n deleteFile: deleteStoredFile,\n\n uploadInstructions: {\n adminHandler: {\n path: '@payloadcms/storage-vercel-blob/client#VercelBlobClientUploadHandler',\n },\n enabled: Boolean(clientUploads),\n generate: async ({\n collectionSlug,\n docPrefix,\n filename,\n filesize,\n mimeType,\n overrideAccess,\n req,\n }) => {\n if (\n !overrideAccess &&\n (clientUploadsAccess ? !(await clientUploadsAccess({ collectionSlug, req })) : !req.user)\n ) {\n throw new Forbidden(req.t)\n }\n\n assertClientUploadAllowed({ collection, filename, mimeType })\n\n const requested = buildUploadStoragePathData({\n collectionPrefix: prefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n })\n const allowOverwrite = collection.versions\n ? false\n : await authorizeClientOverwrite({\n collectionPrefix: prefix,\n collectionSources,\n overrideAccess,\n req,\n requestedCollectionSlug: collectionSlug,\n requestedFilename: requested.sanitizedFilename,\n requestedStorageFilePath: requested.storageFilePath,\n })\n const resolved = allowOverwrite\n ? {\n ...requested,\n uploadReference: {\n prefix: requested.sanitizedDocPrefix,\n signedReceipt: createClientUploadReceipt({\n allowOverwrite: true,\n collectionSlug,\n filename: requested.sanitizedFilename,\n filePrefix: requested.sanitizedDocPrefix,\n req,\n storageFilePath: requested.storageFilePath,\n }),\n },\n }\n : await resolveSignedURLKey({\n collectionPrefix: prefix,\n collectionSlug,\n docPrefix,\n filename,\n req,\n useCompositePrefixes,\n })\n\n return {\n name: 'uploadToVercelBlob',\n type: 'dispatch',\n data: {\n pathname: resolved.storageFilePath,\n token: await generateClientTokenFromReadWriteToken({\n addRandomSuffix: false,\n allowedContentTypes: mimeType ? [mimeType] : undefined,\n ...(allowOverwrite && { allowOverwrite: true }),\n cacheControlMaxAge,\n maximumSizeInBytes: filesize,\n pathname: resolved.storageFilePath,\n token,\n }),\n },\n file: {\n filename: resolved.sanitizedFilename,\n mimeType,\n size: filesize,\n uploadReference: resolved.uploadReference,\n },\n }\n },\n requiresUploadReceipt: true,\n useInAdmin: true,\n },\n\n generateURL: ({ filename, prefix: urlPrefix = '' }) =>\n generateURL({\n baseUrl,\n collectionPrefix: prefix,\n filename,\n prefix: urlPrefix,\n useCompositePrefixes,\n }),\n\n handleDelete: deleteStoredFile,\n\n handleUpload: async ({ data, file: { buffer, mimeType }, storageFilePath }) => {\n const result = await uploadFile({\n access,\n addRandomSuffix,\n buffer,\n cacheControlMaxAge,\n mimeType,\n storageFilePath,\n token,\n })\n\n if (result.filename) {\n data.filename = result.filename\n }\n\n return data\n },\n\n staticHandler: (req, { doc, headers, params: { filename, operation, uploadReference } }) =>\n getFile({\n baseUrl,\n cacheControlMaxAge,\n collection,\n collectionPrefix: prefix,\n doc,\n filename,\n incomingHeaders: headers,\n operation,\n req,\n token,\n uploadReference,\n useCompositePrefixes,\n }),\n })\n}\n"],"names":["buildUploadStoragePathData","resolveSignedURLKey","generateClientTokenFromReadWriteToken","Forbidden","assertClientUploadAllowed","createClientUploadReceipt","authorizeClientOverwrite","copyVercelBlobFile","deleteFile","generateURL","getFile","uploadFile","createVercelBlobAdapter","access","addRandomSuffix","baseUrl","cacheControlMaxAge","clientUploads","collectionSources","token","useCompositePrefixes","clientUploadsAccess","undefined","deleteStoredFile","storageFilePath","collection","prefix","name","copyFile","from","req","to","uploadInstructions","adminHandler","path","enabled","Boolean","generate","collectionSlug","docPrefix","filename","filesize","mimeType","overrideAccess","user","t","requested","collectionPrefix","allowOverwrite","versions","requestedCollectionSlug","requestedFilename","sanitizedFilename","requestedStorageFilePath","resolved","uploadReference","sanitizedDocPrefix","signedReceipt","filePrefix","type","data","pathname","allowedContentTypes","maximumSizeInBytes","file","size","requiresUploadReceipt","useInAdmin","urlPrefix","handleDelete","handleUpload","buffer","result","staticHandler","doc","headers","params","operation","incomingHeaders"],"mappings":"AAOA,SACEA,0BAA0B,EAC1BC,mBAAmB,QACd,6CAA4C;AACnD,SAASC,qCAAqC,QAAQ,sBAAqB;AAC3E,SAASC,SAAS,QAAQ,UAAS;AACnC,SAASC,yBAAyB,EAAEC,yBAAyB,QAAQ,mBAAkB;AAIvF,SAASC,wBAAwB,QAAQ,8BAA6B;AACtE,SAASC,kBAAkB,QAAQ,gBAAe;AAClD,SAASC,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,UAAU,QAAQ,kBAAiB;AAa5C,OAAO,SAASC,wBAAwB,EACtCC,MAAM,EACNC,eAAe,EACfC,OAAO,EACPC,kBAAkB,EAClBC,aAAa,EACbC,iBAAiB,EACjBC,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AAC3C,KAAK,EAAE4C,GAAG,EAAEC,OAAO,EAAEC,QAAQ,EAAEpC,QAAQ,EAAEqC,SAAS,EAAEtB,eAAe,EAAE,EAAE,GACrF7C,QAAQ;oBACNK;oBACAC;oBACAS;oBACAsB,kBAAkBrB;oBAClBgD;oBACAlC;oBACAsC,iBAAiBH;oBACjBE;oBACA/C;oBACAX;oBACAoC;oBACAnC;gBACF;QACJ,CAAA;AACF"}
|
|
@@ -3,7 +3,7 @@ import { combineQueries, executeAccess, Forbidden } from 'payload';
|
|
|
3
3
|
function getDocumentFileKeys({ collectionPrefix, doc, useCompositePrefixes }) {
|
|
4
4
|
return [
|
|
5
5
|
doc.filename,
|
|
6
|
-
...Object.values(doc.
|
|
6
|
+
...Object.values(doc.variants || {}).map((size)=>size?.filename)
|
|
7
7
|
].filter((filename)=>typeof filename === 'string').map((filename)=>buildStoragePathData({
|
|
8
8
|
collectionPrefix,
|
|
9
9
|
docPrefix: doc.prefix,
|
|
@@ -16,15 +16,15 @@ async function findMatchingDocs({ collectionPrefix, collectionSlug, req, request
|
|
|
16
16
|
if (!collection) {
|
|
17
17
|
return [];
|
|
18
18
|
}
|
|
19
|
-
const
|
|
19
|
+
const variants = collection.config.upload && typeof collection.config.upload === 'object' ? collection.config.upload.variants || [] : [];
|
|
20
20
|
const filenameQueries = [
|
|
21
21
|
{
|
|
22
22
|
filename: {
|
|
23
23
|
equals: requestedFilename
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
|
-
...
|
|
27
|
-
[`
|
|
26
|
+
...variants.map(({ name })=>({
|
|
27
|
+
[`variants.${name}.filename`]: {
|
|
28
28
|
equals: requestedFilename
|
|
29
29
|
}
|
|
30
30
|
}))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/authorizeFileOverwrite.ts"],"sourcesContent":["import type { FileData, PayloadRequest, TypeWithID, Where } from 'payload'\n\nimport {\n buildStoragePathData,\n isStoragePathWithinCollectionPrefix,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { combineQueries, executeAccess, Forbidden } from 'payload'\n\ntype OwnerDocument = { prefix?: string } & FileData & TypeWithID\n\nexport type VercelBlobCollectionSource = {\n collectionPrefix: string\n collectionSlug: string\n useCompositePrefixes: boolean\n}\n\ntype Owner = {\n collectionSlug: string\n doc: OwnerDocument\n}\n\nfunction getDocumentFileKeys({\n collectionPrefix,\n doc,\n useCompositePrefixes,\n}: {\n collectionPrefix: string\n doc: OwnerDocument\n useCompositePrefixes: boolean\n}): string[] {\n return [doc.filename, ...Object.values(doc.
|
|
1
|
+
{"version":3,"sources":["../src/authorizeFileOverwrite.ts"],"sourcesContent":["import type { FileData, PayloadRequest, TypeWithID, Where } from 'payload'\n\nimport {\n buildStoragePathData,\n isStoragePathWithinCollectionPrefix,\n} from '@payloadcms/plugin-cloud-storage/utilities'\nimport { combineQueries, executeAccess, Forbidden } from 'payload'\n\ntype OwnerDocument = { prefix?: string } & FileData & TypeWithID\n\nexport type VercelBlobCollectionSource = {\n collectionPrefix: string\n collectionSlug: string\n useCompositePrefixes: boolean\n}\n\ntype Owner = {\n collectionSlug: string\n doc: OwnerDocument\n}\n\nfunction getDocumentFileKeys({\n collectionPrefix,\n doc,\n useCompositePrefixes,\n}: {\n collectionPrefix: string\n doc: OwnerDocument\n useCompositePrefixes: boolean\n}): string[] {\n return [doc.filename, ...Object.values(doc.variants || {}).map((size) => size?.filename)]\n .filter((filename): filename is string => typeof filename === 'string')\n .map(\n (filename) =>\n buildStoragePathData({\n collectionPrefix,\n docPrefix: doc.prefix,\n filename,\n useCompositePrefixes,\n }).storageFilePath,\n )\n}\n\nasync function findMatchingDocs({\n collectionPrefix,\n collectionSlug,\n req,\n requestedFilename,\n requestedStorageFilePath,\n useCompositePrefixes,\n}: {\n collectionPrefix: string\n collectionSlug: string\n req: PayloadRequest\n requestedFilename: string\n requestedStorageFilePath: string\n useCompositePrefixes: boolean\n}): Promise<OwnerDocument[]> {\n const collection = req.payload.collections[collectionSlug]\n\n if (!collection) {\n return []\n }\n\n const variants =\n collection.config.upload && typeof collection.config.upload === 'object'\n ? collection.config.upload.variants || []\n : []\n const filenameQueries: Where[] = [\n { filename: { equals: requestedFilename } },\n ...variants.map(({ name }) => ({\n [`variants.${name}.filename`]: { equals: requestedFilename },\n })),\n ]\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: true,\n overrideAccess: true,\n pagination: false,\n req,\n where: { or: filenameQueries },\n })\n\n return (result.docs as OwnerDocument[]).filter((doc) =>\n getDocumentFileKeys({ collectionPrefix, doc, useCompositePrefixes }).includes(\n requestedStorageFilePath,\n ),\n )\n}\n\nasync function canUpdateDoc({\n collectionSlug,\n doc,\n req,\n}: {\n collectionSlug: string\n doc: OwnerDocument\n req: PayloadRequest\n}): Promise<boolean> {\n const collection = req.payload.collections[collectionSlug]\n\n if (!collection) {\n return false\n }\n\n const accessResult = await executeAccess(\n { id: doc.id, slug: collectionSlug, disableErrors: true, req },\n collection.config.access.update,\n )\n\n if (typeof accessResult === 'boolean') {\n return accessResult\n }\n\n const result = await req.payload.find({\n collection: collectionSlug,\n depth: 0,\n draft: true,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n where: combineQueries({ id: { equals: doc.id } }, accessResult),\n })\n\n return result.docs.length === 1\n}\n\nexport async function authorizeClientOverwrite({\n collectionPrefix: collectionPrefixArg,\n collectionSources,\n overrideAccess = false,\n req,\n requestedCollectionSlug,\n requestedFilename,\n requestedStorageFilePath,\n}: {\n collectionPrefix: string\n collectionSources: VercelBlobCollectionSource[]\n overrideAccess?: boolean\n req: PayloadRequest\n requestedCollectionSlug: string\n requestedFilename: string\n requestedStorageFilePath: string\n}): Promise<boolean> {\n if (\n !isStoragePathWithinCollectionPrefix({\n collectionPrefix: collectionPrefixArg,\n docPrefix: requestedStorageFilePath,\n })\n ) {\n throw new Forbidden(req.t)\n }\n\n const matchedDocs = (\n await Promise.all(\n collectionSources.map(\n async ({ collectionPrefix, collectionSlug, useCompositePrefixes }): Promise<Owner[]> => {\n const docs = await findMatchingDocs({\n collectionPrefix,\n collectionSlug,\n req,\n requestedFilename,\n requestedStorageFilePath,\n useCompositePrefixes,\n })\n\n return docs.map((doc) => ({ collectionSlug, doc }))\n },\n ),\n )\n ).flat()\n\n if (matchedDocs.length === 0) {\n return false\n }\n\n const matchedDoc = matchedDocs[0]!\n if (matchedDocs.length !== 1 || matchedDoc.collectionSlug !== requestedCollectionSlug) {\n throw new Forbidden(req.t)\n }\n\n if (\n !overrideAccess &&\n !(await canUpdateDoc({ collectionSlug: matchedDoc.collectionSlug, doc: matchedDoc.doc, req }))\n ) {\n throw new Forbidden(req.t)\n }\n\n return true\n}\n"],"names":["buildStoragePathData","isStoragePathWithinCollectionPrefix","combineQueries","executeAccess","Forbidden","getDocumentFileKeys","collectionPrefix","doc","useCompositePrefixes","filename","Object","values","variants","map","size","filter","docPrefix","prefix","storageFilePath","findMatchingDocs","collectionSlug","req","requestedFilename","requestedStorageFilePath","collection","payload","collections","config","upload","filenameQueries","equals","name","result","find","depth","draft","overrideAccess","pagination","where","or","docs","includes","canUpdateDoc","accessResult","id","slug","disableErrors","access","update","limit","length","authorizeClientOverwrite","collectionPrefixArg","collectionSources","requestedCollectionSlug","t","matchedDocs","Promise","all","flat","matchedDoc"],"mappings":"AAEA,SACEA,oBAAoB,EACpBC,mCAAmC,QAC9B,6CAA4C;AACnD,SAASC,cAAc,EAAEC,aAAa,EAAEC,SAAS,QAAQ,UAAS;AAelE,SAASC,oBAAoB,EAC3BC,gBAAgB,EAChBC,GAAG,EACHC,oBAAoB,EAKrB;IACC,OAAO;QAACD,IAAIE,QAAQ;WAAKC,OAAOC,MAAM,CAACJ,IAAIK,QAAQ,IAAI,CAAC,GAAGC,GAAG,CAAC,CAACC,OAASA,MAAML;KAAU,CACtFM,MAAM,CAAC,CAACN,WAAiC,OAAOA,aAAa,UAC7DI,GAAG,CACF,CAACJ,WACCT,qBAAqB;YACnBM;YACAU,WAAWT,IAAIU,MAAM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3B;IAEA,IACE,CAACnB,kBACD,CAAE,MAAMM,aAAa;QAAEtB,gBAAgBwC,WAAWxC,cAAc;QAAEb,KAAKqD,WAAWrD,GAAG;QAAEc;IAAI,IAC3F;QACA,MAAM,IAAIjB,UAAUiB,IAAIkC,CAAC;IAC3B;IAEA,OAAO;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VercelBlobClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VercelBlobClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,6BAA6B;;;;;;iCAexC,CAAA"}
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client';
|
|
3
3
|
import { put } from '@vercel/blob/client';
|
|
4
|
-
/** Last path segment only (POSIX), for keys like `folder/sub/file.png`. */ function posixBasename(key) {
|
|
5
|
-
const normalized = key.replace(/^\/+/, '');
|
|
6
|
-
const lastSlash = normalized.lastIndexOf('/');
|
|
7
|
-
return lastSlash === -1 ? normalized : normalized.slice(lastSlash + 1);
|
|
8
|
-
}
|
|
9
4
|
export const VercelBlobClientUploadHandler = createClientUploadHandler({
|
|
10
5
|
name: 'uploadToVercelBlob',
|
|
11
|
-
handler: async ({ data, file
|
|
6
|
+
handler: async ({ data, file })=>{
|
|
12
7
|
const { pathname, token } = data;
|
|
13
8
|
const result = await put(pathname, file, {
|
|
14
9
|
access: 'public',
|
|
15
10
|
contentType: file.type,
|
|
16
11
|
token
|
|
17
12
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
updateFilename(filename);
|
|
13
|
+
if (decodeURIComponent(result.pathname) !== decodeURIComponent(pathname)) {
|
|
14
|
+
throw new Error('The uploaded file was stored at an unexpected location');
|
|
21
15
|
}
|
|
22
16
|
}
|
|
23
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\nimport { put } from '@vercel/blob/client'\n\
|
|
1
|
+
{"version":3,"sources":["../../src/client/VercelBlobClientUploadHandler.ts"],"sourcesContent":["'use client'\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\nimport { put } from '@vercel/blob/client'\n\nexport const VercelBlobClientUploadHandler = createClientUploadHandler({\n name: 'uploadToVercelBlob',\n handler: async ({ data, file }) => {\n const { pathname, token } = data as { pathname: string; token: string }\n\n const result = await put(pathname, file, {\n access: 'public',\n contentType: file.type,\n token,\n })\n\n if (decodeURIComponent(result.pathname) !== decodeURIComponent(pathname)) {\n throw new Error('The uploaded file was stored at an unexpected location')\n }\n },\n})\n"],"names":["createClientUploadHandler","put","VercelBlobClientUploadHandler","name","handler","data","file","pathname","token","result","access","contentType","type","decodeURIComponent","Error"],"mappings":"AAAA;AACA,SAASA,yBAAyB,QAAQ,0CAAyC;AACnF,SAASC,GAAG,QAAQ,sBAAqB;AAEzC,OAAO,MAAMC,gCAAgCF,0BAA0B;IACrEG,MAAM;IACNC,SAAS,OAAO,EAAEC,IAAI,EAAEC,IAAI,EAAE;QAC5B,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGH;QAE5B,MAAMI,SAAS,MAAMR,IAAIM,UAAUD,MAAM;YACvCI,QAAQ;YACRC,aAAaL,KAAKM,IAAI;YACtBJ;QACF;QAEA,IAAIK,mBAAmBJ,OAAOF,QAAQ,MAAMM,mBAAmBN,WAAW;YACxE,MAAM,IAAIO,MAAM;QAClB;IACF;AACF,GAAE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PayloadRequest } from 'payload';
|
|
2
|
+
type Args = {
|
|
3
|
+
access: 'public';
|
|
4
|
+
cacheControlMaxAge: number;
|
|
5
|
+
from: string;
|
|
6
|
+
req?: PayloadRequest;
|
|
7
|
+
to: string;
|
|
8
|
+
token: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const copyVercelBlobFile: ({ access, cacheControlMaxAge, from, req, to, token, }: Args) => Promise<void>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=copyFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyFile.d.ts","sourceRoot":"","sources":["../src/copyFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAI7C,KAAK,IAAI,GAAG;IACV,MAAM,EAAE,QAAQ,CAAA;IAChB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,cAAc,CAAA;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,kBAAkB,0DAO5B,IAAI,KAAG,OAAO,CAAC,IAAI,CA+ErB,CAAA"}
|
package/dist/copyFile.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { BlobNotFoundError, copy, del, head, put } from '@vercel/blob';
|
|
2
|
+
export const copyVercelBlobFile = async ({ access, cacheControlMaxAge, from, req, to, token })=>{
|
|
3
|
+
if (from === to) {
|
|
4
|
+
throw new Error('Storage copy requires different source and destination keys');
|
|
5
|
+
}
|
|
6
|
+
const source = await head(from, {
|
|
7
|
+
token
|
|
8
|
+
});
|
|
9
|
+
try {
|
|
10
|
+
await head(to, {
|
|
11
|
+
token
|
|
12
|
+
});
|
|
13
|
+
throw new Error(`Storage destination already exists: ${to}`);
|
|
14
|
+
} catch (err) {
|
|
15
|
+
if (!isBlobNotFound(err)) {
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const sourceMaxAge = /(?:^|,)\s*max-age=(\d+)/.exec(source.cacheControl);
|
|
20
|
+
let copied = await copy(from, to, {
|
|
21
|
+
access,
|
|
22
|
+
addRandomSuffix: false,
|
|
23
|
+
allowOverwrite: false,
|
|
24
|
+
cacheControlMaxAge: sourceMaxAge ? Number(sourceMaxAge[1]) : cacheControlMaxAge,
|
|
25
|
+
contentType: source.contentType,
|
|
26
|
+
token
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
if (copied.pathname !== to) {
|
|
30
|
+
throw new Error(`Vercel Blob assigned an unexpected destination key: ${copied.pathname}`);
|
|
31
|
+
}
|
|
32
|
+
let destination = await head(to, {
|
|
33
|
+
token
|
|
34
|
+
});
|
|
35
|
+
if (destination.size !== source.size) {
|
|
36
|
+
await del(to, {
|
|
37
|
+
ifMatch: copied.etag,
|
|
38
|
+
token
|
|
39
|
+
});
|
|
40
|
+
// The first copy is gone; a rejected fallback must not delete another upload's object.
|
|
41
|
+
copied = undefined;
|
|
42
|
+
const sourceResponse = await fetch(source.url);
|
|
43
|
+
if (!sourceResponse.ok || !sourceResponse.body) {
|
|
44
|
+
throw new Error(`Vercel Blob source is not readable: ${from}`);
|
|
45
|
+
}
|
|
46
|
+
copied = await put(to, sourceResponse.body, {
|
|
47
|
+
access,
|
|
48
|
+
addRandomSuffix: false,
|
|
49
|
+
allowOverwrite: false,
|
|
50
|
+
cacheControlMaxAge: sourceMaxAge ? Number(sourceMaxAge[1]) : cacheControlMaxAge,
|
|
51
|
+
contentType: source.contentType,
|
|
52
|
+
token
|
|
53
|
+
});
|
|
54
|
+
if (copied.pathname !== to) {
|
|
55
|
+
throw new Error(`Vercel Blob assigned an unexpected destination key: ${copied.pathname}`);
|
|
56
|
+
}
|
|
57
|
+
destination = await head(to, {
|
|
58
|
+
token
|
|
59
|
+
});
|
|
60
|
+
if (destination.size !== source.size) {
|
|
61
|
+
throw new Error(`Copied Vercel Blob object is not readable at its expected length: ${to}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
if (copied) {
|
|
66
|
+
try {
|
|
67
|
+
if (copied.pathname === from || !copied.etag) {
|
|
68
|
+
throw new Error('Vercel Blob copy did not return a safe destination for cleanup');
|
|
69
|
+
}
|
|
70
|
+
await del(copied.pathname, {
|
|
71
|
+
ifMatch: copied.etag,
|
|
72
|
+
token
|
|
73
|
+
});
|
|
74
|
+
} catch (cleanupError) {
|
|
75
|
+
req?.payload.logger.error({
|
|
76
|
+
err: cleanupError,
|
|
77
|
+
msg: `Failed to remove unsuccessful Vercel Blob copy at ${copied.pathname}`
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const isBlobNotFound = (err)=>err instanceof BlobNotFoundError || err !== null && typeof err === 'object' && 'name' in err && err.name === 'BlobNotFoundError';
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=copyFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/copyFile.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { BlobNotFoundError, copy, del, head, put } from '@vercel/blob'\n\ntype Args = {\n access: 'public'\n cacheControlMaxAge: number\n from: string\n req?: PayloadRequest\n to: string\n token: string\n}\n\nexport const copyVercelBlobFile = async ({\n access,\n cacheControlMaxAge,\n from,\n req,\n to,\n token,\n}: Args): Promise<void> => {\n if (from === to) {\n throw new Error('Storage copy requires different source and destination keys')\n }\n\n const source = await head(from, { token })\n\n try {\n await head(to, { token })\n throw new Error(`Storage destination already exists: ${to}`)\n } catch (err) {\n if (!isBlobNotFound(err)) {\n throw err\n }\n }\n\n const sourceMaxAge = /(?:^|,)\\s*max-age=(\\d+)/.exec(source.cacheControl)\n let copied: { etag: string; pathname: string } | undefined = await copy(from, to, {\n access,\n addRandomSuffix: false,\n allowOverwrite: false,\n cacheControlMaxAge: sourceMaxAge ? Number(sourceMaxAge[1]) : cacheControlMaxAge,\n contentType: source.contentType,\n token,\n })\n\n try {\n if (copied.pathname !== to) {\n throw new Error(`Vercel Blob assigned an unexpected destination key: ${copied.pathname}`)\n }\n\n let destination = await head(to, { token })\n\n if (destination.size !== source.size) {\n await del(to, { ifMatch: copied.etag, token })\n // The first copy is gone; a rejected fallback must not delete another upload's object.\n copied = undefined\n\n const sourceResponse = await fetch(source.url)\n\n if (!sourceResponse.ok || !sourceResponse.body) {\n throw new Error(`Vercel Blob source is not readable: ${from}`)\n }\n\n copied = await put(to, sourceResponse.body, {\n access,\n addRandomSuffix: false,\n allowOverwrite: false,\n cacheControlMaxAge: sourceMaxAge ? Number(sourceMaxAge[1]) : cacheControlMaxAge,\n contentType: source.contentType,\n token,\n })\n\n if (copied.pathname !== to) {\n throw new Error(`Vercel Blob assigned an unexpected destination key: ${copied.pathname}`)\n }\n\n destination = await head(to, { token })\n\n if (destination.size !== source.size) {\n throw new Error(`Copied Vercel Blob object is not readable at its expected length: ${to}`)\n }\n }\n } catch (err) {\n if (copied) {\n try {\n if (copied.pathname === from || !copied.etag) {\n throw new Error('Vercel Blob copy did not return a safe destination for cleanup')\n }\n await del(copied.pathname, { ifMatch: copied.etag, token })\n } catch (cleanupError) {\n req?.payload.logger.error({\n err: cleanupError,\n msg: `Failed to remove unsuccessful Vercel Blob copy at ${copied.pathname}`,\n })\n }\n }\n throw err\n }\n}\n\nconst isBlobNotFound = (err: unknown): boolean =>\n err instanceof BlobNotFoundError ||\n (err !== null && typeof err === 'object' && 'name' in err && err.name === 'BlobNotFoundError')\n"],"names":["BlobNotFoundError","copy","del","head","put","copyVercelBlobFile","access","cacheControlMaxAge","from","req","to","token","Error","source","err","isBlobNotFound","sourceMaxAge","exec","cacheControl","copied","addRandomSuffix","allowOverwrite","Number","contentType","pathname","destination","size","ifMatch","etag","undefined","sourceResponse","fetch","url","ok","body","cleanupError","payload","logger","error","msg","name"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,IAAI,EAAEC,GAAG,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M,IAAIoB,eAAeI,IAAI,EAAE;gBAC1C5B;gBACAc,iBAAiB;gBACjBC,gBAAgB;gBAChBd,oBAAoBS,eAAeM,OAAON,YAAY,CAAC,EAAE,IAAIT;gBAC7DgB,aAAaV,OAAOU,WAAW;gBAC/BZ;YACF;YAEA,IAAIQ,OAAOK,QAAQ,KAAKd,IAAI;gBAC1B,MAAM,IAAIE,MAAM,CAAC,oDAAoD,EAAEO,OAAOK,QAAQ,EAAE;YAC1F;YAEAC,cAAc,MAAMtB,KAAKO,IAAI;gBAAEC;YAAM;YAErC,IAAIc,YAAYC,IAAI,KAAKb,OAAOa,IAAI,EAAE;gBACpC,MAAM,IAAId,MAAM,CAAC,kEAAkE,EAAEF,IAAI;YAC3F;QACF;IACF,EAAE,OAAOI,KAAK;QACZ,IAAIK,QAAQ;YACV,IAAI;gBACF,IAAIA,OAAOK,QAAQ,KAAKhB,QAAQ,CAACW,OAAOS,IAAI,EAAE;oBAC5C,MAAM,IAAIhB,MAAM;gBAClB;gBACA,MAAMV,IAAIiB,OAAOK,QAAQ,EAAE;oBAAEG,SAASR,OAAOS,IAAI;oBAAEjB;gBAAM;YAC3D,EAAE,OAAOwB,cAAc;gBACrB1B,KAAK2B,QAAQC,OAAOC,MAAM;oBACxBxB,KAAKqB;oBACLI,KAAK,CAAC,kDAAkD,EAAEpB,OAAOK,QAAQ,EAAE;gBAC7E;YACF;QACF;QACA,MAAMV;IACR;AACF,EAAC;AAED,MAAMC,iBAAiB,CAACD,MACtBA,eAAed,qBACdc,QAAQ,QAAQ,OAAOA,QAAQ,YAAY,UAAUA,OAAOA,IAAI0B,IAAI,KAAK"}
|
package/dist/getFile.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload';
|
|
1
|
+
import type { CollectionConfig, FileHandlerOperation, PayloadRequest, TypeWithID } from 'payload';
|
|
2
2
|
interface GetFileArgs {
|
|
3
3
|
baseUrl: string;
|
|
4
4
|
cacheControlMaxAge: number;
|
|
@@ -7,11 +7,12 @@ interface GetFileArgs {
|
|
|
7
7
|
doc?: TypeWithID;
|
|
8
8
|
filename: string;
|
|
9
9
|
incomingHeaders?: Headers;
|
|
10
|
+
operation?: FileHandlerOperation;
|
|
10
11
|
req: PayloadRequest;
|
|
11
12
|
token: string;
|
|
12
13
|
uploadReference?: unknown;
|
|
13
14
|
useCompositePrefixes?: boolean;
|
|
14
15
|
}
|
|
15
|
-
export declare function getFile({ baseUrl, cacheControlMaxAge, collection, collectionPrefix, doc, filename, incomingHeaders, req, token, uploadReference, useCompositePrefixes, }: GetFileArgs): Promise<Response>;
|
|
16
|
+
export declare function getFile({ baseUrl, cacheControlMaxAge, collection, collectionPrefix, doc, filename, incomingHeaders, operation, req, token, uploadReference, useCompositePrefixes, }: GetFileArgs): Promise<Response>;
|
|
16
17
|
export {};
|
|
17
18
|
//# sourceMappingURL=getFile.d.ts.map
|
package/dist/getFile.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../src/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getFile.d.ts","sourceRoot":"","sources":["../src/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAQjG,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAA;IACf,kBAAkB,EAAE,MAAM,CAAA;IAC1B,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE,UAAU,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,SAAS,CAAC,EAAE,oBAAoB,CAAA;IAChC,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,wBAAsB,OAAO,CAAC,EAC5B,OAAO,EACP,kBAAkB,EAClB,UAAU,EACV,gBAAqB,EACrB,GAAG,EACH,QAAQ,EACR,eAAe,EACf,SAAkB,EAClB,GAAG,EACH,KAAK,EACL,eAAe,EACf,oBAA4B,GAC7B,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAsGjC"}
|
package/dist/getFile.js
CHANGED
|
@@ -2,7 +2,8 @@ import { getFilePrefix as getDocPrefix } from '@payloadcms/plugin-cloud-storage/
|
|
|
2
2
|
import { BlobNotFoundError, head } from '@vercel/blob';
|
|
3
3
|
import { getRangeRequestInfo, isXmlMimeType, uploadContentSecurityPolicy } from 'payload/internal';
|
|
4
4
|
import { generateURL } from './generateURL.js';
|
|
5
|
-
export async function getFile({ baseUrl, cacheControlMaxAge, collection, collectionPrefix = '', doc, filename, incomingHeaders, req, token, uploadReference, useCompositePrefixes = false }) {
|
|
5
|
+
export async function getFile({ baseUrl, cacheControlMaxAge, collection, collectionPrefix = '', doc, filename, incomingHeaders, operation = 'read', req, token, uploadReference, useCompositePrefixes = false }) {
|
|
6
|
+
const isTransformSource = operation === 'transform';
|
|
6
7
|
try {
|
|
7
8
|
const docPrefix = await getDocPrefix({
|
|
8
9
|
collection,
|
|
@@ -28,8 +29,7 @@ export async function getFile({ baseUrl, cacheControlMaxAge, collection, collect
|
|
|
28
29
|
const uploadedAtString = uploadedAt.toISOString();
|
|
29
30
|
const fileKeyForETag = fileUrl.replace(`${baseUrl}/`, '');
|
|
30
31
|
const ETag = `"${fileKeyForETag}-${uploadedAtString}"`;
|
|
31
|
-
|
|
32
|
-
const rangeHeader = req.headers.get('range');
|
|
32
|
+
const rangeHeader = isTransformSource ? null : req.headers.get('range');
|
|
33
33
|
const rangeResult = getRangeRequestInfo({
|
|
34
34
|
fileSize: size,
|
|
35
35
|
rangeHeader
|
|
@@ -41,7 +41,6 @@ export async function getFile({ baseUrl, cacheControlMaxAge, collection, collect
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
let headers = new Headers(incomingHeaders);
|
|
44
|
-
// Add range-related headers from the result
|
|
45
44
|
for (const [key, value] of Object.entries(rangeResult.headers)){
|
|
46
45
|
headers.append(key, value);
|
|
47
46
|
}
|
|
@@ -53,12 +52,12 @@ export async function getFile({ baseUrl, cacheControlMaxAge, collection, collect
|
|
|
53
52
|
if (isXmlMimeType(contentType)) {
|
|
54
53
|
headers.append('Content-Security-Policy', uploadContentSecurityPolicy);
|
|
55
54
|
}
|
|
56
|
-
if (collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
|
|
55
|
+
if (!isTransformSource && collection.upload && typeof collection.upload === 'object' && typeof collection.upload.modifyResponseHeaders === 'function') {
|
|
57
56
|
headers = collection.upload.modifyResponseHeaders({
|
|
58
57
|
headers
|
|
59
58
|
}) || headers;
|
|
60
59
|
}
|
|
61
|
-
if (etagFromHeaders && etagFromHeaders === ETag) {
|
|
60
|
+
if (!isTransformSource && etagFromHeaders && etagFromHeaders === ETag) {
|
|
62
61
|
return new Response(null, {
|
|
63
62
|
headers,
|
|
64
63
|
status: 304
|
|
@@ -74,6 +73,13 @@ export async function getFile({ baseUrl, cacheControlMaxAge, collection, collect
|
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
75
|
if (!response.ok || !response.body) {
|
|
76
|
+
// A transformer needs the real failure status; masking it as 204 is only safe for a plain download.
|
|
77
|
+
if (isTransformSource) {
|
|
78
|
+
return new Response(null, {
|
|
79
|
+
status: response.status,
|
|
80
|
+
statusText: response.statusText
|
|
81
|
+
});
|
|
82
|
+
}
|
|
77
83
|
return new Response(null, {
|
|
78
84
|
status: 204,
|
|
79
85
|
statusText: 'No Content'
|
package/dist/getFile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload'\n\nimport { getFilePrefix as getDocPrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { BlobNotFoundError, head } from '@vercel/blob'\nimport { getRangeRequestInfo, isXmlMimeType, uploadContentSecurityPolicy } from 'payload/internal'\n\nimport { generateURL } from './generateURL.js'\n\ninterface GetFileArgs {\n baseUrl: string\n cacheControlMaxAge: number\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: TypeWithID\n filename: string\n incomingHeaders?: Headers\n req: PayloadRequest\n token: string\n uploadReference?: unknown\n useCompositePrefixes?: boolean\n}\n\nexport async function getFile({\n baseUrl,\n cacheControlMaxAge,\n collection,\n collectionPrefix = '',\n doc,\n filename,\n incomingHeaders,\n req,\n token,\n uploadReference,\n useCompositePrefixes = false,\n}: GetFileArgs): Promise<Response> {\n try {\n const docPrefix = await getDocPrefix({\n collection,\n collectionPrefix,\n doc,\n filename,\n req,\n uploadReference,\n useCompositePrefixes,\n })\n\n const fileUrl = generateURL({\n baseUrl,\n collectionPrefix,\n filename,\n prefix: docPrefix,\n useCompositePrefixes,\n })\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 fileKeyForETag = fileUrl.replace(`${baseUrl}/`, '')\n const ETag = `\"${fileKeyForETag}-${uploadedAtString}\"`\n\n
|
|
1
|
+
{"version":3,"sources":["../src/getFile.ts"],"sourcesContent":["import type { CollectionConfig, FileHandlerOperation, PayloadRequest, TypeWithID } from 'payload'\n\nimport { getFilePrefix as getDocPrefix } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { BlobNotFoundError, head } from '@vercel/blob'\nimport { getRangeRequestInfo, isXmlMimeType, uploadContentSecurityPolicy } from 'payload/internal'\n\nimport { generateURL } from './generateURL.js'\n\ninterface GetFileArgs {\n baseUrl: string\n cacheControlMaxAge: number\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: TypeWithID\n filename: string\n incomingHeaders?: Headers\n operation?: FileHandlerOperation\n req: PayloadRequest\n token: string\n uploadReference?: unknown\n useCompositePrefixes?: boolean\n}\n\nexport async function getFile({\n baseUrl,\n cacheControlMaxAge,\n collection,\n collectionPrefix = '',\n doc,\n filename,\n incomingHeaders,\n operation = 'read',\n req,\n token,\n uploadReference,\n useCompositePrefixes = false,\n}: GetFileArgs): Promise<Response> {\n const isTransformSource = operation === 'transform'\n\n try {\n const docPrefix = await getDocPrefix({\n collection,\n collectionPrefix,\n doc,\n filename,\n req,\n uploadReference,\n useCompositePrefixes,\n })\n\n const fileUrl = generateURL({\n baseUrl,\n collectionPrefix,\n filename,\n prefix: docPrefix,\n useCompositePrefixes,\n })\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 fileKeyForETag = fileUrl.replace(`${baseUrl}/`, '')\n const ETag = `\"${fileKeyForETag}-${uploadedAtString}\"`\n\n const rangeHeader = isTransformSource ? null : 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 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 // Apply a restrictive policy to XML-family responses served through Payload.\n if (isXmlMimeType(contentType)) {\n headers.append('Content-Security-Policy', uploadContentSecurityPolicy)\n }\n\n if (\n !isTransformSource &&\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 (!isTransformSource && 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 // A transformer needs the real failure status; masking it as 204 is only safe for a plain download.\n if (isTransformSource) {\n return new Response(null, { status: response.status, statusText: response.statusText })\n }\n\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"],"names":["getFilePrefix","getDocPrefix","BlobNotFoundError","head","getRangeRequestInfo","isXmlMimeType","uploadContentSecurityPolicy","generateURL","getFile","baseUrl","cacheControlMaxAge","collection","collectionPrefix","doc","filename","incomingHeaders","operation","req","token","uploadReference","useCompositePrefixes","isTransformSource","docPrefix","fileUrl","prefix","etagFromHeaders","headers","get","blobMetadata","contentDisposition","contentType","size","uploadedAt","uploadedAtString","toISOString","fileKeyForETag","replace","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":"AAEA,SAASA,iBAAiBC,YAAY,QAAQ,6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AQQ,SAASR,MAAM;oBAAEgB,YAAYR,SAASQ,UAAU;gBAAC;YACvF;YAEA,OAAO,IAAIlB,SAAS,MAAM;gBAAEE,QAAQ;gBAAKgB,YAAY;YAAa;QACpE;QAEAlC,QAAQuB,MAAM,CAAC,iBAAiBhB;QAEhC,OAAO,IAAIS,SAASU,SAASO,IAAI,EAAE;YACjCjC;YACAkB,QAAQL,YAAYK,MAAM;QAC5B;IACF,EAAE,OAAOiB,KAAc;QACrB,IAAIA,eAAe3D,mBAAmB;YACpC,OAAO,IAAIwC,SAAS,MAAM;gBAAEE,QAAQ;gBAAKgB,YAAY;YAAY;QACnE;QACA3C,IAAI6C,OAAO,CAACC,MAAM,CAACC,KAAK,CAAC;YAAEH;YAAKI,KAAK;QAAoC;QACzE,OAAO,IAAIvB,SAAS,yBAAyB;YAAEE,QAAQ;QAAI;IAC7D;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export type VercelBlobStorageOptions = {
|
|
|
9
9
|
*/
|
|
10
10
|
access?: 'public';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Must be false or omitted for enabled adapters with configured collections.
|
|
13
|
+
* Payload requires exact storage paths and allocates unique object folders.
|
|
13
14
|
*
|
|
14
15
|
* @default false
|
|
15
16
|
*/
|
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,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAW3E,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IAEjB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EAEnB,iBAAiB,EAClB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAU,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAW3E,MAAM,MAAM,wBAAwB,GAAG;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,QAAQ,CAAA;IAEjB;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB;;;;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;IACjB;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IAEzB;;;;;;;;;;;;;OAaG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AASD,KAAK,wBAAwB,GAAG,CAAC,qBAAqB,EAAE,wBAAwB,KAAK,cAAc,CAAA;AAEnG,eAAO,MAAM,iBAAiB,EAAE,wBA8G/B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -39,6 +39,9 @@ export const vercelBlobStorage = (options)=>{
|
|
|
39
39
|
useCompositePrefixes: options.useCompositePrefixes
|
|
40
40
|
})(incomingConfig);
|
|
41
41
|
}
|
|
42
|
+
if (options.addRandomSuffix && storageAdapter.collections.length > 0) {
|
|
43
|
+
throw new Error('Vercel Blob addRandomSuffix must be false. Payload requires exact storage paths and already allocates unique object folders.');
|
|
44
|
+
}
|
|
42
45
|
const adapter = createVercelBlobAdapter({
|
|
43
46
|
access: optionsWithDefaults.access ?? 'public',
|
|
44
47
|
addRandomSuffix: optionsWithDefaults.addRandomSuffix,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { createVercelBlobAdapter } from './adapter.js'\nimport {\n getCollectionSources,\n type InternalVercelBlobStorageAdapter,\n vercelBlobStorageMetadata,\n} from './getCollectionSources.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 *
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n ClientUploadsConfig,\n PluginOptions as CloudStoragePluginOptions,\n CollectionOptions,\n} from '@payloadcms/plugin-cloud-storage/types'\nimport type { Config, StorageAdapter, UploadCollectionSlug } from 'payload'\n\nimport { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage'\n\nimport { createVercelBlobAdapter } from './adapter.js'\nimport {\n getCollectionSources,\n type InternalVercelBlobStorageAdapter,\n vercelBlobStorageMetadata,\n} from './getCollectionSources.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 * Must be false or omitted for enabled adapters with configured collections.\n * Payload requires exact storage paths and allocates unique object folders.\n *\n * @default false\n */\n addRandomSuffix?: 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 * Upload directly to Vercel Blob instead of through Payload.\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 * 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 /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), a document prefix already within the\n * collection prefix is used as-is for new uploads; otherwise it is nested beneath it.\n * Existing files retain their stored prefixes for reads, URLs, and cleanup.\n *\n * Example with a document prefix already contained by the collection prefix:\n * - collection prefix: `uploads/`\n * - document prefix: `uploads/documents/`\n * - resulting prefix with useCompositePrefixes=true: `uploads/uploads/documents/`\n * - resulting prefix with useCompositePrefixes=false: `uploads/documents/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\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 VercelBlobStorageFactory = (vercelBlobStorageOpts: VercelBlobStorageOptions) => StorageAdapter\n\nexport const vercelBlobStorage: VercelBlobStorageFactory = (\n options: VercelBlobStorageOptions,\n): StorageAdapter => {\n const storeId = options.token?.match(/^vercel_blob_rw_([a-z\\d]+)_[a-z\\d]+$/i)?.[1]?.toLowerCase()\n const isPluginDisabled = options.enabled === false || !options.token\n const storageAdapter: InternalVercelBlobStorageAdapter = {\n name: 'vercel-blob',\n collections: Object.keys(options.collections),\n init: (incomingConfig: Config): Config => {\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 // support overriding the base URL for emulator https://github.com/payloadcms/vercel-blob-emulator\n const baseUrl =\n process.env.STORAGE_VERCEL_BLOB_BASE_URL ||\n `https://${storeId}.${optionsWithDefaults.access}.blob.vercel-storage.com`\n\n // If the plugin is disabled or no token is provided, do not enable the plugin\n if (isPluginDisabled) {\n const collectionsWithoutAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n options.collections,\n ).reduce(\n (acc, [slug, collOptions]) => ({\n ...acc,\n [slug]: { ...(collOptions === true ? {} : collOptions), adapter: null },\n }),\n {} as Record<string, CollectionOptions>,\n )\n return cloudStoragePlugin({\n collections: collectionsWithoutAdapter,\n enabled: false,\n useCompositePrefixes: options.useCompositePrefixes,\n })(incomingConfig)\n }\n\n if (options.addRandomSuffix && storageAdapter.collections.length > 0) {\n throw new Error(\n 'Vercel Blob addRandomSuffix must be false. Payload requires exact storage paths and already allocates unique object folders.',\n )\n }\n\n const adapter = createVercelBlobAdapter({\n access: optionsWithDefaults.access ?? 'public',\n addRandomSuffix: optionsWithDefaults.addRandomSuffix,\n baseUrl,\n cacheControlMaxAge: optionsWithDefaults.cacheControlMaxAge ?? 60 * 60 * 24 * 365,\n clientUploads: optionsWithDefaults.clientUploads,\n collectionSources: getCollectionSources({\n currentAdapter: storageAdapter,\n storageAdapters: incomingConfig.storage,\n }),\n token: options.token!,\n useCompositePrefixes: options.useCompositePrefixes,\n })\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 useCompositePrefixes: options.useCompositePrefixes,\n })(config)\n },\n [vercelBlobStorageMetadata]: {\n collections: options.collections,\n enabled: !isPluginDisabled,\n storeId,\n useCompositePrefixes: Boolean(options.useCompositePrefixes),\n },\n }\n\n return storageAdapter\n}\n"],"names":["cloudStoragePlugin","createVercelBlobAdapter","getCollectionSources","vercelBlobStorageMetadata","defaultUploadOptions","access","addRandomSuffix","cacheControlMaxAge","enabled","vercelBlobStorage","options","storeId","token","match","toLowerCase","isPluginDisabled","storageAdapter","name","collections","Object","keys","init","incomingConfig","Error","optionsWithDefaults","baseUrl","process","env","STORAGE_VERCEL_BLOB_BASE_URL","collectionsWithoutAdapter","entries","reduce","acc","slug","collOptions","adapter","useCompositePrefixes","length","clientUploads","collectionSources","currentAdapter","storageAdapters","storage","collectionsWithAdapter","config","map","collection","upload","disableLocalStorage","Boolean"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AAErE,SAASC,uBAAuB,QAAQ,eAAc;AACtD,SACEC,oBAAoB,EAEpBC,yBAAyB,QACpB,4BAA2B;AAoElC,MAAMC,uBAA0D;IAC9DC,QAAQ;IACRC,iBAAiB;IACjBC,oBAAoB,KAAK,KAAK,KAAK;IACnCC,SAAS;AACX;AAIA,OAAO,MAAMC,oBAA8C,CACzDC;IAEA,MAAMC,UAAUD,QAAQE,KAAK,EAAEC,MAAM,0CAA0C,CAAC,EAAE,EAAEC;IACpF,MAAMC,mBAAmBL,QAAQF,OAAO,KAAK,SAAS,CAACE,QAAQE,KAAK;IACpE,MAAMI,iBAAmD;QACvDC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACV,QAAQQ,WAAW;QAC5CG,MAAM,CAACC;YACL,wCAAwC;YACxC,IAAI,CAACX,WAAW,CAACI,kBAAkB;gBACjC,MAAM,IAAIQ,MACR;YAEJ;YAEA,MAAMC,sBAAsB;gBAC1B,GAAGpB,oBAAoB;gBACvB,GAAGM,OAAO;YACZ;YAEA,kGAAkG;YA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AC,IAAIA,WAAW;wBAC3CC;oBACF;gBACF,CAAA,GACA,CAAC;YAGH,gFAAgF;YAChF,MAAMS,SAAS;gBACb,GAAGtB,cAAc;gBACjBJ,aAAa,AAACI,CAAAA,eAAeJ,WAAW,IAAI,EAAE,AAAD,EAAG2B,GAAG,CAAC,CAACC;oBACnD,IAAI,CAACH,sBAAsB,CAACG,WAAWb,IAAI,CAAC,EAAE;wBAC5C,OAAOa;oBACT;oBAEA,OAAO;wBACL,GAAGA,UAAU;wBACbC,QAAQ;4BACN,GAAI,OAAOD,WAAWC,MAAM,KAAK,WAAWD,WAAWC,MAAM,GAAG,CAAC,CAAC;4BAClEC,qBAAqB;wBACvB;oBACF;gBACF;YACF;YAEA,OAAOhD,mBAAmB;gBACxBkB,aAAayB;gBACbP,sBAAsB1B,QAAQ0B,oBAAoB;YACpD,GAAGQ;QACL;QACA,CAACzC,0BAA0B,EAAE;YAC3Be,aAAaR,QAAQQ,WAAW;YAChCV,SAAS,CAACO;YACVJ;YACAyB,sBAAsBa,QAAQvC,QAAQ0B,oBAAoB;QAC5D;IACF;IAEA,OAAOpB;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-vercel-blob",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.d3909a9",
|
|
4
4
|
"description": "Payload storage adapter for Vercel Blob Storage",
|
|
5
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
6
|
"license": "MIT",
|
|
12
7
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
13
8
|
"maintainers": [
|
|
@@ -17,8 +12,18 @@
|
|
|
17
12
|
"url": "https://payloadcms.com"
|
|
18
13
|
}
|
|
19
14
|
],
|
|
20
|
-
"
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
18
|
+
"directory": "packages/storage-vercel-blob"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
21
23
|
"type": "module",
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
22
27
|
"exports": {
|
|
23
28
|
".": {
|
|
24
29
|
"import": "./dist/index.js",
|
|
@@ -31,20 +36,15 @@
|
|
|
31
36
|
"default": "./dist/exports/client.js"
|
|
32
37
|
}
|
|
33
38
|
},
|
|
34
|
-
"main": "./dist/index.js",
|
|
35
|
-
"types": "./dist/index.d.ts",
|
|
36
|
-
"files": [
|
|
37
|
-
"dist"
|
|
38
|
-
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@vercel/blob": "2.3.1",
|
|
41
|
-
"@payloadcms/plugin-cloud-storage": "4.0.0-internal.
|
|
41
|
+
"@payloadcms/plugin-cloud-storage": "4.0.0-internal.d3909a9"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"payload": "4.0.0-internal.
|
|
44
|
+
"payload": "4.0.0-internal.d3909a9"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"payload": "4.0.0-internal.
|
|
47
|
+
"payload": "4.0.0-internal.d3909a9"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
50
|
"node": ">=24.15.0"
|
|
@@ -55,8 +55,6 @@
|
|
|
55
55
|
"build:debug": "pnpm build",
|
|
56
56
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
57
57
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
58
|
-
"clean": "rimraf -g {dist,*.tsbuildinfo}"
|
|
59
|
-
"lint": "eslint .",
|
|
60
|
-
"lint:fix": "eslint . --fix"
|
|
58
|
+
"clean": "rimraf -g {dist,*.tsbuildinfo}"
|
|
61
59
|
}
|
|
62
60
|
}
|