@payloadcms/plugin-cloud-storage 4.0.0-internal.8001944 → 4.0.0-internal.8089ef7

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.
Files changed (46) hide show
  1. package/dist/fields/getFields.d.ts.map +1 -1
  2. package/dist/fields/getFields.js +73 -8
  3. package/dist/fields/getFields.js.map +1 -1
  4. package/dist/hooks/afterChange.d.ts +3 -1
  5. package/dist/hooks/afterChange.d.ts.map +1 -1
  6. package/dist/hooks/afterChange.js +64 -6
  7. package/dist/hooks/afterChange.js.map +1 -1
  8. package/dist/hooks/afterDelete.d.ts.map +1 -1
  9. package/dist/hooks/afterDelete.js +10 -2
  10. package/dist/hooks/afterDelete.js.map +1 -1
  11. package/dist/hooks/afterRead.d.ts +6 -1
  12. package/dist/hooks/afterRead.d.ts.map +1 -1
  13. package/dist/hooks/afterRead.js +20 -6
  14. package/dist/hooks/afterRead.js.map +1 -1
  15. package/dist/hooks/beforeChange.d.ts +2 -1
  16. package/dist/hooks/beforeChange.d.ts.map +1 -1
  17. package/dist/hooks/beforeChange.js +7 -4
  18. package/dist/hooks/beforeChange.js.map +1 -1
  19. package/dist/hooks/publicOriginalURL.d.ts +8 -0
  20. package/dist/hooks/publicOriginalURL.d.ts.map +1 -0
  21. package/dist/hooks/publicOriginalURL.js +34 -0
  22. package/dist/hooks/publicOriginalURL.js.map +1 -0
  23. package/dist/plugin.d.ts.map +1 -1
  24. package/dist/plugin.js +29 -4
  25. package/dist/plugin.js.map +1 -1
  26. package/dist/types.d.ts +26 -1
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/types.js.map +1 -1
  29. package/dist/utilities/createFileOperations.d.ts +13 -0
  30. package/dist/utilities/createFileOperations.d.ts.map +1 -0
  31. package/dist/utilities/createFileOperations.js +258 -0
  32. package/dist/utilities/createFileOperations.js.map +1 -0
  33. package/dist/utilities/getFilePrefix.d.ts +2 -5
  34. package/dist/utilities/getFilePrefix.d.ts.map +1 -1
  35. package/dist/utilities/getFilePrefix.js +25 -10
  36. package/dist/utilities/getFilePrefix.js.map +1 -1
  37. package/dist/utilities/getIncomingFiles.js +2 -2
  38. package/dist/utilities/getIncomingFiles.js.map +1 -1
  39. package/dist/utilities/getStorageLocationSelect.d.ts +9 -0
  40. package/dist/utilities/getStorageLocationSelect.d.ts.map +1 -0
  41. package/dist/utilities/getStorageLocationSelect.js +54 -0
  42. package/dist/utilities/getStorageLocationSelect.js.map +1 -0
  43. package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
  44. package/dist/utilities/resolveSignedURLKey.js +15 -7
  45. package/dist/utilities/resolveSignedURLKey.js.map +1 -1
  46. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload';
1
+ import type { CollectionConfig, FileData, PayloadRequest, TypeWithID } from 'payload';
2
2
  /**
3
3
  * Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).
4
4
  *
@@ -11,10 +11,7 @@ import type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload';
11
11
  export declare function getFilePrefix({ collection, collectionPrefix, doc, filename, prefixQueryParam, req, uploadReference, useCompositePrefixes, }: {
12
12
  collection: CollectionConfig;
13
13
  collectionPrefix?: string;
14
- doc?: {
15
- _objectKey?: string;
16
- prefix?: string;
17
- } & TypeWithID;
14
+ doc?: Partial<FileData> & TypeWithID;
18
15
  filename: string;
19
16
  /**
20
17
  * Only narrows the access-controlled fallback lookup below; never trusted or
@@ -1 +1 @@
1
- {"version":3,"file":"getFilePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/getFilePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAA;AAMzF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,UAAU,EACV,gBAAgB,EAChB,GAAG,EACH,QAAQ,EACR,gBAAgB,EAChB,GAAG,EACH,eAAe,EACf,oBAA4B,GAC7B,EAAE;IACD,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU,CAAA;IAC3D,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,CAqElB"}
1
+ {"version":3,"file":"getFilePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/getFilePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,cAAc,EAEd,UAAU,EACX,MAAM,SAAS,CAAA;AAMhB;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,UAAU,EACV,gBAAgB,EAChB,GAAG,EACH,QAAQ,EACR,gBAAgB,EAChB,GAAG,EACH,eAAe,EACf,oBAA4B,GAC7B,EAAE;IACD,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAA;IACpC,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,CA2ElB"}
@@ -13,9 +13,9 @@ import { sanitizePrefix } from './sanitizePrefix.js';
13
13
  // The serve path already loaded and authorized this document — trust it over any
14
14
  // client-supplied upload reference or query prefix.
15
15
  if (doc) {
16
- return buildPrefixWithObjectKey({
17
- objectKey: doc._objectKey,
18
- prefix: doc.prefix
16
+ return getRepresentationPrefix({
17
+ doc,
18
+ filename
19
19
  });
20
20
  }
21
21
  // Upload instructions call handlers without a document yet. Re-contain the claimed
@@ -34,7 +34,7 @@ import { sanitizePrefix } from './sanitizePrefix.js';
34
34
  });
35
35
  }
36
36
  // Reads without a query prefix or read-access constraints skip the endpoint's document lookup.
37
- const imageSizes = collection?.upload?.imageSizes || [];
37
+ const variants = collection?.upload?.variants || [];
38
38
  const filenameClause = {
39
39
  or: [
40
40
  {
@@ -42,8 +42,13 @@ import { sanitizePrefix } from './sanitizePrefix.js';
42
42
  equals: filename
43
43
  }
44
44
  },
45
- ...imageSizes.map((imageSize)=>({
46
- [`sizes.${imageSize.name}.filename`]: {
45
+ {
46
+ 'original.filename': {
47
+ equals: filename
48
+ }
49
+ },
50
+ ...variants.map((imageSize)=>({
51
+ [`variants.${imageSize.name}.filename`]: {
47
52
  equals: filename
48
53
  }
49
54
  }))
@@ -71,16 +76,26 @@ import { sanitizePrefix } from './sanitizePrefix.js';
71
76
  req,
72
77
  select: {
73
78
  _objectKey: true,
74
- prefix: true
79
+ filename: true,
80
+ original: true,
81
+ prefix: true,
82
+ variants: true
75
83
  },
76
84
  showHiddenFields: true,
77
85
  where
78
86
  });
79
87
  const found = files?.docs?.[0];
88
+ return found ? getRepresentationPrefix({
89
+ doc: found,
90
+ filename
91
+ }) : '';
92
+ }
93
+ const getRepresentationPrefix = ({ doc, filename })=>{
94
+ const representation = doc.original?.filename === filename ? doc.original : Object.values(doc.variants ?? {}).find((variant)=>variant?.filename === filename) ?? doc;
80
95
  return buildPrefixWithObjectKey({
81
- objectKey: found?._objectKey,
82
- prefix: found?.prefix
96
+ objectKey: representation._objectKey ?? (!doc.original?.filename ? doc._objectKey : undefined),
97
+ prefix: representation.prefix ?? (!doc.original?.filename ? doc.prefix : undefined)
83
98
  });
84
- }
99
+ };
85
100
 
86
101
  //# sourceMappingURL=getFilePrefix.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getFilePrefix.ts"],"sourcesContent":["import type { CollectionConfig, PayloadRequest, TypeWithID, UploadConfig } from 'payload'\n\nimport { buildPrefixWithObjectKey } from './buildPrefixWithObjectKey.js'\nimport { buildUploadStoragePathData } from './buildStoragePathData.js'\nimport { sanitizePrefix } from './sanitizePrefix.js'\n\n/**\n * Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).\n *\n * An already-authorized `doc` wins outright. Otherwise an `uploadReference` is used (its\n * `prefix` re-contained with {@link buildUploadStoragePathData}, since it hasn't been verified against\n * a signed receipt by every adapter). Otherwise the document is resolved with\n * `overrideAccess: false`, any query-param prefix only narrows that lookup, and `_objectKey`\n * is read from the resolved document via `showHiddenFields`.\n */\nexport async function getFilePrefix({\n collection,\n collectionPrefix,\n doc,\n filename,\n prefixQueryParam,\n req,\n uploadReference,\n useCompositePrefixes = false,\n}: {\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: { _objectKey?: string; prefix?: string } & TypeWithID\n filename: string\n /**\n * Only narrows the access-controlled fallback lookup below; never trusted or\n * returned directly. Prefer passing the access-checked document as `doc` instead.\n */\n prefixQueryParam?: string\n req: PayloadRequest\n uploadReference?: unknown\n useCompositePrefixes?: boolean\n}): Promise<string> {\n // The serve path already loaded and authorized this document — trust it over any\n // client-supplied upload reference or query prefix.\n if (doc) {\n return buildPrefixWithObjectKey({ objectKey: doc._objectKey, prefix: doc.prefix })\n }\n\n // Upload instructions call handlers without a document yet. Re-contain the claimed\n // prefix — it hasn't been verified against a signed receipt by every adapter.\n if (\n uploadReference &&\n typeof uploadReference === 'object' &&\n 'prefix' in uploadReference &&\n typeof uploadReference.prefix === 'string'\n ) {\n const referenceObjectKey =\n '_objectKey' in uploadReference\n ? (uploadReference as { _objectKey?: string })._objectKey\n : undefined\n const containedPrefix = buildUploadStoragePathData({\n collectionPrefix,\n docPrefix: uploadReference.prefix,\n filename,\n useCompositePrefixes,\n }).sanitizedDocPrefix\n return buildPrefixWithObjectKey({ objectKey: referenceObjectKey, prefix: containedPrefix })\n }\n\n // Reads without a query prefix or read-access constraints skip the endpoint's document lookup.\n const imageSizes = (collection?.upload as UploadConfig)?.imageSizes || []\n\n const filenameClause = {\n or: [\n {\n filename: { equals: filename },\n },\n ...imageSizes.map((imageSize) => ({\n [`sizes.${imageSize.name}.filename`]: { equals: filename },\n })),\n ],\n }\n\n // Only filter by prefix when the collection persists a `prefix` field (querying a missing field throws).\n const hasPrefixField = collection.fields?.some(\n (field) => 'name' in field && field.name === 'prefix',\n )\n const where =\n typeof prefixQueryParam === 'string' && hasPrefixField\n ? { and: [filenameClause, { prefix: { equals: sanitizePrefix(prefixQueryParam) } }] }\n : filenameClause\n\n const files = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n select: {\n _objectKey: true,\n prefix: true,\n },\n showHiddenFields: true,\n where,\n })\n\n const found = files?.docs?.[0] as { _objectKey?: string; prefix?: string } | undefined\n return buildPrefixWithObjectKey({ objectKey: found?._objectKey, prefix: found?.prefix })\n}\n"],"names":["buildPrefixWithObjectKey","buildUploadStoragePathData","sanitizePrefix","getFilePrefix","collection","collectionPrefix","doc","filename","prefixQueryParam","req","uploadReference","useCompositePrefixes","objectKey","_objectKey","prefix","referenceObjectKey","undefined","containedPrefix","docPrefix","sanitizedDocPrefix","imageSizes","upload","filenameClause","or","equals","map","imageSize","name","hasPrefixField","fields","some","field","where","and","files","payload","find","slug","depth","draft","limit","overrideAccess","pagination","select","showHiddenFields","found","docs"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,0BAA0B,QAAQ,4BAA2B;AACtE,SAASC,cAAc,QAAQ,sBAAqB;AAEpD;;;;;;;;CAQC,GACD,OAAO,eAAeC,cAAc,EA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I0B,OAAO,CAACC,IAAI,CAAC;QACnChC,YAAYA,WAAWiC,IAAI;QAC3BC,OAAO;QACPC,OAAO;QACPC,OAAO;QACPC,gBAAgB;QAChBC,YAAY;QACZjC;QACAkC,QAAQ;YACN9B,YAAY;YACZC,QAAQ;QACV;QACA8B,kBAAkB;QAClBZ;IACF;IAEA,MAAMa,QAAQX,OAAOY,MAAM,CAAC,EAAE;IAC9B,OAAO9C,yBAAyB;QAAEY,WAAWiC,OAAOhC;QAAYC,QAAQ+B,OAAO/B;IAAO;AACxF"}
1
+ {"version":3,"sources":["../../src/utilities/getFilePrefix.ts"],"sourcesContent":["import type {\n CollectionConfig,\n FileData,\n PayloadRequest,\n SanitizedUploadConfig,\n TypeWithID,\n} from 'payload'\n\nimport { buildPrefixWithObjectKey } from './buildPrefixWithObjectKey.js'\nimport { buildUploadStoragePathData } from './buildStoragePathData.js'\nimport { sanitizePrefix } from './sanitizePrefix.js'\n\n/**\n * Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).\n *\n * An already-authorized `doc` wins outright. Otherwise an `uploadReference` is used (its\n * `prefix` re-contained with {@link buildUploadStoragePathData}, since it hasn't been verified against\n * a signed receipt by every adapter). Otherwise the document is resolved with\n * `overrideAccess: false`, any query-param prefix only narrows that lookup, and `_objectKey`\n * is read from the resolved document via `showHiddenFields`.\n */\nexport async function getFilePrefix({\n collection,\n collectionPrefix,\n doc,\n filename,\n prefixQueryParam,\n req,\n uploadReference,\n useCompositePrefixes = false,\n}: {\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: Partial<FileData> & TypeWithID\n filename: string\n /**\n * Only narrows the access-controlled fallback lookup below; never trusted or\n * returned directly. Prefer passing the access-checked document as `doc` instead.\n */\n prefixQueryParam?: string\n req: PayloadRequest\n uploadReference?: unknown\n useCompositePrefixes?: boolean\n}): Promise<string> {\n // The serve path already loaded and authorized this document — trust it over any\n // client-supplied upload reference or query prefix.\n if (doc) {\n return getRepresentationPrefix({ doc, filename })\n }\n\n // Upload instructions call handlers without a document yet. Re-contain the claimed\n // prefix — it hasn't been verified against a signed receipt by every adapter.\n if (\n uploadReference &&\n typeof uploadReference === 'object' &&\n 'prefix' in uploadReference &&\n typeof uploadReference.prefix === 'string'\n ) {\n const referenceObjectKey =\n '_objectKey' in uploadReference\n ? (uploadReference as { _objectKey?: string })._objectKey\n : undefined\n const containedPrefix = buildUploadStoragePathData({\n collectionPrefix,\n docPrefix: uploadReference.prefix,\n filename,\n useCompositePrefixes,\n }).sanitizedDocPrefix\n return buildPrefixWithObjectKey({ objectKey: referenceObjectKey, prefix: containedPrefix })\n }\n\n // Reads without a query prefix or read-access constraints skip the endpoint's document lookup.\n const variants = (collection?.upload as SanitizedUploadConfig)?.variants || []\n\n const filenameClause = {\n or: [\n {\n filename: { equals: filename },\n },\n { 'original.filename': { equals: filename } },\n ...variants.map((imageSize) => ({\n [`variants.${imageSize.name}.filename`]: { equals: filename },\n })),\n ],\n }\n\n // Only filter by prefix when the collection persists a `prefix` field (querying a missing field throws).\n const hasPrefixField = collection.fields?.some(\n (field) => 'name' in field && field.name === 'prefix',\n )\n const where =\n typeof prefixQueryParam === 'string' && hasPrefixField\n ? { and: [filenameClause, { prefix: { equals: sanitizePrefix(prefixQueryParam) } }] }\n : filenameClause\n\n const files = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n select: {\n _objectKey: true,\n filename: true,\n original: true,\n prefix: true,\n variants: true,\n },\n showHiddenFields: true,\n where,\n })\n\n const found = files?.docs?.[0] as\n | ({ _objectKey?: string; prefix?: string } & Partial<FileData>)\n | undefined\n return found ? getRepresentationPrefix({ doc: found, filename }) : ''\n}\n\nconst getRepresentationPrefix = ({\n doc,\n filename,\n}: {\n doc: Partial<FileData>\n filename: string\n}): string => {\n const representation =\n doc.original?.filename === filename\n ? doc.original\n : (Object.values(doc.variants ?? {}).find((variant) => variant?.filename === filename) ?? doc)\n return buildPrefixWithObjectKey({\n objectKey: representation._objectKey ?? (!doc.original?.filename ? doc._objectKey : undefined),\n prefix: representation.prefix ?? (!doc.original?.filename ? doc.prefix : undefined),\n })\n}\n"],"names":["buildPrefixWithObjectKey","buildUploadStoragePathData","sanitizePrefix","getFilePrefix","collection","collectionPrefix","doc","filename","prefixQueryParam","req","uploadReference","useCompositePrefixes","getRepresentationPrefix","prefix","referenceObjectKey","_objectKey","undefined","containedPrefix","docPrefix","sanitizedDocPrefix","objectKey","variants","upload","filenameClause","or","equals","map","imageSize","name","hasPrefixField","fields","some","field","where","and","files","payload","find","slug","depth","draft","limit","overrideAccess","pagination","select","original","showHiddenFields","found","docs","representation","Object","values","variant"],"mappings":"AAQA,SAASA,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,0BAA0B,QAAQ,4BAA2B;AACtE,SAASC,cAAc,QAAQ,sBAAqB;AAEpD;;;;;;;;CAQC,GACD,OAAO,eAAeC,cAAc,EAClCC,UAAU,EACVC,gBAAgB,EAChBC,GAAG,EACHC,QAAQ,EACRC,gBAAgB,EAChBC,GAAG,EACHC,eAAe,EACfC,uBAAuB,KAAK,EAc7B;IACC,iFAAiF;IACjF,oDAAoD;IACpD,IAAIL,KAAK;QACP,OAAOM,wBAAwB;YAAEN;YAAKC;QAAS;IACjD;IAEA,mFAAmF;IACnF,8EAA8E;IAC9E,IACEG,mBACA,OAAOA,oBAAoB,YAC3B,YAAYA,mBACZ,OAAOA,gBAAgBG,MAAM,KAAK,UAClC;QACA,MAAMC,qBACJ,gBAAgBJ,kBACZ,AAACA,gBAA4CK,UAAU,GACvDC;QACN,MAAMC,kBAAkBhB,2BAA2B;YACjDI;YACAa,WAAWR,gBAAgBG,MAAM;YACjCN;YACAI;QACF,GAAGQ,kBAAkB;QACrB,OAAOnB,yBAAyB;YAAEoB,WAAWN;YAAoBD,QAAQI;QAAgB;IAC3F;IAEA,+FAA+F;IAC/F,MAAMI,WAAW,AAACjB,YAAYkB,QAAkCD,YAAY,EAAE;IAE9E,M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B;QAC9BoB,WAAW6B,eAAelC,UAAU,IAAK,CAAA,CAACT,IAAIuC,QAAQ,EAAEtC,WAAWD,IAAIS,UAAU,GAAGC,SAAQ;QAC5FH,QAAQoC,eAAepC,MAAM,IAAK,CAAA,CAACP,IAAIuC,QAAQ,EAAEtC,WAAWD,IAAIO,MAAM,GAAGG,SAAQ;IACnF;AACF"}
@@ -16,8 +16,8 @@ export function getIncomingFiles({ data, req }) {
16
16
  files = [
17
17
  mainFile
18
18
  ];
19
- if (data?.sizes) {
20
- Object.entries(data.sizes).forEach(([key, resizedFileData])=>{
19
+ if (data?.variants) {
20
+ Object.entries(data.variants).forEach(([key, resizedFileData])=>{
21
21
  if (payloadUploadSizes?.[key] && resizedFileData.mimeType) {
22
22
  files = files.concat([
23
23
  {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getIncomingFiles.ts"],"sourcesContent":["import type { FileData, PayloadRequest } from 'payload'\n\nimport type { File } from '../types.js'\n\ninterface CloudStorageContext {\n file: PayloadRequest['file']\n uploadSizes: PayloadRequest['payloadUploadSizes']\n}\n\nexport function getIncomingFiles({\n data,\n req,\n}: {\n data: Partial<FileData>\n req: PayloadRequest\n}): File[] {\n // Fall back to context if req.file was cleared\n const ctx = req.context?._payloadCloudStorage as CloudStorageContext | undefined\n const file = req.file ?? ctx?.file\n const payloadUploadSizes = req.payloadUploadSizes ?? ctx?.uploadSizes\n\n let files: File[] = []\n\n if (file && data.filename && data.mimeType) {\n const mainFile: File = {\n buffer: file.data,\n filename: data.filename,\n filesize: file.size,\n mimeType: data.mimeType,\n tempFilePath: file.tempFilePath,\n uploadReference: file.uploadReference,\n }\n\n files = [mainFile]\n\n if (data?.sizes) {\n Object.entries(data.sizes).forEach(([key, resizedFileData]) => {\n if (payloadUploadSizes?.[key] && resizedFileData.mimeType) {\n files = files.concat([\n {\n buffer: payloadUploadSizes[key],\n filename: `${resizedFileData.filename}`,\n filesize: payloadUploadSizes[key].length,\n mimeType: resizedFileData.mimeType,\n },\n ])\n }\n })\n }\n }\n\n return files\n}\n"],"names":["getIncomingFiles","data","req","ctx","context","_payloadCloudStorage","file","payloadUploadSizes","uploadSizes","files","filename","mimeType","mainFile","buffer","filesize","size","tempFilePath","uploadReference","sizes","Object","entries","forEach","key","resizedFileData","concat","length"],"mappings":"AASA,OAAO,SAASA,iBAAiB,EAC/BC,IAAI,EACJC,GAAG,EAIJ;IACC,+CAA+C;IAC/C,MAAMC,MAAMD,IAAIE,OAAO,EAAEC;IACzB,MAAMC,OAAOJ,IAAII,IAAI,IAAIH,KAAKG;IAC9B,MAAMC,qBAAqBL,IAAIK,kBAAkB,IAAIJ,KAAKK;IAE1D,IAAIC,QAAgB,EAAE;IAEtB,IAAIH,QAAQL,KAAKS,QAAQ,IAAIT,KAAKU,QAAQ,EAAE;QAC1C,MAAMC,WAAiB;YACrBC,QAAQP,KAAKL,IAAI;YACjBS,UAAUT,KAAKS,QAAQ;YACvBI,UAAUR,KAAKS,IAAI;YACnBJ,UAAUV,KAAKU,QAAQ;YACvBK,cAAcV,KAAKU,YAAY;YAC/BC,iBAAiBX,KAAKW,eAAe;QACvC;QAEAR,QAAQ;YAACG;SAAS;QAElB,IAAIX,MAAMiB,OAAO;YACfC,OAAOC,OAAO,CAACnB,KAAKiB,KAAK,EAAEG,OAAO,CAAC,CAAC,CAACC,KAAKC,gBAAgB;gBACxD,IAAIhB,oBAAoB,CAACe,IAAI,IAAIC,gBAAgBZ,QAAQ,EAAE;oBACzDF,QAAQA,MAAMe,MAAM,CAAC;wBACnB;4BACEX,QAAQN,kBAAkB,CAACe,IAAI;4BAC/BZ,UAAU,GAAGa,gBAAgBb,QAAQ,EAAE;4BACvCI,UAAUP,kBAAkB,CAACe,IAAI,CAACG,MAAM;4BACxCd,UAAUY,gBAAgBZ,QAAQ;wBACpC;qBACD;gBACH;YACF;QACF;IACF;IAEA,OAAOF;AACT"}
1
+ {"version":3,"sources":["../../src/utilities/getIncomingFiles.ts"],"sourcesContent":["import type { FileData, PayloadRequest } from 'payload'\n\nimport type { File } from '../types.js'\n\ninterface CloudStorageContext {\n file: PayloadRequest['file']\n uploadSizes: PayloadRequest['payloadUploadSizes']\n}\n\nexport function getIncomingFiles({\n data,\n req,\n}: {\n data: Partial<FileData>\n req: PayloadRequest\n}): File[] {\n // Fall back to context if req.file was cleared\n const ctx = req.context?._payloadCloudStorage as CloudStorageContext | undefined\n const file = req.file ?? ctx?.file\n const payloadUploadSizes = req.payloadUploadSizes ?? ctx?.uploadSizes\n\n let files: File[] = []\n\n if (file && data.filename && data.mimeType) {\n const mainFile: File = {\n buffer: file.data,\n filename: data.filename,\n filesize: file.size,\n mimeType: data.mimeType,\n tempFilePath: file.tempFilePath,\n uploadReference: file.uploadReference,\n }\n\n files = [mainFile]\n\n if (data?.variants) {\n Object.entries(data.variants).forEach(([key, resizedFileData]) => {\n if (payloadUploadSizes?.[key] && resizedFileData.mimeType) {\n files = files.concat([\n {\n buffer: payloadUploadSizes[key],\n filename: `${resizedFileData.filename}`,\n filesize: payloadUploadSizes[key].length,\n mimeType: resizedFileData.mimeType,\n },\n ])\n }\n })\n }\n }\n\n return files\n}\n"],"names":["getIncomingFiles","data","req","ctx","context","_payloadCloudStorage","file","payloadUploadSizes","uploadSizes","files","filename","mimeType","mainFile","buffer","filesize","size","tempFilePath","uploadReference","variants","Object","entries","forEach","key","resizedFileData","concat","length"],"mappings":"AASA,OAAO,SAASA,iBAAiB,EAC/BC,IAAI,EACJC,GAAG,EAIJ;IACC,+CAA+C;IAC/C,MAAMC,MAAMD,IAAIE,OAAO,EAAEC;IACzB,MAAMC,OAAOJ,IAAII,IAAI,IAAIH,KAAKG;IAC9B,MAAMC,qBAAqBL,IAAIK,kBAAkB,IAAIJ,KAAKK;IAE1D,IAAIC,QAAgB,EAAE;IAEtB,IAAIH,QAAQL,KAAKS,QAAQ,IAAIT,KAAKU,QAAQ,EAAE;QAC1C,MAAMC,WAAiB;YACrBC,QAAQP,KAAKL,IAAI;YACjBS,UAAUT,KAAKS,QAAQ;YACvBI,UAAUR,KAAKS,IAAI;YACnBJ,UAAUV,KAAKU,QAAQ;YACvBK,cAAcV,KAAKU,YAAY;YAC/BC,iBAAiBX,KAAKW,eAAe;QACvC;QAEAR,QAAQ;YAACG;SAAS;QAElB,IAAIX,MAAMiB,UAAU;YAClBC,OAAOC,OAAO,CAACnB,KAAKiB,QAAQ,EAAEG,OAAO,CAAC,CAAC,CAACC,KAAKC,gBAAgB;gBAC3D,IAAIhB,oBAAoB,CAACe,IAAI,IAAIC,gBAAgBZ,QAAQ,EAAE;oBACzDF,QAAQA,MAAMe,MAAM,CAAC;wBACnB;4BACEX,QAAQN,kBAAkB,CAACe,IAAI;4BAC/BZ,UAAU,GAAGa,gBAAgBb,QAAQ,EAAE;4BACvCI,UAAUP,kBAAkB,CAACe,IAAI,CAACG,MAAM;4BACxCd,UAAUY,gBAAgBZ,QAAQ;wBACpC;qBACD;gBACH;YACF;QACF;IACF;IAEA,OAAOF;AACT"}
@@ -0,0 +1,9 @@
1
+ import type { CollectionConfig } from 'payload';
2
+ /**
3
+ * URL hooks rebuild direct URLs from each representation's stored location, so a positive
4
+ * selection of a URL must also read the fields that location is built from.
5
+ */
6
+ export declare const getStorageLocationSelect: ({ select: existingSelect, }: {
7
+ select: CollectionConfig['select'];
8
+ }) => NonNullable<CollectionConfig['select']>;
9
+ //# sourceMappingURL=getStorageLocationSelect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStorageLocationSelect.d.ts","sourceRoot":"","sources":["../../src/utilities/getStorageLocationSelect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,SAAS,CAAA;AAQ3D;;;GAGG;AACH,eAAO,MAAM,wBAAwB,gCAGhC;IACD,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAA;CACnC,KAAG,WAAW,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CASzC,CAAA"}
@@ -0,0 +1,54 @@
1
+ import { getSelectMode } from 'payload/shared';
2
+ const locationFieldNames = [
3
+ 'filename',
4
+ 'prefix',
5
+ '_objectKey'
6
+ ];
7
+ /**
8
+ * URL hooks rebuild direct URLs from each representation's stored location, so a positive
9
+ * selection of a URL must also read the fields that location is built from.
10
+ */ export const getStorageLocationSelect = ({ select: existingSelect })=>(args)=>{
11
+ const select = existingSelect?.(args) ?? args.select;
12
+ if (!select || getSelectMode(select) === 'exclude') {
13
+ return select;
14
+ }
15
+ return withLocationFields({
16
+ select
17
+ });
18
+ };
19
+ const withLocationFields = ({ select })=>{
20
+ const result = addLocationFields({
21
+ representation: {
22
+ ...select
23
+ }
24
+ });
25
+ if (isSelectRecord(result.original)) {
26
+ result.original = addLocationFields({
27
+ representation: {
28
+ ...result.original
29
+ }
30
+ });
31
+ }
32
+ if (isSelectRecord(result.variants)) {
33
+ result.variants = Object.fromEntries(Object.entries(result.variants).map(([name, variant])=>[
34
+ name,
35
+ isSelectRecord(variant) ? addLocationFields({
36
+ representation: {
37
+ ...variant
38
+ }
39
+ }) : variant
40
+ ]));
41
+ }
42
+ return result;
43
+ };
44
+ const addLocationFields = ({ representation })=>{
45
+ if (representation.url === true) {
46
+ for (const fieldName of locationFieldNames){
47
+ representation[fieldName] = true;
48
+ }
49
+ }
50
+ return representation;
51
+ };
52
+ const isSelectRecord = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
53
+
54
+ //# sourceMappingURL=getStorageLocationSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/getStorageLocationSelect.ts"],"sourcesContent":["import type { CollectionConfig, SelectType } from 'payload'\n\nimport { getSelectMode } from 'payload/shared'\n\ntype SelectRecord = Record<string, unknown>\n\nconst locationFieldNames = ['filename', 'prefix', '_objectKey'] as const\n\n/**\n * URL hooks rebuild direct URLs from each representation's stored location, so a positive\n * selection of a URL must also read the fields that location is built from.\n */\nexport const getStorageLocationSelect =\n ({\n select: existingSelect,\n }: {\n select: CollectionConfig['select']\n }): NonNullable<CollectionConfig['select']> =>\n (args) => {\n const select = existingSelect?.(args) ?? args.select\n\n if (!select || getSelectMode(select) === 'exclude') {\n return select\n }\n\n return withLocationFields({ select })\n }\n\nconst withLocationFields = ({ select }: { select: SelectType }): SelectType => {\n const result = addLocationFields({ representation: { ...select } })\n\n if (isSelectRecord(result.original)) {\n result.original = addLocationFields({ representation: { ...result.original } })\n }\n\n if (isSelectRecord(result.variants)) {\n result.variants = Object.fromEntries(\n Object.entries(result.variants).map(([name, variant]) => [\n name,\n isSelectRecord(variant) ? addLocationFields({ representation: { ...variant } }) : variant,\n ]),\n )\n }\n\n return result as SelectType\n}\n\nconst addLocationFields = ({ representation }: { representation: SelectRecord }): SelectRecord => {\n if (representation.url === true) {\n for (const fieldName of locationFieldNames) {\n representation[fieldName] = true\n }\n }\n\n return representation\n}\n\nconst isSelectRecord = (value: unknown): value is SelectRecord =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n"],"names":["getSelectMode","locationFieldNames","getStorageLocationSelect","select","existingSelect","args","withLocationFields","result","addLocationFields","representation","isSelectRecord","original","variants","Object","fromEntries","entries","map","name","variant","url","fieldName","value","Array","isArray"],"mappings":"AAEA,SAASA,aAAa,QAAQ,iBAAgB;AAI9C,MAAMC,qBAAqB;IAAC;IAAY;IAAU;CAAa;AAE/D;;;CAGC,GACD,OAAO,MAAMC,2BACX,CAAC,EACCC,QAAQC,cAAc,EAGvB,GACD,CAACC;QACC,MAAMF,SAASC,iBAAiBC,SAASA,KAAKF,MAAM;QAEpD,IAAI,CAACA,UAAUH,cAAcG,YAAY,WAAW;YAClD,OAAOA;QACT;QAEA,OAAOG,mBAAmB;YAAEH;QAAO;IACrC,EAAC;AAEH,MAAMG,qBAAqB,CAAC,EAAEH,MAAM,EAA0B;IAC5D,MAAMI,SAASC,kBAAkB;QAAEC,gBAAgB;YAAE,GAAGN,MAAM;QAAC;IAAE;IAEjE,IAAIO,eAAeH,OAAOI,QAAQ,GAAG;QACnCJ,OAAOI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AAQ,EACR,GAAG,EACH,oBAA4B,GAC7B,EAAE,IAAI,GAAG,OAAO,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,EAAE,MAAM,CAAA;IACzB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,eAAe,CAAA;CACjC,CAAC,CAyCD"}
1
+ {"version":3,"file":"resolveSignedURLKey.d.ts","sourceRoot":"","sources":["../../src/utilities/resolveSignedURLKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAW7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAIlD,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;IACnB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,gBAAqB,EACrB,cAAc,EACd,SAAS,EACT,QAAQ,EACR,GAAG,EACH,oBAA4B,GAC7B,EAAE,IAAI,GAAG,OAAO,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,EAAE,MAAM,CAAA;IACzB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,eAAe,CAAA;CACjC,CAAC,CA6CD"}
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { createClientUploadReceipt, getSafeFileName } from 'payload/internal';
2
+ import { createClientUploadReceipt, getOriginalFilename, getSafeFileName, incrementName } from 'payload/internal';
3
3
  import { getSanitizedUploadFilename } from 'payload/shared';
4
4
  import { buildUploadPrefix, buildUploadStoragePathData } from './buildStoragePathData.js';
5
5
  /**
@@ -19,13 +19,21 @@ import { buildUploadPrefix, buildUploadStoragePathData } from './buildStoragePat
19
19
  * key with {@link buildUploadStoragePathData}, so the receipt only ever signs a key
20
20
  * beneath the configured collection prefix.
21
21
  */ export async function resolveSignedURLKey({ collectionPrefix = '', collectionSlug, docPrefix, filename, req, useCompositePrefixes = false }) {
22
- // Sanitize with the same helper generateFileData uses for the DB filename so the storage key
23
- // and doc.filename stay in sync (#16694).
24
- const sanitizedFilename = await getSafeFileName({
22
+ // The document stores the -original name, so check collisions against that name.
23
+ let sanitizedFilename = getSanitizedUploadFilename(filename);
24
+ let originalFilename = getOriginalFilename({
25
+ filename: sanitizedFilename
26
+ });
27
+ while(await getSafeFileName({
25
28
  collectionSlug,
26
- desiredFilename: getSanitizedUploadFilename(filename),
29
+ desiredFilename: originalFilename,
27
30
  req
28
- });
31
+ }) !== originalFilename){
32
+ sanitizedFilename = incrementName(sanitizedFilename);
33
+ originalFilename = getOriginalFilename({
34
+ filename: sanitizedFilename
35
+ });
36
+ }
29
37
  const rawBaseDocPrefix = useCompositePrefixes ? docPrefix : docPrefix || collectionPrefix;
30
38
  const { sanitizedDocPrefix } = buildUploadPrefix({
31
39
  collectionPrefix,
@@ -38,7 +46,7 @@ import { buildUploadPrefix, buildUploadStoragePathData } from './buildStoragePat
38
46
  const { storageFilePath } = buildUploadStoragePathData({
39
47
  collectionPrefix,
40
48
  docPrefix: keyedDocPrefix,
41
- filename: sanitizedFilename,
49
+ filename: originalFilename,
42
50
  useCompositePrefixes
43
51
  });
44
52
  const uploadReference = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/resolveSignedURLKey.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { randomUUID } from 'node:crypto'\nimport { createClientUploadReceipt, getSafeFileName } from 'payload/internal'\nimport { getSanitizedUploadFilename } from 'payload/shared'\n\nimport type { UploadReference } from '../types.js'\n\nimport { buildUploadPrefix, buildUploadStoragePathData } from './buildStoragePathData.js'\n\ntype Args = {\n collectionPrefix?: string\n collectionSlug: string\n docPrefix?: string\n filename: string\n req: PayloadRequest\n useCompositePrefixes?: boolean\n}\n\n/**\n * Resolves the storage key for an upload-instructions request, deduping\n * the filename via {@link getSafeFileName} so a duplicate upload does not\n * overwrite an existing blob.\n *\n * A unique per-upload segment is included in the storage key so each issued\n * key is distinct. The stored `filename` stays clean and the semantic `prefix`\n * stays exactly what the collection configured — the per-upload entropy is\n * persisted separately in `_objectKey`.\n *\n * The resolved `sanitizedFilename` is returned so the browser-side handler\n * can update the form via `updateFilename`.\n *\n * The semantic prefix is resolved with {@link buildUploadPrefix} and the final\n * key with {@link buildUploadStoragePathData}, so the receipt only ever signs a key\n * beneath the configured collection prefix.\n */\nexport async function resolveSignedURLKey({\n collectionPrefix = '',\n collectionSlug,\n docPrefix,\n filename,\n req,\n useCompositePrefixes = false,\n}: Args): Promise<{\n sanitizedDocPrefix: string\n sanitizedFilename: string\n storageFilePath: string\n uploadReference: UploadReference\n}> {\n // Sanitize with the same helper generateFileData uses for the DB filename so the storage key\n // and doc.filename stay in sync (#16694).\n const sanitizedFilename = await getSafeFileName({\n collectionSlug,\n desiredFilename: getSanitizedUploadFilename(filename),\n req,\n })\n\n const rawBaseDocPrefix = useCompositePrefixes ? docPrefix : docPrefix || collectionPrefix\n const { sanitizedDocPrefix } = buildUploadPrefix({\n collectionPrefix,\n docPrefix: rawBaseDocPrefix,\n useCompositePrefixes,\n })\n\n const _objectKey = randomUUID()\n // Per-upload segment lives in the key; it is persisted in `_objectKey`, keeping `prefix` semantic.\n const keyedDocPrefix = sanitizedDocPrefix ? `${sanitizedDocPrefix}/${_objectKey}` : _objectKey\n\n const { storageFilePath } = buildUploadStoragePathData({\n collectionPrefix,\n docPrefix: keyedDocPrefix,\n filename: sanitizedFilename,\n useCompositePrefixes,\n })\n\n const uploadReference = {\n _objectKey,\n prefix: sanitizedDocPrefix,\n signedReceipt: createClientUploadReceipt({\n _objectKey,\n collectionSlug,\n filename: sanitizedFilename,\n filePrefix: sanitizedDocPrefix,\n req,\n storageFilePath,\n }),\n }\n\n return { sanitizedDocPrefix, sanitizedFilename, storageFilePath, uploadReference }\n}\n"],"names":["randomUUID","createClientUploadReceipt","getSafeFileName","getSanitizedUploadFilename","buildUploadPrefix","buildUploadStoragePathData","resolveSignedURLKey","collectionPrefix","collectionSlug","docPrefix","filename","req","useCompositePrefixes","sanitizedFilename","desiredFilename","rawBaseDocPrefix","sanitizedDocPrefix","_objectKey","keyedDocPrefix","storageFilePath","uploadReference","prefix","signedReceipt","filePrefix"],"mappings":"AAEA,SAASA,UAAU,QAAQ,cAAa;AACxC,SAASC,yBAAyB,EAAEC,eAAe,QAAQ,mBAAkB;AAC7E,SAASC,0BAA0B,QAAQ,iBAAgB;AAI3D,SAASC,iBAAiB,EAAEC,0BAA0B,QAAQ,4BAA2B;AAWzF;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,oBAAoB,EACxCC,mBAAmB,EAAE,EACrBC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,GAAG,EACHC,uBAAuB,KAAK,EACvB;IAML,6FAA6F;IAC7F,0CAA0C;IAC1C,MAAMC,oBAAoB,MAAMX,gBAAgB;QAC9CM;QACAM,iBAAiBX,2BAA2BO;QAC5CC;IACF;IAEA,MAAMI,mBAAmBH,uBAAuBH,YAAYA,aAAaF;IACzE,MAAM,EAAES,kBAAkB,EAAE,GAAGZ,kBAAkB;QAC/CG;QACAE,WAAWM;QACXH;IACF;IAEA,MAAMK,aAAajB;IACnB,mGAAmG;IACnG,MAAMkB,iBAAiBF,qBAAqB,GAAGA,mBAAmB,CAAC,EAAEC,YAAY,GAAGA;IAEpF,MAAM,EAAEE,eAAe,EAAE,GAAGd,2BAA2B;QACrDE;QACAE,WAAWS;QACXR,UAAUG;QACVD;IACF;IAEA,MAAMQ,kBAAkB;QACtBH;QACAI,QAAQL;QACRM,eAAerB,0BAA0B;YACvCgB;YACAT;YACAE,UAAUG;YACVU,YAAYP;YACZL;YACAQ;QACF;IACF;IAEA,OAAO;QAAEH;QAAoBH;QAAmBM;QAAiBC;IAAgB;AACnF"}
1
+ {"version":3,"sources":["../../src/utilities/resolveSignedURLKey.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { randomUUID } from 'node:crypto'\nimport {\n createClientUploadReceipt,\n getOriginalFilename,\n getSafeFileName,\n incrementName,\n} from 'payload/internal'\nimport { getSanitizedUploadFilename } from 'payload/shared'\n\nimport type { UploadReference } from '../types.js'\n\nimport { buildUploadPrefix, buildUploadStoragePathData } from './buildStoragePathData.js'\n\ntype Args = {\n collectionPrefix?: string\n collectionSlug: string\n docPrefix?: string\n filename: string\n req: PayloadRequest\n useCompositePrefixes?: boolean\n}\n\n/**\n * Resolves the storage key for an upload-instructions request, deduping\n * the filename via {@link getSafeFileName} so a duplicate upload does not\n * overwrite an existing blob.\n *\n * A unique per-upload segment is included in the storage key so each issued\n * key is distinct. The stored `filename` stays clean and the semantic `prefix`\n * stays exactly what the collection configured — the per-upload entropy is\n * persisted separately in `_objectKey`.\n *\n * The resolved `sanitizedFilename` is returned so the browser-side handler\n * can update the form via `updateFilename`.\n *\n * The semantic prefix is resolved with {@link buildUploadPrefix} and the final\n * key with {@link buildUploadStoragePathData}, so the receipt only ever signs a key\n * beneath the configured collection prefix.\n */\nexport async function resolveSignedURLKey({\n collectionPrefix = '',\n collectionSlug,\n docPrefix,\n filename,\n req,\n useCompositePrefixes = false,\n}: Args): Promise<{\n sanitizedDocPrefix: string\n sanitizedFilename: string\n storageFilePath: string\n uploadReference: UploadReference\n}> {\n // The document stores the -original name, so check collisions against that name.\n let sanitizedFilename = getSanitizedUploadFilename(filename)\n let originalFilename = getOriginalFilename({ filename: sanitizedFilename })\n\n while (\n (await getSafeFileName({ collectionSlug, desiredFilename: originalFilename, req })) !==\n originalFilename\n ) {\n sanitizedFilename = incrementName(sanitizedFilename)\n originalFilename = getOriginalFilename({ filename: sanitizedFilename })\n }\n\n const rawBaseDocPrefix = useCompositePrefixes ? docPrefix : docPrefix || collectionPrefix\n const { sanitizedDocPrefix } = buildUploadPrefix({\n collectionPrefix,\n docPrefix: rawBaseDocPrefix,\n useCompositePrefixes,\n })\n\n const _objectKey = randomUUID()\n // Per-upload segment lives in the key; it is persisted in `_objectKey`, keeping `prefix` semantic.\n const keyedDocPrefix = sanitizedDocPrefix ? `${sanitizedDocPrefix}/${_objectKey}` : _objectKey\n\n const { storageFilePath } = buildUploadStoragePathData({\n collectionPrefix,\n docPrefix: keyedDocPrefix,\n filename: originalFilename,\n useCompositePrefixes,\n })\n\n const uploadReference = {\n _objectKey,\n prefix: sanitizedDocPrefix,\n signedReceipt: createClientUploadReceipt({\n _objectKey,\n collectionSlug,\n filename: sanitizedFilename,\n filePrefix: sanitizedDocPrefix,\n req,\n storageFilePath,\n }),\n }\n\n return { sanitizedDocPrefix, sanitizedFilename, storageFilePath, uploadReference }\n}\n"],"names":["randomUUID","createClientUploadReceipt","getOriginalFilename","getSafeFileName","incrementName","getSanitizedUploadFilename","buildUploadPrefix","buildUploadStoragePathData","resolveSignedURLKey","collectionPrefix","collectionSlug","docPrefix","filename","req","useCompositePrefixes","sanitizedFilename","originalFilename","desiredFilename","rawBaseDocPrefix","sanitizedDocPrefix","_objectKey","keyedDocPrefix","storageFilePath","uploadReference","prefix","signedReceipt","filePrefix"],"mappings":"AAEA,SAASA,UAAU,QAAQ,cAAa;AACxC,SACEC,yBAAyB,EACzBC,mBAAmB,EACnBC,eAAe,EACfC,aAAa,QACR,mBAAkB;AACzB,SAASC,0BAA0B,QAAQ,iBAAgB;AAI3D,SAASC,iBAAiB,EAAEC,0BAA0B,QAAQ,4BAA2B;AAWzF;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,oBAAoB,EACxCC,mBAAmB,EAAE,EACrBC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,GAAG,EACHC,uBAAuB,KAAK,EACvB;IAML,iFAAiF;IACjF,IAAIC,oBAAoBV,2BAA2BO;IACnD,IAAII,mBAAmBd,oBAAoB;QAAEU,UAAUG;IAAkB;IAEzE,MACE,AAAC,MAAMZ,gBAAgB;QAAEO;QAAgBO,iBAAiBD;QAAkBH;IAAI,OAChFG,iBACA;QACAD,oBAAoBX,cAAcW;QAClCC,mBAAmBd,oBAAoB;YAAEU,UAAUG;QAAkB;IACvE;IAEA,MAAMG,mBAAmBJ,uBAAuBH,YAAYA,aAAaF;IACzE,MAAM,EAAEU,kBAAkB,EAAE,GAAGb,kBAAkB;QAC/CG;QACAE,WAAWO;QACXJ;IACF;IAEA,MAAMM,aAAapB;IACnB,mGAAmG;IACnG,MAAMqB,iBAAiBF,qBAAqB,GAAGA,mBAAmB,CAAC,EAAEC,YAAY,GAAGA;IAEpF,MAAM,EAAEE,eAAe,EAAE,GAAGf,2BAA2B;QACrDE;QACAE,WAAWU;QACXT,UAAUI;QACVF;IACF;IAEA,MAAMS,kBAAkB;QACtBH;QACAI,QAAQL;QACRM,eAAexB,0BAA0B;YACvCmB;YACAV;YACAE,UAAUG;YACVW,YAAYP;YACZN;YACAS;QACF;IACF;IAEA,OAAO;QAAEH;QAAoBJ;QAAmBO;QAAiBC;IAAgB;AACnF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-cloud-storage",
3
- "version": "4.0.0-internal.8001944",
3
+ "version": "4.0.0-internal.8089ef7",
4
4
  "description": "The official cloud storage plugin for Payload CMS",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -51,18 +51,18 @@
51
51
  "dependencies": {
52
52
  "find-node-modules": "^2.1.3",
53
53
  "range-parser": "^1.2.1",
54
- "@payloadcms/ui": "4.0.0-internal.8001944"
54
+ "@payloadcms/ui": "4.0.0-internal.8089ef7"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/find-node-modules": "^2.1.2",
58
58
  "@types/react": "19.3.0",
59
59
  "@types/react-dom": "19.3.0",
60
- "payload": "4.0.0-internal.8001944"
60
+ "payload": "4.0.0-internal.8089ef7"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": "^19.0.1 || ^19.1.2 || ^19.2.1",
64
64
  "react-dom": "^19.0.1 || ^19.1.2 || ^19.2.1",
65
- "payload": "4.0.0-internal.8001944"
65
+ "payload": "4.0.0-internal.8089ef7"
66
66
  },
67
67
  "publishConfig": {
68
68
  "registry": "https://registry.npmjs.org/"