@payloadcms/storage-r2 4.0.0-internal.5b1e7cd → 4.0.0-internal.c2b57ce
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/dist/client/R2ClientUploadHandler.d.ts +1 -1
- package/dist/client/R2ClientUploadHandler.d.ts.map +1 -1
- package/dist/client/R2ClientUploadHandler.js +5 -2
- package/dist/client/R2ClientUploadHandler.js.map +1 -1
- package/dist/handleMultiPartUpload.d.ts.map +1 -1
- package/dist/handleMultiPartUpload.js +5 -2
- package/dist/handleMultiPartUpload.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -49
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { R2StorageClientUploadHandlerParams } from '../types.js';
|
|
2
2
|
export declare const R2ClientUploadHandler: ({ children, collectionSlug, enabled, extra, prefix, serverHandlerPath, }: {
|
|
3
3
|
children: import("react").ReactNode;
|
|
4
|
-
collectionSlug: import("
|
|
4
|
+
collectionSlug: import("payload").UploadCollectionSlug;
|
|
5
5
|
enabled?: boolean;
|
|
6
6
|
extra: R2StorageClientUploadHandlerParams;
|
|
7
7
|
prefix?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"R2ClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/R2ClientUploadHandler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAGV,kCAAkC,EAGnC,MAAM,aAAa,CAAA;AAEpB,eAAO,MAAM,qBAAqB;;;;;;;
|
|
1
|
+
{"version":3,"file":"R2ClientUploadHandler.d.ts","sourceRoot":"","sources":["../../src/client/R2ClientUploadHandler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAGV,kCAAkC,EAGnC,MAAM,aAAa,CAAA;AAEpB,eAAO,MAAM,qBAAqB;;;;;;;iCAyFhC,CAAA"}
|
|
@@ -3,7 +3,7 @@ import { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/clie
|
|
|
3
3
|
import { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
4
4
|
import { formatAdminURL } from 'payload/shared';
|
|
5
5
|
export const R2ClientUploadHandler = createClientUploadHandler({
|
|
6
|
-
handler: async ({ apiRoute, collectionSlug, docPrefix, extra: { chunkSize = 5 * 1024 * 1024 }, file, prefix, serverHandlerPath, serverURL })=>{
|
|
6
|
+
handler: async ({ apiRoute, collectionSlug, docPrefix, extra: { chunkSize = 5 * 1024 * 1024 }, file, prefix, serverHandlerPath, serverURL, updateFilename })=>{
|
|
7
7
|
const { sanitizedDocPrefix } = getFileKey({
|
|
8
8
|
collectionPrefix: prefix,
|
|
9
9
|
docPrefix,
|
|
@@ -28,7 +28,10 @@ export const R2ClientUploadHandler = createClientUploadHandler({
|
|
|
28
28
|
if (!multipart.ok) {
|
|
29
29
|
throw new Error('Failed to initialize multipart upload');
|
|
30
30
|
}
|
|
31
|
-
const multipartUpload = await multipart.json();
|
|
31
|
+
const { filename: sanitizedFilename, ...multipartUpload } = await multipart.json();
|
|
32
|
+
if (sanitizedFilename && sanitizedFilename !== file.name) {
|
|
33
|
+
updateFilename(sanitizedFilename);
|
|
34
|
+
}
|
|
32
35
|
const multipartUploadedParts = [];
|
|
33
36
|
params.multipartId = multipartUpload.uploadId;
|
|
34
37
|
params.multipartKey = multipartUpload.key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/client/R2ClientUploadHandler.ts"],"sourcesContent":["'use client'\n\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\nimport { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { formatAdminURL } from 'payload/shared'\n\nimport type {\n R2MultipartUpload,\n R2StorageClientUploadContext,\n R2StorageClientUploadHandlerParams,\n R2StorageMultipartUploadHandlerParams,\n R2UploadedPart,\n} from '../types.js'\n\nexport const R2ClientUploadHandler = createClientUploadHandler<R2StorageClientUploadHandlerParams>({\n handler: async ({\n apiRoute,\n collectionSlug,\n docPrefix,\n extra: { chunkSize = 5 * 1024 * 1024 },\n file,\n prefix,\n serverHandlerPath,\n serverURL,\n }): Promise<R2StorageClientUploadContext | undefined> => {\n const { sanitizedDocPrefix } = getFileKey({\n collectionPrefix: prefix,\n docPrefix,\n filename: file.name,\n })\n\n const params: R2StorageMultipartUploadHandlerParams = {\n collection: collectionSlug,\n docPrefix: sanitizedDocPrefix,\n fileName: file.name,\n fileType: file.type,\n }\n const baseURL = formatAdminURL({\n apiRoute,\n path: serverHandlerPath,\n serverURL,\n })\n\n const endpoint = `${baseURL}?${String(new URLSearchParams(params))}`\n\n // upload the file directly to R2 using the signed URL\n const multipart = await fetch(endpoint, { method: 'POST' })\n if (!multipart.ok) {\n throw new Error('Failed to initialize multipart upload')\n }\n\n const multipartUpload = (await multipart.json()) as Pick<R2MultipartUpload, 'key' | 'uploadId'>\n const multipartUploadedParts: R2UploadedPart[] = []\n\n params.multipartId = multipartUpload.uploadId\n params.multipartKey = multipartUpload.key\n\n const partTotal = Math.ceil(file.size / chunkSize)\n\n for (let part = 1; part <= partTotal; part++) {\n const bytesEnd = Math.min(part * chunkSize, file.size)\n const bytesStart = (part - 1) * chunkSize\n\n params.multipartNumber = String(part)\n\n const body = file.slice(bytesStart, bytesEnd)\n const headers = {\n 'Content-Length': String(body.size),\n 'Content-Type': 'application/octet-stream',\n }\n const uploaded = await fetch(endpoint, { body, headers, method: 'POST' })\n if (!uploaded.ok) {\n throw new Error(`Failed to upload part ${part} / ${partTotal}`)\n }\n\n multipartUploadedParts.push((await uploaded.json()) as R2UploadedPart)\n\n if (part === partTotal) {\n delete params.multipartNumber\n\n const body = JSON.stringify(multipartUploadedParts)\n const headers = { 'Content-Type': 'application/json' }\n const complete = await fetch(endpoint, { body, headers, method: 'POST' })\n if (!complete.ok) {\n throw new Error(`Failed to complete multipart upload`)\n }\n\n const key = await complete.text()\n return {\n key,\n prefix: sanitizedDocPrefix,\n }\n }\n }\n },\n})\n"],"names":["createClientUploadHandler","getFileKey","formatAdminURL","R2ClientUploadHandler","handler","apiRoute","collectionSlug","docPrefix","extra","chunkSize","file","prefix","serverHandlerPath","serverURL","sanitizedDocPrefix","collectionPrefix","filename","name","params","collection","fileName","fileType","type","baseURL","path","endpoint","String","URLSearchParams","multipart","fetch","method","ok","Error","multipartUpload","json","multipartUploadedParts","multipartId","uploadId","multipartKey","key","partTotal","Math","ceil","size","part","bytesEnd","min","bytesStart","multipartNumber","body","slice","headers","uploaded","push","JSON","stringify","complete","text"],"mappings":"AAAA;AAEA,SAASA,yBAAyB,QAAQ,0CAAyC;AACnF,SAASC,UAAU,QAAQ,6CAA4C;AACvE,SAASC,cAAc,QAAQ,iBAAgB;AAU/C,OAAO,MAAMC,wBAAwBH,0BAA8D;IACjGI,SAAS,OAAO,EACdC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,OAAO,EAAEC,YAAY,IAAI,OAAO,IAAI,EAAE,EACtCC,IAAI,EACJC,MAAM,EACNC,iBAAiB,EACjBC,SAAS,
|
|
1
|
+
{"version":3,"sources":["../../src/client/R2ClientUploadHandler.ts"],"sourcesContent":["'use client'\n\nimport { createClientUploadHandler } from '@payloadcms/plugin-cloud-storage/client'\nimport { getFileKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { formatAdminURL } from 'payload/shared'\n\nimport type {\n R2MultipartUpload,\n R2StorageClientUploadContext,\n R2StorageClientUploadHandlerParams,\n R2StorageMultipartUploadHandlerParams,\n R2UploadedPart,\n} from '../types.js'\n\nexport const R2ClientUploadHandler = createClientUploadHandler<R2StorageClientUploadHandlerParams>({\n handler: async ({\n apiRoute,\n collectionSlug,\n docPrefix,\n extra: { chunkSize = 5 * 1024 * 1024 },\n file,\n prefix,\n serverHandlerPath,\n serverURL,\n updateFilename,\n }): Promise<R2StorageClientUploadContext | undefined> => {\n const { sanitizedDocPrefix } = getFileKey({\n collectionPrefix: prefix,\n docPrefix,\n filename: file.name,\n })\n\n const params: R2StorageMultipartUploadHandlerParams = {\n collection: collectionSlug,\n docPrefix: sanitizedDocPrefix,\n fileName: file.name,\n fileType: file.type,\n }\n const baseURL = formatAdminURL({\n apiRoute,\n path: serverHandlerPath,\n serverURL,\n })\n\n const endpoint = `${baseURL}?${String(new URLSearchParams(params))}`\n\n // upload the file directly to R2 using the signed URL\n const multipart = await fetch(endpoint, { method: 'POST' })\n if (!multipart.ok) {\n throw new Error('Failed to initialize multipart upload')\n }\n\n const { filename: sanitizedFilename, ...multipartUpload } = (await multipart.json()) as {\n filename?: string\n } & Pick<R2MultipartUpload, 'key' | 'uploadId'>\n\n if (sanitizedFilename && sanitizedFilename !== file.name) {\n updateFilename(sanitizedFilename)\n }\n\n const multipartUploadedParts: R2UploadedPart[] = []\n\n params.multipartId = multipartUpload.uploadId\n params.multipartKey = multipartUpload.key\n\n const partTotal = Math.ceil(file.size / chunkSize)\n\n for (let part = 1; part <= partTotal; part++) {\n const bytesEnd = Math.min(part * chunkSize, file.size)\n const bytesStart = (part - 1) * chunkSize\n\n params.multipartNumber = String(part)\n\n const body = file.slice(bytesStart, bytesEnd)\n const headers = {\n 'Content-Length': String(body.size),\n 'Content-Type': 'application/octet-stream',\n }\n const uploaded = await fetch(endpoint, { body, headers, method: 'POST' })\n if (!uploaded.ok) {\n throw new Error(`Failed to upload part ${part} / ${partTotal}`)\n }\n\n multipartUploadedParts.push((await uploaded.json()) as R2UploadedPart)\n\n if (part === partTotal) {\n delete params.multipartNumber\n\n const body = JSON.stringify(multipartUploadedParts)\n const headers = { 'Content-Type': 'application/json' }\n const complete = await fetch(endpoint, { body, headers, method: 'POST' })\n if (!complete.ok) {\n throw new Error(`Failed to complete multipart upload`)\n }\n\n const key = await complete.text()\n return {\n key,\n prefix: sanitizedDocPrefix,\n }\n }\n }\n },\n})\n"],"names":["createClientUploadHandler","getFileKey","formatAdminURL","R2ClientUploadHandler","handler","apiRoute","collectionSlug","docPrefix","extra","chunkSize","file","prefix","serverHandlerPath","serverURL","updateFilename","sanitizedDocPrefix","collectionPrefix","filename","name","params","collection","fileName","fileType","type","baseURL","path","endpoint","String","URLSearchParams","multipart","fetch","method","ok","Error","sanitizedFilename","multipartUpload","json","multipartUploadedParts","multipartId","uploadId","multipartKey","key","partTotal","Math","ceil","size","part","bytesEnd","min","bytesStart","multipartNumber","body","slice","headers","uploaded","push","JSON","stringify","complete","text"],"mappings":"AAAA;AAEA,SAASA,yBAAyB,QAAQ,0CAAyC;AACnF,SAASC,UAAU,QAAQ,6CAA4C;AACvE,SAASC,cAAc,QAAQ,iBAAgB;AAU/C,OAAO,MAAMC,wBAAwBH,0BAA8D;IACjGI,SAAS,OAAO,EACdC,QAAQ,EACRC,cAAc,EACdC,SAAS,EACTC,OAAO,EAAEC,YAAY,IAAI,OAAO,IAAI,EAAE,EACtCC,IAAI,EACJC,MAAM,EACNC,iBAAiB,EACjBC,SAAS,EACTC,cAAc,EACf;QACC,MAAM,EAAEC,kBAAkB,EAAE,GAAGd,WAAW;YACxCe,kBAAkBL;YAClBJ;YACAU,UAAUP,KAAKQ,IAAI;QACrB;QAEA,MAAMC,SAAgD;YACpDC,YAAYd;YACZC,WAAWQ;YACXM,UAAUX,KAAKQ,IAAI;YACnBI,UAAUZ,KAAKa,IAAI;QACrB;QACA,MAAMC,UAAUtB,eAAe;YAC7BG;YACAoB,MAAMb;YACNC;QACF;QAEA,MAAMa,WAAW,GAAGF,QAAQ,CAAC,EAAEG,OAAO,IAAIC,gBAAgBT,UAAU;QAEpE,sDAAsD;QACtD,MAAMU,YAAY,MAAMC,MAAMJ,UAAU;YAAEK,QAAQ;QAAO;QACzD,IAAI,CAACF,UAAUG,EAAE,EAAE;YACjB,MAAM,IAAIC,MAAM;QAClB;QAEA,MAAM,EAAEhB,UAAUiB,iBAAiB,EAAE,GAAGC,iBAAiB,GAAI,M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M,MAAMiB,SAASC,IAAI;gBAC/B,OAAO;oBACLlB;oBACA9B,QAAQI;gBACV;YACF;QACF;IACF;AACF,GAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleMultiPartUpload.d.ts","sourceRoot":"","sources":["../src/handleMultiPartUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAK7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAyC,MAAM,YAAY,CAAA;AAEjF,KAAK,IAAI,GAAG;IACV,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,MAAM,EAAE,QAAQ,CAAA;IAChB,WAAW,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAC5C,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAGD,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"handleMultiPartUpload.d.ts","sourceRoot":"","sources":["../src/handleMultiPartUpload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AACjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAK7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAyC,MAAM,YAAY,CAAA;AAEjF,KAAK,IAAI,GAAG;IACV,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,MAAM,EAAE,QAAQ,CAAA;IAChB,WAAW,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;IAC5C,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAGD,eAAO,MAAM,wBAAwB,GAClC,uDAA+D,IAAI,KAAG,cA+EtE,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
2
2
|
import { APIError, Forbidden } from 'payload';
|
|
3
3
|
// Adapted from https://developers.cloudflare.com/r2/api/workers/workers-multipart-usage/
|
|
4
4
|
export const getHandleMultiPartUpload = ({ access, bucket, collections, useCompositePrefixes = false })=>async (req)=>{
|
|
@@ -37,10 +37,12 @@ export const getHandleMultiPartUpload = ({ access, bucket, collections, useCompo
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
const collectionPrefix = typeof collectionConfig === 'object' && collectionConfig.prefix || '';
|
|
40
|
-
const { fileKey } =
|
|
40
|
+
const { fileKey, sanitizedFilename } = await resolveSignedURLKey({
|
|
41
41
|
collectionPrefix,
|
|
42
|
+
collectionSlug,
|
|
42
43
|
docPrefix: params.docPrefix ?? undefined,
|
|
43
44
|
filename: params.fileName,
|
|
45
|
+
req,
|
|
44
46
|
useCompositePrefixes
|
|
45
47
|
});
|
|
46
48
|
const multipartId = params.multipartId;
|
|
@@ -68,6 +70,7 @@ export const getHandleMultiPartUpload = ({ access, bucket, collections, useCompo
|
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
return Response.json({
|
|
73
|
+
filename: sanitizedFilename,
|
|
71
74
|
key: multipartUpload.key,
|
|
72
75
|
uploadId: multipartUpload.uploadId
|
|
73
76
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleMultiPartUpload.ts"],"sourcesContent":["import type { ClientUploadsAccess } from '@payloadcms/plugin-cloud-storage/types'\nimport type { PayloadHandler } from 'payload'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/handleMultiPartUpload.ts"],"sourcesContent":["import type { ClientUploadsAccess } from '@payloadcms/plugin-cloud-storage/types'\nimport type { PayloadHandler } from 'payload'\n\nimport { resolveSignedURLKey } from '@payloadcms/plugin-cloud-storage/utilities'\nimport { APIError, Forbidden } from 'payload'\n\nimport type { R2StorageOptions } from './index.js'\nimport type { R2Bucket, R2StorageMultipartUploadHandlerParams } from './types.js'\n\ntype Args = {\n access?: ClientUploadsAccess\n bucket: R2Bucket\n collections: R2StorageOptions['collections']\n useCompositePrefixes?: boolean\n}\n\n// Adapted from https://developers.cloudflare.com/r2/api/workers/workers-multipart-usage/\nexport const getHandleMultiPartUpload =\n ({ access, bucket, collections, useCompositePrefixes = false }: Args): PayloadHandler =>\n async (req) => {\n const params = Object.fromEntries(req.searchParams) as R2StorageMultipartUploadHandlerParams\n const collectionSlug = params.collection\n const filetype = params.fileType\n\n const collectionConfig = collections[collectionSlug]\n if (!collectionConfig) {\n throw new APIError(`Collection ${collectionSlug} was not found in R2 Storage options`)\n }\n\n // Check custom access if provided, otherwise check collection's create access\n if (access) {\n if (!(await access({ collectionSlug, req }))) {\n throw new Forbidden(req.t)\n }\n } else {\n // Use the collection's create access control\n const collection = req.payload.collections[collectionSlug]\n if (!collection) {\n throw new APIError(`Collection ${collectionSlug} not found`)\n }\n\n const createAccess = collection.config.access?.create\n if (createAccess) {\n const hasAccess = await createAccess({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n } else if (!req.user) {\n // No custom access and no user - deny by default\n throw new Forbidden(req.t)\n }\n }\n\n const collectionPrefix = (typeof collectionConfig === 'object' && collectionConfig.prefix) || ''\n const { fileKey, sanitizedFilename } = await resolveSignedURLKey({\n collectionPrefix,\n collectionSlug,\n docPrefix: params.docPrefix ?? undefined,\n filename: params.fileName,\n req,\n useCompositePrefixes,\n })\n\n const multipartId = params.multipartId\n const multipartKey = params.multipartKey\n const multipartNumber = parseInt(params.multipartNumber || '')\n\n if (multipartId && multipartKey) {\n const multipartUpload = bucket.resumeMultipartUpload(multipartKey, multipartId)\n const request = req as Request\n\n if (isNaN(multipartNumber)) {\n // Upload complete\n const object = await multipartUpload.complete((await request.json()) as any)\n return new Response(object.key, { status: 200 })\n } else {\n // Upload part\n const uploadedPart = await multipartUpload.uploadPart(\n multipartNumber,\n await request.arrayBuffer(),\n )\n return Response.json(uploadedPart)\n }\n } else {\n // Create multipart upload\n const multipartUpload = await bucket.createMultipartUpload(fileKey, {\n httpMetadata: {\n contentType: filetype,\n },\n })\n\n return Response.json({\n filename: sanitizedFilename,\n key: multipartUpload.key,\n uploadId: multipartUpload.uploadId,\n })\n }\n }\n"],"names":["resolveSignedURLKey","APIError","Forbidden","getHandleMultiPartUpload","access","bucket","collections","useCompositePrefixes","req","params","Object","fromEntries","searchParams","collectionSlug","collection","filetype","fileType","collectionConfig","t","payload","createAccess","config","create","hasAccess","user","collectionPrefix","prefix","fileKey","sanitizedFilename","docPrefix","undefined","filename","fileName","multipartId","multipartKey","multipartNumber","parseInt","multipartUpload","resumeMultipartUpload","request","isNaN","object","complete","json","Response","key","status","uploadedPart","uploadPart","arrayBuffer","createMultipartUpload","httpMetadata","contentType","uploadId"],"mappings":"AAGA,SAASA,mBAAmB,QAAQ,6CAA4C;AAChF,SAASC,QAAQ,EAAEC,SAAS,QAAQ,UAAS;AAY7C,yFAAyF;AACzF,OAAO,MAAMC,2BACX,CAAC,EAAEC,MAAM,EAAEC,MAAM,EAAEC,WAAW,EAAEC,uBAAuB,KAAK,EAAQ,GACpE,OAAOC;QACL,MAAMC,SAASC,OAAOC,WAAW,CAACH,IAAII,YAAY;QAClD,MAAMC,iBAAiBJ,OAAOK,UAAU;QACxC,MAAMC,WAAWN,OAAOO,QAAQ;QAEhC,MAAMC,mBAAmBX,WAAW,CAACO,eAAe;QACpD,IAAI,CAACI,kBAAkB;YACrB,MAAM,IAAIhB,SAAS,CAAC,WAAW,EAAEY,eAAe,oCAAoC,CAAC;QACvF;QAEA,8EAA8E;QAC9E,IAAIT,QAAQ;YACV,IAAI,CAAE,MAAMA,OAAO;gBAAES;gBAAgBL;YAAI,IAAK;gBAC5C,MAAM,IAAIN,UAAUM,IAAIU,CAAC;YAC3B;QACF,OAAO;YACL,6CA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U,WAAW;gBAE3B,OAAOL,SAASD,IAAI,CAACI;YACvB;QACF,OAAO;YACL,0BAA0B;YAC1B,MAAMV,kBAAkB,MAAMhC,OAAO6C,qBAAqB,CAACvB,SAAS;gBAClEwB,cAAc;oBACZC,aAAarC;gBACf;YACF;YAEA,OAAO6B,SAASD,IAAI,CAAC;gBACnBZ,UAAUH;gBACViB,KAAKR,gBAAgBQ,GAAG;gBACxBQ,UAAUhB,gBAAgBgB,QAAQ;YACpC;QACF;IACF,EAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientUploadsConfig, CollectionOptions } from '@payloadcms/plugin-cloud-storage/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { StorageAdapter, UploadCollectionSlug } from 'payload';
|
|
3
3
|
import type { R2Bucket } from './types.js';
|
|
4
4
|
export interface R2StorageOptions {
|
|
5
5
|
/**
|
|
@@ -37,7 +37,7 @@ export interface R2StorageOptions {
|
|
|
37
37
|
*/
|
|
38
38
|
useCompositePrefixes?: boolean;
|
|
39
39
|
}
|
|
40
|
-
type
|
|
41
|
-
export declare const r2Storage:
|
|
40
|
+
type R2StorageFactory = (r2StorageArgs: R2StorageOptions) => StorageAdapter;
|
|
41
|
+
export declare const r2Storage: R2StorageFactory;
|
|
42
42
|
export {};
|
|
43
43
|
//# sourceMappingURL=index.d.ts.map
|
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,
|
|
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;AAK3E,OAAO,KAAK,EAAE,QAAQ,EAAsC,MAAM,YAAY,CAAA;AAK9E,MAAM,WAAW,gBAAgB;IAC/B;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAE5B,MAAM,EAAE,QAAQ,CAAA;IAChB;;OAEG;IACH,aAAa,CAAC,EAAE,mBAAmB,CAAA;IACnC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;IAC7F,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;;;;;;;OAYG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,KAAK,gBAAgB,GAAG,CAAC,aAAa,EAAE,gBAAgB,KAAK,cAAc,CAAA;AAE3E,eAAO,MAAM,SAAS,EAAE,gBA4EtB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,58 +2,62 @@ import { cloudStoragePlugin } from '@payloadcms/plugin-cloud-storage';
|
|
|
2
2
|
import { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities';
|
|
3
3
|
import { createR2Adapter } from './adapter.js';
|
|
4
4
|
import { getHandleMultiPartUpload } from './handleMultiPartUpload.js';
|
|
5
|
-
export const r2Storage = (r2StorageOptions)=>(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
const isPluginDisabled = r2StorageOptions.enabled === false;
|
|
12
|
-
initClientUploads({
|
|
13
|
-
clientHandler: '@payloadcms/storage-r2/client#R2ClientUploadHandler',
|
|
14
|
-
collections: r2StorageOptions.collections,
|
|
15
|
-
config: incomingConfig,
|
|
16
|
-
enabled: !isPluginDisabled && Boolean(r2StorageOptions.clientUploads),
|
|
17
|
-
serverHandler: getHandleMultiPartUpload({
|
|
18
|
-
access: typeof r2StorageOptions.clientUploads === 'object' ? r2StorageOptions.clientUploads.access : undefined,
|
|
5
|
+
export const r2Storage = (r2StorageOptions)=>({
|
|
6
|
+
name: 'r2',
|
|
7
|
+
collections: Object.keys(r2StorageOptions.collections),
|
|
8
|
+
init: (incomingConfig)=>{
|
|
9
|
+
const adapter = createR2Adapter({
|
|
19
10
|
bucket: r2StorageOptions.bucket,
|
|
11
|
+
clientUploads: r2StorageOptions.clientUploads,
|
|
12
|
+
useCompositePrefixes: r2StorageOptions.useCompositePrefixes
|
|
13
|
+
});
|
|
14
|
+
const isPluginDisabled = r2StorageOptions.enabled === false;
|
|
15
|
+
initClientUploads({
|
|
16
|
+
clientHandler: '@payloadcms/storage-r2/client#R2ClientUploadHandler',
|
|
20
17
|
collections: r2StorageOptions.collections,
|
|
18
|
+
config: incomingConfig,
|
|
19
|
+
enabled: !isPluginDisabled && Boolean(r2StorageOptions.clientUploads),
|
|
20
|
+
serverHandler: getHandleMultiPartUpload({
|
|
21
|
+
access: typeof r2StorageOptions.clientUploads === 'object' ? r2StorageOptions.clientUploads.access : undefined,
|
|
22
|
+
bucket: r2StorageOptions.bucket,
|
|
23
|
+
collections: r2StorageOptions.collections,
|
|
24
|
+
useCompositePrefixes: r2StorageOptions.useCompositePrefixes
|
|
25
|
+
}),
|
|
26
|
+
serverHandlerPath: '/storage-r2-multi-part-upload'
|
|
27
|
+
});
|
|
28
|
+
if (isPluginDisabled) {
|
|
29
|
+
return incomingConfig;
|
|
30
|
+
}
|
|
31
|
+
// Add adapter to each collection option object
|
|
32
|
+
const collectionsWithAdapter = Object.entries(r2StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
|
|
33
|
+
...acc,
|
|
34
|
+
[slug]: {
|
|
35
|
+
...collOptions === true ? {} : collOptions,
|
|
36
|
+
adapter
|
|
37
|
+
}
|
|
38
|
+
}), {});
|
|
39
|
+
// Set disableLocalStorage: true for collections specified in the plugin options
|
|
40
|
+
const config = {
|
|
41
|
+
...incomingConfig,
|
|
42
|
+
collections: (incomingConfig.collections || []).map((collection)=>{
|
|
43
|
+
if (!collectionsWithAdapter[collection.slug]) {
|
|
44
|
+
return collection;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...collection,
|
|
48
|
+
upload: {
|
|
49
|
+
...typeof collection.upload === 'object' ? collection.upload : {},
|
|
50
|
+
disableLocalStorage: true
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
})
|
|
54
|
+
};
|
|
55
|
+
return cloudStoragePlugin({
|
|
56
|
+
alwaysInsertFields: r2StorageOptions.alwaysInsertFields,
|
|
57
|
+
collections: collectionsWithAdapter,
|
|
21
58
|
useCompositePrefixes: r2StorageOptions.useCompositePrefixes
|
|
22
|
-
})
|
|
23
|
-
serverHandlerPath: '/storage-r2-multi-part-upload'
|
|
24
|
-
});
|
|
25
|
-
if (isPluginDisabled) {
|
|
26
|
-
return incomingConfig;
|
|
59
|
+
})(config);
|
|
27
60
|
}
|
|
28
|
-
|
|
29
|
-
const collectionsWithAdapter = Object.entries(r2StorageOptions.collections).reduce((acc, [slug, collOptions])=>({
|
|
30
|
-
...acc,
|
|
31
|
-
[slug]: {
|
|
32
|
-
...collOptions === true ? {} : collOptions,
|
|
33
|
-
adapter
|
|
34
|
-
}
|
|
35
|
-
}), {});
|
|
36
|
-
// Set disableLocalStorage: true for collections specified in the plugin options
|
|
37
|
-
const config = {
|
|
38
|
-
...incomingConfig,
|
|
39
|
-
collections: (incomingConfig.collections || []).map((collection)=>{
|
|
40
|
-
if (!collectionsWithAdapter[collection.slug]) {
|
|
41
|
-
return collection;
|
|
42
|
-
}
|
|
43
|
-
return {
|
|
44
|
-
...collection,
|
|
45
|
-
upload: {
|
|
46
|
-
...typeof collection.upload === 'object' ? collection.upload : {},
|
|
47
|
-
disableLocalStorage: true
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
})
|
|
51
|
-
};
|
|
52
|
-
return cloudStoragePlugin({
|
|
53
|
-
alwaysInsertFields: r2StorageOptions.alwaysInsertFields,
|
|
54
|
-
collections: collectionsWithAdapter,
|
|
55
|
-
useCompositePrefixes: r2StorageOptions.useCompositePrefixes
|
|
56
|
-
})(config);
|
|
57
|
-
};
|
|
61
|
+
});
|
|
58
62
|
|
|
59
63
|
//# sourceMappingURL=index.js.map
|
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,
|
|
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'\nimport { initClientUploads } from '@payloadcms/plugin-cloud-storage/utilities'\n\nimport type { R2Bucket, R2StorageClientUploadHandlerParams } from './types.js'\n\nimport { createR2Adapter } from './adapter.js'\nimport { getHandleMultiPartUpload } from './handleMultiPartUpload.js'\n\nexport interface R2StorageOptions {\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 bucket: R2Bucket\n /**\n * Do uploads directly on the client, to bypass limits on Cloudflare/Vercel.\n */\n clientUploads?: ClientUploadsConfig\n /**\n * Collection options to apply the R2 adapter to.\n */\n collections: Partial<Record<UploadCollectionSlug, Omit<CollectionOptions, 'adapter'> | true>>\n enabled?: boolean\n /**\n * When true, the collection-level prefix and document-level prefix are combined\n * (compositional). When false (default), document prefix overrides collection\n * prefix entirely.\n *\n * Example:\n * - collection prefix: `collection-prefix/`\n * - document prefix: `document-prefix/`\n * - resulting prefix with useCompositePrefixes=true: `collection-prefix/document-prefix/`\n * - resulting prefix with useCompositePrefixes=false: `document-prefix/`\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n\ntype R2StorageFactory = (r2StorageArgs: R2StorageOptions) => StorageAdapter\n\nexport const r2Storage: R2StorageFactory = (\n r2StorageOptions: R2StorageOptions,\n): StorageAdapter => ({\n name: 'r2',\n collections: Object.keys(r2StorageOptions.collections),\n init: (incomingConfig: Config): Config => {\n const adapter = createR2Adapter({\n bucket: r2StorageOptions.bucket,\n clientUploads: r2StorageOptions.clientUploads,\n useCompositePrefixes: r2StorageOptions.useCompositePrefixes,\n })\n\n const isPluginDisabled = r2StorageOptions.enabled === false\n\n initClientUploads<\n R2StorageClientUploadHandlerParams,\n R2StorageOptions['collections'][keyof R2StorageOptions['collections']]\n >({\n clientHandler: '@payloadcms/storage-r2/client#R2ClientUploadHandler',\n collections: r2StorageOptions.collections,\n config: incomingConfig,\n enabled: !isPluginDisabled && Boolean(r2StorageOptions.clientUploads),\n serverHandler: getHandleMultiPartUpload({\n access:\n typeof r2StorageOptions.clientUploads === 'object'\n ? r2StorageOptions.clientUploads.access\n : undefined,\n bucket: r2StorageOptions.bucket,\n collections: r2StorageOptions.collections,\n useCompositePrefixes: r2StorageOptions.useCompositePrefixes,\n }),\n serverHandlerPath: '/storage-r2-multi-part-upload',\n })\n\n if (isPluginDisabled) {\n return incomingConfig\n }\n\n // Add adapter to each collection option object\n const collectionsWithAdapter: CloudStoragePluginOptions['collections'] = Object.entries(\n r2StorageOptions.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: r2StorageOptions.alwaysInsertFields,\n collections: collectionsWithAdapter,\n useCompositePrefixes: r2StorageOptions.useCompositePrefixes,\n })(config)\n },\n})\n"],"names":["cloudStoragePlugin","initClientUploads","createR2Adapter","getHandleMultiPartUpload","r2Storage","r2StorageOptions","name","collections","Object","keys","init","incomingConfig","adapter","bucket","clientUploads","useCompositePrefixes","isPluginDisabled","enabled","clientHandler","config","Boolean","serverHandler","access","undefined","serverHandlerPath","collectionsWithAdapter","entries","reduce","acc","slug","collOptions","map","collection","upload","disableLocalStorage","alwaysInsertFields"],"mappings":"AAOA,SAASA,kBAAkB,QAAQ,mCAAkC;AACrE,SAASC,iBAAiB,QAAQ,6CAA4C;AAI9E,SAASC,eAAe,QAAQ,eAAc;AAC9C,SAASC,wBAAwB,QAAQ,6BAA4B;AA0CrE,OAAO,MAAMC,YAA8B,CACzCC,mBACoB,CAAA;QACpBC,MAAM;QACNC,aAAaC,OAAOC,IAAI,CAACJ,iBAAiBE,WAAW;QACrDG,MAAM,CAACC;YACL,MAAMC,UAAUV,gBAAgB;gBAC9BW,QAAQR,iBAAiBQ,MAAM;gBAC/BC,eAAeT,iBAAiBS,aAAa;gBAC7CC,sBAAsBV,iBAAiBU,oBAAoB;YAC7D;YAEA,MAAMC,mBAAmBX,iBAAiBY,OAAO,KAAK;YAEtDhB,kBAGE;gBACAiB,eAAe;gBACfX,aAAaF,iBAAiBE,WAAW;gBACzCY,QAAQR;gBACRM,SAAS,CAACD,oBAAoBI,QAAQf,iBAAiBS,aAAa;gBACpEO,eAAelB,yBAAyB;oBACtCmB,QACE,OAAOjB,iBAAiBS,aAAa,KAAK,WACtCT,iBAAiBS,aAAa,CAACQ,MAAM,GACrCC;oBACNV,QAAQR,iBAAiBQ,MAAM;oBAC/BN,aAAaF,iBAAiBE,WAAW;oBACzCQ,sBAAsBV,iBAAiBU,oBAAoB;gBAC7D;gBACAS,mBAAmB;YACrB;YAEA,IAAIR,kBAAkB;gBACpB,OAAOL;YACT;YAEA,+CAA+C;YAC/C,MAAMc,yBAAmEjB,OAAOkB,OAAO,CACrFrB,iBAAiBE,WAAW,EAC5BoB,MAAM,CACN,CAACC,KAAK,CAACC,MAAMC,YAAY,GAAM,CAAA;oBAC7B,GAAGF,GAAG;oBACN,CAACC,KAAK,EAAE;wBACN,GAAIC,gBAAgB,OAAO,CAAC,IAAIA,WAAW;wBAC3ClB;oBACF;gBACF,CAAA,GACA,CAAC;YAGH,gFAAgF;YAChF,MAAMO,SAAS;gBACb,GAAGR,cAAc;gBACjBJ,aAAa,AAACI,CAAAA,eAAeJ,WAAW,IAAI,EAAE,AAAD,EAAGwB,GAAG,CAAC,CAACC;oBACnD,IAAI,CAACP,sBAAsB,CAACO,WAAWH,IAAI,CAAC,EAAE;wBAC5C,OAAOG;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,OAAOlC,mBAAmB;gBACxBmC,oBAAoB9B,iBAAiB8B,kBAAkB;gBACvD5B,aAAakB;gBACbV,sBAAsBV,iBAAiBU,oBAAoB;YAC7D,GAAGI;QACL;IACF,CAAA,EAAE"}
|
package/dist/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* R2Range is sourced from Cloudflare so it cannot drift; other types are our own
|
|
4
4
|
* so Node's Blob/Buffer/Headers are accepted and we avoid strict Workers-only types.
|
|
5
5
|
*/
|
|
6
|
-
import type { R2Range } from '@cloudflare/workers-types/2023-07-01';
|
|
6
|
+
import type { R2Range } from '@cloudflare/workers-types/2023-07-01/index.js';
|
|
7
7
|
export type { R2Range };
|
|
8
8
|
export interface R2GetOptions {
|
|
9
9
|
[key: string]: any;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+CAA+C,CAAA;AAE5E,YAAY,EAAE,OAAO,EAAE,CAAA;AAEvB,MAAM,WAAW,YAAY;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAClB,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAA;IACtB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAC7E,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,GAAG,YAAY,CAAC,CAAA;IACtE,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAA;IAC3C,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC,GAAG,CACD,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,WAAW,GAAG,eAAe,GAAG,IAAI,GAAG,IAAI,GAAG,cAAc,GAAG,MAAM,EAC5E,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC,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AM,WAAW,4BAA4B;IAC3C,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;CACf;AACD,MAAM,MAAM,kCAAkC,GAAG;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,qCAAqC,GAAG;IAClD,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * R2 API types compatible with both Node (Miniflare) and Cloudflare Workers.\n * R2Range is sourced from Cloudflare so it cannot drift; other types are our own\n * so Node's Blob/Buffer/Headers are accepted and we avoid strict Workers-only types.\n */\nimport type { R2Range } from '@cloudflare/workers-types/2023-07-01'\n\nexport type { R2Range }\n\nexport interface R2GetOptions {\n [key: string]: any\n onlyIf?: any | Headers\n range?: R2Range\n}\n\nexport interface R2Bucket {\n createMultipartUpload(key: string, options?: any): Promise<R2MultipartUpload>\n delete(keys: string | string[]): Promise<void>\n get(key: string, options?: R2GetOptions): Promise<null | R2ObjectBody>\n head(key: string): Promise<null | R2Object>\n list(options?: any): Promise<any>\n put(\n key: string,\n value: ArrayBuffer | ArrayBufferView | Blob | null | ReadableStream | string,\n options?: any,\n ): Promise<any>\n resumeMultipartUpload(key: string, uploadId: string): R2MultipartUpload\n}\n\ninterface R2HTTPMetadata {\n cacheControl?: string\n cacheExpiry?: Date\n contentDisposition?: string\n contentEncoding?: string\n contentLanguage?: string\n contentType?: string\n}\n\nexport interface R2Object {\n readonly etag: string\n readonly httpMetadata?: R2HTTPMetadata\n readonly key: string\n readonly size: number\n writeHttpMetadata(headers: Headers): void\n}\n\nexport interface R2ObjectBody extends R2Object {\n get body(): ReadableStream\n}\n\nexport interface R2MultipartUpload {\n abort(): Promise<void>\n complete(uploadedParts: R2UploadedPart[]): Promise<R2Object>\n readonly key: string\n readonly uploadId: string\n uploadPart(\n partNumber: number,\n value: (ArrayBuffer | ArrayBufferView) | Blob | ReadableStream | string,\n options?: any,\n ): Promise<R2UploadedPart>\n}\n\nexport interface R2UploadedPart {\n etag: string\n partNumber: number\n}\n\nexport interface R2StorageClientUploadContext {\n key: string\n prefix: string\n}\nexport type R2StorageClientUploadHandlerParams = {\n chunkSize?: number\n}\n\nexport type R2StorageMultipartUploadHandlerParams = {\n collection: string\n docPrefix?: string\n fileName: string\n fileType: string\n multipartId?: string\n multipartKey?: string\n multipartNumber?: string\n}\n"],"names":[],"mappings":"AAAA;;;;CAIC,GAuED,WAQC"}
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * R2 API types compatible with both Node (Miniflare) and Cloudflare Workers.\n * R2Range is sourced from Cloudflare so it cannot drift; other types are our own\n * so Node's Blob/Buffer/Headers are accepted and we avoid strict Workers-only types.\n */\nimport type { R2Range } from '@cloudflare/workers-types/2023-07-01/index.js'\n\nexport type { R2Range }\n\nexport interface R2GetOptions {\n [key: string]: any\n onlyIf?: any | Headers\n range?: R2Range\n}\n\nexport interface R2Bucket {\n createMultipartUpload(key: string, options?: any): Promise<R2MultipartUpload>\n delete(keys: string | string[]): Promise<void>\n get(key: string, options?: R2GetOptions): Promise<null | R2ObjectBody>\n head(key: string): Promise<null | R2Object>\n list(options?: any): Promise<any>\n put(\n key: string,\n value: ArrayBuffer | ArrayBufferView | Blob | null | ReadableStream | string,\n options?: any,\n ): Promise<any>\n resumeMultipartUpload(key: string, uploadId: string): R2MultipartUpload\n}\n\ninterface R2HTTPMetadata {\n cacheControl?: string\n cacheExpiry?: Date\n contentDisposition?: string\n contentEncoding?: string\n contentLanguage?: string\n contentType?: string\n}\n\nexport interface R2Object {\n readonly etag: string\n readonly httpMetadata?: R2HTTPMetadata\n readonly key: string\n readonly size: number\n writeHttpMetadata(headers: Headers): void\n}\n\nexport interface R2ObjectBody extends R2Object {\n get body(): ReadableStream\n}\n\nexport interface R2MultipartUpload {\n abort(): Promise<void>\n complete(uploadedParts: R2UploadedPart[]): Promise<R2Object>\n readonly key: string\n readonly uploadId: string\n uploadPart(\n partNumber: number,\n value: (ArrayBuffer | ArrayBufferView) | Blob | ReadableStream | string,\n options?: any,\n ): Promise<R2UploadedPart>\n}\n\nexport interface R2UploadedPart {\n etag: string\n partNumber: number\n}\n\nexport interface R2StorageClientUploadContext {\n key: string\n prefix: string\n}\nexport type R2StorageClientUploadHandlerParams = {\n chunkSize?: number\n}\n\nexport type R2StorageMultipartUploadHandlerParams = {\n collection: string\n docPrefix?: string\n fileName: string\n fileType: string\n multipartId?: string\n multipartKey?: string\n multipartNumber?: string\n}\n"],"names":[],"mappings":"AAAA;;;;CAIC,GAuED,WAQC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/storage-r2",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.c2b57ce",
|
|
4
4
|
"description": "Payload storage adapter for Cloudflare R2",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,17 +37,17 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@payloadcms/plugin-cloud-storage": "4.0.0-internal.
|
|
40
|
+
"@payloadcms/plugin-cloud-storage": "4.0.0-internal.c2b57ce"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@cloudflare/workers-types": "4.20260218.0",
|
|
44
|
-
"payload": "4.0.0-internal.
|
|
44
|
+
"payload": "4.0.0-internal.c2b57ce"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"payload": "4.0.0-internal.
|
|
47
|
+
"payload": "4.0.0-internal.c2b57ce"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
|
-
"node": "
|
|
50
|
+
"node": ">=24.15.0"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
53
53
|
"build": "pnpm build:types && pnpm build:swc",
|