|
| 1 | +diff --git a/dist/client/VercelBlobClientUploadHandler.d.ts b/dist/client/VercelBlobClientUploadHandler.d.ts |
| 2 | +index 984feebe49e7bfaabd0294eebaa9415e09e0e5cd..18285f61580c050750d6312d12a8cdfb5d4ba6c8 100644 |
| 3 | +--- a/dist/client/VercelBlobClientUploadHandler.d.ts |
| 4 | ++++ b/dist/client/VercelBlobClientUploadHandler.d.ts |
| 5 | +@@ -1,5 +1,6 @@ |
| 6 | + export type VercelBlobClientUploadHandlerExtra = { |
| 7 | + addRandomSuffix: boolean; |
| 8 | ++ allowOverwrite: boolean; |
| 9 | + baseURL: string; |
| 10 | + prefix: string; |
| 11 | + }; |
| 12 | +diff --git a/dist/client/VercelBlobClientUploadHandler.js b/dist/client/VercelBlobClientUploadHandler.js |
| 13 | +index 94a3512c0436805acba26910adb595cf970f4961..cda0b0aea5769c0522b7e9d609d9b919f89a43aa 100644 |
| 14 | +--- a/dist/client/VercelBlobClientUploadHandler.js |
| 15 | ++++ b/dist/client/VercelBlobClientUploadHandler.js |
| 16 | +@@ -3,7 +3,7 @@ import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/clie |
| 17 | + import { upload } from '@vercel/blob/client'; |
| 18 | + import { formatAdminURL } from 'payload/shared'; |
| 19 | + export const VercelBlobClientUploadHandler = createClientUploadHandler({ |
| 20 | +- handler: async ({ apiRoute, collectionSlug, extra: { addRandomSuffix, baseURL, prefix = '' }, file, serverHandlerPath, serverURL, updateFilename })=>{ |
| 21 | ++ handler: async ({ apiRoute, collectionSlug, extra: { addRandomSuffix, allowOverwrite, baseURL, prefix = '' }, file, serverHandlerPath, serverURL, updateFilename })=>{ |
| 22 | + const endpointRoute = formatAdminURL({ |
| 23 | + apiRoute, |
| 24 | + path: serverHandlerPath, |
| 25 | +diff --git a/dist/getClientUploadRoute.d.ts b/dist/getClientUploadRoute.d.ts |
| 26 | +index b0d9157554801e9a873ad09c1ace7c6c5db43a90..519f19e05145f5aaabd7afe8571149b529019b50 100644 |
| 27 | +--- a/dist/getClientUploadRoute.d.ts |
| 28 | ++++ b/dist/getClientUploadRoute.d.ts |
| 29 | +@@ -5,9 +5,10 @@ type Args = { |
| 30 | + req: PayloadRequest; |
| 31 | + }) => boolean | Promise<boolean>; |
| 32 | + addRandomSuffix?: boolean; |
| 33 | ++ allowOverwrite?: boolean; |
| 34 | + cacheControlMaxAge?: number; |
| 35 | + token: string; |
| 36 | + }; |
| 37 | +-export declare const getClientUploadRoute: ({ access, addRandomSuffix, cacheControlMaxAge, token }: Args) => PayloadHandler; |
| 38 | ++export declare const getClientUploadRoute: ({ access, addRandomSuffix, allowOverwrite, cacheControlMaxAge, token }: Args) => PayloadHandler; |
| 39 | + export {}; |
| 40 | + //# sourceMappingURL=getClientUploadRoute.d.ts.map |
| 41 | +\ No newline at end of file |
| 42 | +diff --git a/dist/getClientUploadRoute.js b/dist/getClientUploadRoute.js |
| 43 | +index e11cf568867309efcb243fab490a33c6b01c46a8..bfeeee12b5180db867576f1a33738ebd076850a7 100644 |
| 44 | +--- a/dist/getClientUploadRoute.js |
| 45 | ++++ b/dist/getClientUploadRoute.js |
| 46 | +@@ -1,7 +1,7 @@ |
| 47 | + import { handleUpload } from '@vercel/blob/client'; |
| 48 | + import { APIError, Forbidden } from 'payload'; |
| 49 | + const defaultAccess = ({ req })=>!!req.user; |
| 50 | +-export const getClientUploadRoute = ({ access = defaultAccess, addRandomSuffix, cacheControlMaxAge, token })=>async (req)=>{ |
| 51 | ++export const getClientUploadRoute = ({ access = defaultAccess, addRandomSuffix, allowOverwrite, cacheControlMaxAge, token })=>async (req)=>{ |
| 52 | + const body = await req.json(); |
| 53 | + try { |
| 54 | + const jsonResponse = await handleUpload({ |
| 55 | +@@ -18,6 +18,7 @@ export const getClientUploadRoute = ({ access = defaultAccess, addRandomSuffix, |
| 56 | + } |
| 57 | + return Promise.resolve({ |
| 58 | + addRandomSuffix, |
| 59 | ++ allowOverwrite, |
| 60 | + cacheControlMaxAge |
| 61 | + }); |
| 62 | + }, |
| 63 | +diff --git a/dist/handleUpload.d.ts b/dist/handleUpload.d.ts |
| 64 | +index 74b7b972fc9dbeffb7a2c79c8b472c831e61a670..404b4e4f2adc0d8f0180fae9428444232a2e4d6f 100644 |
| 65 | +--- a/dist/handleUpload.d.ts |
| 66 | ++++ b/dist/handleUpload.d.ts |
| 67 | +@@ -4,6 +4,6 @@ type HandleUploadArgs = { |
| 68 | + baseUrl: string; |
| 69 | + prefix?: string; |
| 70 | + } & Omit<VercelBlobStorageOptions, 'collections'>; |
| 71 | +-export declare const getHandleUpload: ({ access, addRandomSuffix, baseUrl, cacheControlMaxAge, prefix, token, }: HandleUploadArgs) => HandleUpload; |
| 72 | ++export declare const getHandleUpload: ({ access, addRandomSuffix, allowOverwrite, baseUrl, cacheControlMaxAge, prefix, token, }: HandleUploadArgs) => HandleUpload; |
| 73 | + export {}; |
| 74 | + //# sourceMappingURL=handleUpload.d.ts.map |
| 75 | +\ No newline at end of file |
| 76 | +diff --git a/dist/handleUpload.js b/dist/handleUpload.js |
| 77 | +index db797445156822d2a2a0024b303df940b446e4c2..eedefda709bf53e7f0b4bd2f1b0cdc81e5267c52 100644 |
| 78 | +--- a/dist/handleUpload.js |
| 79 | ++++ b/dist/handleUpload.js |
| 80 | +@@ -1,11 +1,12 @@ |
| 81 | + import { put } from '@vercel/blob'; |
| 82 | + import path from 'path'; |
| 83 | +-export const getHandleUpload = ({ access = 'public', addRandomSuffix, baseUrl, cacheControlMaxAge, prefix = '', token })=>{ |
| 84 | ++export const getHandleUpload = ({ access = 'public', addRandomSuffix, allowOverwrite, baseUrl, cacheControlMaxAge, prefix = '', token })=>{ |
| 85 | + return async ({ data, file: { buffer, filename, mimeType } })=>{ |
| 86 | + const fileKey = path.posix.join(data.prefix || prefix, filename); |
| 87 | + const result = await put(fileKey, buffer, { |
| 88 | + access, |
| 89 | + addRandomSuffix, |
| 90 | ++ allowOverwrite, |
| 91 | + cacheControlMaxAge, |
| 92 | + contentType: mimeType, |
| 93 | + token |
| 94 | +diff --git a/dist/index.d.ts b/dist/index.d.ts |
| 95 | +index 8949c2db42d2657bdd7a72e1476420ce9766ea23..1edaf94546ad7876d4577a7150ed3b85f14f1585 100644 |
| 96 | +--- a/dist/index.d.ts |
| 97 | ++++ b/dist/index.d.ts |
| 98 | +@@ -14,6 +14,13 @@ export type VercelBlobStorageOptions = { |
| 99 | + * @default false |
| 100 | + */ |
| 101 | + addRandomSuffix?: boolean; |
| 102 | ++ /** |
| 103 | ++ * Allow overwriting existing blobs with the same pathname. |
| 104 | ++ * When false (default), uploading a blob with an existing pathname throws an error. |
| 105 | ++ * |
| 106 | ++ * @default false |
| 107 | ++ */ |
| 108 | ++ allowOverwrite?: boolean; |
| 109 | + /** |
| 110 | + * When enabled, fields (like the prefix field) will always be inserted into |
| 111 | + * the collection schema regardless of whether the plugin is enabled. This |
| 112 | +diff --git a/dist/index.js b/dist/index.js |
| 113 | +index 7c56ee05908afb9dfb3bfa20f2a5b9ed3e4cca69..7ca12e268e986d595c86840cce40dd1ae5949021 100644 |
| 114 | +--- a/dist/index.js |
| 115 | ++++ b/dist/index.js |
| 116 | +@@ -8,6 +8,7 @@ import { getStaticHandler } from './staticHandler.js'; |
| 117 | + const defaultUploadOptions = { |
| 118 | + access: 'public', |
| 119 | + addRandomSuffix: false, |
| 120 | ++ allowOverwrite: false, |
| 121 | + cacheControlMaxAge: 60 * 60 * 24 * 365, |
| 122 | + enabled: true |
| 123 | + }; |
| 124 | +@@ -32,12 +33,14 @@ export const vercelBlobStorage = (options)=>(incomingConfig)=>{ |
| 125 | + enabled: !isPluginDisabled && Boolean(options.clientUploads), |
| 126 | + extraClientHandlerProps: (collection)=>({ |
| 127 | + addRandomSuffix: !!optionsWithDefaults.addRandomSuffix, |
| 128 | ++ allowOverwrite: !!optionsWithDefaults.allowOverwrite, |
| 129 | + baseURL: baseUrl, |
| 130 | + prefix: typeof collection === 'object' && collection.prefix && `${collection.prefix}/` || '' |
| 131 | + }), |
| 132 | + serverHandler: getClientUploadRoute({ |
| 133 | + access: typeof options.clientUploads === 'object' ? options.clientUploads.access : undefined, |
| 134 | + addRandomSuffix: optionsWithDefaults.addRandomSuffix, |
| 135 | ++ allowOverwrite: optionsWithDefaults.allowOverwrite, |
| 136 | + cacheControlMaxAge: options.cacheControlMaxAge, |
| 137 | + token: options.token ?? '' |
| 138 | + }), |
| 139 | +@@ -96,7 +99,7 @@ export const vercelBlobStorage = (options)=>(incomingConfig)=>{ |
| 140 | + }; |
| 141 | + function vercelBlobStorageInternal(options) { |
| 142 | + return ({ collection, prefix })=>{ |
| 143 | +- const { access, addRandomSuffix, baseUrl, cacheControlMaxAge, clientUploads, token } = options; |
| 144 | ++ const { access, addRandomSuffix, allowOverwrite, baseUrl, cacheControlMaxAge, clientUploads, token } = options; |
| 145 | + if (!token) { |
| 146 | + throw new Error('Vercel Blob storage token is required'); |
| 147 | + } |
| 148 | +@@ -115,6 +118,7 @@ function vercelBlobStorageInternal(options) { |
| 149 | + handleUpload: getHandleUpload({ |
| 150 | + access, |
| 151 | + addRandomSuffix, |
| 152 | ++ allowOverwrite, |
| 153 | + baseUrl, |
| 154 | + cacheControlMaxAge, |
| 155 | + prefix, |
0 commit comments