@payloadcms/plugin-cloud-storage 4.0.0-internal.e55ccef → 4.0.0-internal.ea6e8f8

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 (98) hide show
  1. package/README.md +2 -0
  2. package/dist/client/createClientUploadHandler.d.ts +8 -7
  3. package/dist/client/createClientUploadHandler.d.ts.map +1 -1
  4. package/dist/client/createClientUploadHandler.js +26 -22
  5. package/dist/client/createClientUploadHandler.js.map +1 -1
  6. package/dist/exports/client.d.ts +1 -1
  7. package/dist/exports/client.d.ts.map +1 -1
  8. package/dist/exports/client.js +1 -1
  9. package/dist/exports/client.js.map +1 -1
  10. package/dist/exports/utilities.d.ts +1 -2
  11. package/dist/exports/utilities.d.ts.map +1 -1
  12. package/dist/exports/utilities.js +1 -2
  13. package/dist/exports/utilities.js.map +1 -1
  14. package/dist/fields/getFields.d.ts +1 -5
  15. package/dist/fields/getFields.d.ts.map +1 -1
  16. package/dist/fields/getFields.js +118 -24
  17. package/dist/fields/getFields.js.map +1 -1
  18. package/dist/hooks/afterChange.d.ts +5 -1
  19. package/dist/hooks/afterChange.d.ts.map +1 -1
  20. package/dist/hooks/afterChange.js +208 -32
  21. package/dist/hooks/afterChange.js.map +1 -1
  22. package/dist/hooks/afterDelete.d.ts +10 -2
  23. package/dist/hooks/afterDelete.d.ts.map +1 -1
  24. package/dist/hooks/afterDelete.js +110 -15
  25. package/dist/hooks/afterDelete.js.map +1 -1
  26. package/dist/hooks/afterRead.d.ts +6 -1
  27. package/dist/hooks/afterRead.d.ts.map +1 -1
  28. package/dist/hooks/afterRead.js +34 -7
  29. package/dist/hooks/afterRead.js.map +1 -1
  30. package/dist/hooks/beforeChange.d.ts +2 -1
  31. package/dist/hooks/beforeChange.d.ts.map +1 -1
  32. package/dist/hooks/beforeChange.js +18 -4
  33. package/dist/hooks/beforeChange.js.map +1 -1
  34. package/dist/hooks/normalizeUploadPrefix.d.ts +11 -0
  35. package/dist/hooks/normalizeUploadPrefix.d.ts.map +1 -0
  36. package/dist/hooks/normalizeUploadPrefix.js +42 -0
  37. package/dist/hooks/normalizeUploadPrefix.js.map +1 -0
  38. package/dist/hooks/publicOriginalURL.d.ts +8 -0
  39. package/dist/hooks/publicOriginalURL.d.ts.map +1 -0
  40. package/dist/hooks/publicOriginalURL.js +34 -0
  41. package/dist/hooks/publicOriginalURL.js.map +1 -0
  42. package/dist/plugin.d.ts.map +1 -1
  43. package/dist/plugin.js +210 -129
  44. package/dist/plugin.js.map +1 -1
  45. package/dist/types.d.ts +60 -21
  46. package/dist/types.d.ts.map +1 -1
  47. package/dist/types.js.map +1 -1
  48. package/dist/utilities/buildPrefixWithObjectKey.d.ts +8 -0
  49. package/dist/utilities/buildPrefixWithObjectKey.d.ts.map +1 -0
  50. package/dist/utilities/buildPrefixWithObjectKey.js +13 -0
  51. package/dist/utilities/buildPrefixWithObjectKey.js.map +1 -0
  52. package/dist/utilities/buildStoragePathData.d.ts +49 -0
  53. package/dist/utilities/buildStoragePathData.d.ts.map +1 -0
  54. package/dist/utilities/buildStoragePathData.js +67 -0
  55. package/dist/utilities/buildStoragePathData.js.map +1 -0
  56. package/dist/utilities/createFileOperations.d.ts +13 -0
  57. package/dist/utilities/createFileOperations.d.ts.map +1 -0
  58. package/dist/utilities/createFileOperations.js +258 -0
  59. package/dist/utilities/createFileOperations.js.map +1 -0
  60. package/dist/utilities/getFilePrefix.d.ts +16 -11
  61. package/dist/utilities/getFilePrefix.d.ts.map +1 -1
  62. package/dist/utilities/getFilePrefix.js +86 -31
  63. package/dist/utilities/getFilePrefix.js.map +1 -1
  64. package/dist/utilities/getIncomingFiles.js +4 -4
  65. package/dist/utilities/getIncomingFiles.js.map +1 -1
  66. package/dist/utilities/getStorageLocationSelect.d.ts +9 -0
  67. package/dist/utilities/getStorageLocationSelect.d.ts.map +1 -0
  68. package/dist/utilities/getStorageLocationSelect.js +54 -0
  69. package/dist/utilities/getStorageLocationSelect.js.map +1 -0
  70. package/dist/utilities/resolveSignedURLKey.d.ts +13 -2
  71. package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
  72. package/dist/utilities/resolveSignedURLKey.js +53 -11
  73. package/dist/utilities/resolveSignedURLKey.js.map +1 -1
  74. package/dist/utilities/sanitizePrefix.d.ts +1 -9
  75. package/dist/utilities/sanitizePrefix.d.ts.map +1 -1
  76. package/dist/utilities/sanitizePrefix.js +1 -21
  77. package/dist/utilities/sanitizePrefix.js.map +1 -1
  78. package/package.json +6 -6
  79. package/dist/admin/fields/getFields.d.ts +0 -17
  80. package/dist/admin/fields/getFields.d.ts.map +0 -1
  81. package/dist/admin/fields/getFields.js +0 -98
  82. package/dist/admin/fields/getFields.js.map +0 -1
  83. package/dist/admin/index.d.ts +0 -4
  84. package/dist/admin/index.d.ts.map +0 -1
  85. package/dist/admin/index.js +0 -34
  86. package/dist/admin/index.js.map +0 -1
  87. package/dist/utilities/getFileKey.d.ts +0 -22
  88. package/dist/utilities/getFileKey.d.ts.map +0 -1
  89. package/dist/utilities/getFileKey.js +0 -23
  90. package/dist/utilities/getFileKey.js.map +0 -1
  91. package/dist/utilities/getFileKey.spec.js +0 -174
  92. package/dist/utilities/getFileKey.spec.js.map +0 -1
  93. package/dist/utilities/getFilePrefix.spec.js +0 -105
  94. package/dist/utilities/getFilePrefix.spec.js.map +0 -1
  95. package/dist/utilities/initClientUploads.d.ts +0 -13
  96. package/dist/utilities/initClientUploads.d.ts.map +0 -1
  97. package/dist/utilities/initClientUploads.js +0 -63
  98. package/dist/utilities/initClientUploads.js.map +0 -1
@@ -1,46 +1,101 @@
1
+ import { buildPrefixWithObjectKey } from './buildPrefixWithObjectKey.js';
2
+ import { buildUploadStoragePathData } from './buildStoragePathData.js';
1
3
  import { sanitizePrefix } from './sanitizePrefix.js';
2
4
  /**
3
- * Resolves the file prefix from the highest-priority available source and
4
- * always returns a sanitized value.
5
+ * Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).
5
6
  *
6
- * Resolution order:
7
- * 1. `prefixQueryParam`
8
- * 2. `clientUploadContext.prefix`
9
- * 3. Stored document `prefix` from the database
10
- *
11
- * Resolved values are passed through `sanitizePrefix`.
12
- */ export async function getFilePrefix({ clientUploadContext, collection, filename, prefixQueryParam, req }) {
13
- if (typeof prefixQueryParam === 'string') {
14
- return sanitizePrefix(prefixQueryParam);
7
+ * An already-authorized `doc` wins outright. Otherwise an `uploadReference` is used (its
8
+ * `prefix` re-contained with {@link buildUploadStoragePathData}, since it hasn't been verified against
9
+ * a signed receipt by every adapter). Otherwise the document is resolved with
10
+ * `overrideAccess: false`, any query-param prefix only narrows that lookup, and `_objectKey`
11
+ * is read from the resolved document via `showHiddenFields`.
12
+ */ export async function getFilePrefix({ collection, collectionPrefix, doc, filename, prefixQueryParam, req, uploadReference, useCompositePrefixes = false }) {
13
+ // The serve path already loaded and authorized this document — trust it over any
14
+ // client-supplied upload reference or query prefix.
15
+ if (doc) {
16
+ return getRepresentationPrefix({
17
+ doc,
18
+ filename
19
+ });
15
20
  }
16
- // Prioritize from clientUploadContext if there is:
17
- if (clientUploadContext && typeof clientUploadContext === 'object' && 'prefix' in clientUploadContext && typeof clientUploadContext.prefix === 'string') {
18
- return sanitizePrefix(clientUploadContext.prefix);
21
+ // Upload instructions call handlers without a document yet. Re-contain the claimed
22
+ // prefix — it hasn't been verified against a signed receipt by every adapter.
23
+ if (uploadReference && typeof uploadReference === 'object' && 'prefix' in uploadReference && typeof uploadReference.prefix === 'string') {
24
+ const referenceObjectKey = '_objectKey' in uploadReference ? uploadReference._objectKey : undefined;
25
+ const containedPrefix = buildUploadStoragePathData({
26
+ collectionPrefix,
27
+ docPrefix: uploadReference.prefix,
28
+ filename,
29
+ useCompositePrefixes
30
+ }).sanitizedDocPrefix;
31
+ return buildPrefixWithObjectKey({
32
+ objectKey: referenceObjectKey,
33
+ prefix: containedPrefix
34
+ });
19
35
  }
20
- const imageSizes = collection?.upload?.imageSizes || [];
36
+ // Reads without a query prefix or read-access constraints skip the endpoint's document lookup.
37
+ const variants = collection?.upload?.variants || [];
38
+ const filenameClause = {
39
+ or: [
40
+ {
41
+ filename: {
42
+ equals: filename
43
+ }
44
+ },
45
+ {
46
+ 'original.filename': {
47
+ equals: filename
48
+ }
49
+ },
50
+ ...variants.map((imageSize)=>({
51
+ [`variants.${imageSize.name}.filename`]: {
52
+ equals: filename
53
+ }
54
+ }))
55
+ ]
56
+ };
57
+ // Only filter by prefix when the collection persists a `prefix` field (querying a missing field throws).
58
+ const hasPrefixField = collection.fields?.some((field)=>'name' in field && field.name === 'prefix');
59
+ const where = typeof prefixQueryParam === 'string' && hasPrefixField ? {
60
+ and: [
61
+ filenameClause,
62
+ {
63
+ prefix: {
64
+ equals: sanitizePrefix(prefixQueryParam)
65
+ }
66
+ }
67
+ ]
68
+ } : filenameClause;
21
69
  const files = await req.payload.find({
22
70
  collection: collection.slug,
23
71
  depth: 0,
24
72
  draft: true,
25
73
  limit: 1,
74
+ overrideAccess: false,
26
75
  pagination: false,
27
- where: {
28
- or: [
29
- {
30
- filename: {
31
- equals: filename
32
- }
33
- },
34
- ...imageSizes.map((imageSize)=>({
35
- [`sizes.${imageSize.name}.filename`]: {
36
- equals: filename
37
- }
38
- }))
39
- ]
40
- }
76
+ req,
77
+ select: {
78
+ _objectKey: true,
79
+ filename: true,
80
+ original: true,
81
+ prefix: true,
82
+ variants: true
83
+ },
84
+ showHiddenFields: true,
85
+ where
41
86
  });
42
- const prefix = files?.docs?.[0]?.prefix;
43
- return prefix ? sanitizePrefix(prefix) : '';
87
+ const found = files?.docs?.[0];
88
+ return found ? getRepresentationPrefix({
89
+ doc: found,
90
+ filename
91
+ }) : '';
44
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;
95
+ return buildPrefixWithObjectKey({
96
+ objectKey: representation._objectKey ?? (!doc.original?.filename ? doc._objectKey : undefined),
97
+ prefix: representation.prefix ?? (!doc.original?.filename ? doc.prefix : undefined)
98
+ });
99
+ };
45
100
 
46
101
  //# sourceMappingURL=getFilePrefix.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/getFilePrefix.ts"],"sourcesContent":["import type { CollectionConfig, PayloadRequest, UploadConfig } from 'payload'\n\nimport { sanitizePrefix } from './sanitizePrefix.js'\n\n/**\n * Resolves the file prefix from the highest-priority available source and\n * always returns a sanitized value.\n *\n * Resolution order:\n * 1. `prefixQueryParam`\n * 2. `clientUploadContext.prefix`\n * 3. Stored document `prefix` from the database\n *\n * Resolved values are passed through `sanitizePrefix`.\n */\nexport async function getFilePrefix({\n clientUploadContext,\n collection,\n filename,\n prefixQueryParam,\n req,\n}: {\n clientUploadContext?: unknown\n collection: CollectionConfig\n filename: string\n prefixQueryParam?: string\n req: PayloadRequest\n}): Promise<string> {\n if (typeof prefixQueryParam === 'string') {\n return sanitizePrefix(prefixQueryParam)\n }\n\n // Prioritize from clientUploadContext if there is:\n if (\n clientUploadContext &&\n typeof clientUploadContext === 'object' &&\n 'prefix' in clientUploadContext &&\n typeof clientUploadContext.prefix === 'string'\n ) {\n return sanitizePrefix(clientUploadContext.prefix)\n }\n\n const imageSizes = (collection?.upload as UploadConfig)?.imageSizes || []\n\n const files = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n limit: 1,\n pagination: false,\n where: {\n or: [\n {\n filename: { equals: filename },\n },\n ...imageSizes.map((imageSize) => ({\n [`sizes.${imageSize.name}.filename`]: { equals: filename },\n })),\n ],\n },\n })\n const prefix = files?.docs?.[0]?.prefix\n return prefix ? sanitizePrefix(prefix as string) : ''\n}\n"],"names":["sanitizePrefix","getFilePrefix","clientUploadContext","collection","filename","prefixQueryParam","req","prefix","imageSizes","upload","files","payload","find","slug","depth","draft","limit","pagination","where","or","equals","map","imageSize","name","docs"],"mappings":"AAEA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD;;;;;;;;;;CAUC,GACD,OAAO,eAAeC,cAAc,EAClCC,mBAAmB,EACnBC,UAAU,EACVC,QAAQ,EACRC,gBAAgB,EAChBC,GAAG,EAOJ;IACC,IAAI,OAAOD,qBAAqB,UAAU;QACxC,OAAOL,eAAeK;IACxB;IAEA,mDAAmD;IACnD,IACEH,uBACA,OAAOA,wBAAwB,YAC/B,YAAYA,uBACZ,OAAOA,oBAAoBK,MAAM,KAAK,UACtC;QACA,OAAOP,eAAeE,oBAAoBK,MAAM;IAClD;IAEA,MAAMC,aAAa,AAACL,YAAYM,QAAyBD,cAAc,EAAE;IAEzE,MAAME,QAAQ,MAAMJ,IAAIK,OAAO,CAACC,IAAI,CAAC;QACnCT,YAAYA,WAAWU,IAAI;QAC3BC,OAAO;QACPC,OAAO;QACPC,OAAO;QACPC,YAAY;QACZC,OAAO;YACLC,IAAI;gBACF;oBACEf,UAAU;wBAAEgB,QAAQhB;oBAAS;gBAC/B;mBACGI,WAAWa,GAAG,CAAC,CAACC,YAAe,CAAA;wBAChC,CAAC,CAAC,MAAM,EAAEA,UAAUC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;4BAAEH,QAAQhB;wBAAS;oBAC3D,CAAA;aACD;QACH;IACF;IACA,MAAMG,SAASG,OAAOc,MAAM,CAAC,EAAE,EAAEjB;IACjC,OAAOA,SAASP,eAAeO,UAAoB;AACrD"}
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,MAAME,iBAAiB;QACrBC,IAAI;YACF;gBACEjB,UAAU;oBAAEkB,QAAQlB;gBAAS;YAC/B;YACA;gBAAE,qBAAqB;oBAAEkB,QAAQlB;gBAAS;YAAE;eACzCc,SAASK,GAAG,CAAC,CAACC,YAAe,CAAA;oBAC9B,CAAC,CAAC,SAAS,EAAEA,UAAUC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;wBAAEH,QAAQlB;oBAAS;gBAC9D,CAAA;SACD;IACH;IAEA,yGAAyG;IACzG,MAAMsB,iBAAiBzB,WAAW0B,MAAM,EAAEC,KACxC,CAACC,QAAU,UAAUA,SAASA,MAAMJ,IAAI,KAAK;IAE/C,MAAMK,QACJ,OAAOzB,qBAAqB,YAAYqB,iBACpC;QAAEK,KAAK;YAACX;YAAgB;gBAAEV,QAAQ;oBAAEY,QAAQvB,eAAeM;gBAAkB;YAAE;SAAE;IAAC,IAClFe;IAEN,MAAMY,QAAQ,MAAM1B,IAAI2B,OAAO,CAACC,IAAI,CAAC;QACnCjC,YAAYA,WAAWkC,IAAI;QAC3BC,OAAO;QACPC,OAAO;QACPC,OAAO;QACPC,gBAAgB;QAChBC,YAAY;QACZlC;QACAmC,QAAQ;YACN7B,YAAY;YACZR,UAAU;YACVsC,UAAU;YACVhC,QAAQ;YACRQ,UAAU;QACZ;QACAyB,kBAAkB;QAClBb;IACF;IAEA,MAAMc,QAAQZ,OAAOa,MAAM,CAAC,EAAE;IAG9B,OAAOD,QAAQnC,wBAAwB;QAAEN,KAAKyC;QAAOxC;IAAS,KAAK;AACrE;AAEA,MAAMK,0BAA0B,CAAC,EAC/BN,GAAG,EACHC,QAAQ,EAIT;IACC,MAAM0C,iBACJ3C,IAAIuC,QAAQ,EAAEtC,aAAaA,WACvBD,IAAIuC,QAAQ,GACXK,OAAOC,MAAM,CAAC7C,IAAIe,QAAQ,IAAI,CAAC,GAAGgB,IAAI,CAAC,CAACe,UAAYA,SAAS7C,aAAaA,aAAaD;IAC9F,OAAON,yBAAyB;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"}
@@ -7,17 +7,17 @@ export function getIncomingFiles({ data, req }) {
7
7
  if (file && data.filename && data.mimeType) {
8
8
  const mainFile = {
9
9
  buffer: file.data,
10
- clientUploadContext: file.clientUploadContext,
11
10
  filename: data.filename,
12
11
  filesize: file.size,
13
12
  mimeType: data.mimeType,
14
- tempFilePath: file.tempFilePath
13
+ tempFilePath: file.tempFilePath,
14
+ uploadReference: file.uploadReference
15
15
  };
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 clientUploadContext: file.clientUploadContext,\n filename: data.filename,\n filesize: file.size,\n mimeType: data.mimeType,\n tempFilePath: file.tempFilePath,\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","clientUploadContext","filesize","size","tempFilePath","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;YACjBa,qBAAqBR,KAAKQ,mBAAmB;YAC7CJ,UAAUT,KAAKS,QAAQ;YACvBK,UAAUT,KAAKU,IAAI;YACnBL,UAAUV,KAAKU,QAAQ;YACvBM,cAAcX,KAAKW,YAAY;QACjC;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;4BACvCK,UAAUR,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,QAAQ,GAAGH,kBAAkB;YAAEC,gBAAgB;gBAAE,GAAGF,OAAOI,QAAQ;YAAC;QAAE;IAC/E;IAEA,IAAID,eAAeH,OAAOK,QAAQ,GAAG;QACnCL,OAAOK,QAAQ,GAAGC,OAAOC,WAAW,CAClCD,OAAOE,OAAO,CAACR,OAAOK,QAAQ,EAAEI,GAAG,CAAC,CAAC,CAACC,MAAMC,QAAQ,GAAK;gBACvDD;gBACAP,eAAeQ,WAAWV,kBAAkB;oBAAEC,gBAAgB;wBAAE,GAAGS,OAAO;oBAAC;gBAAE,KAAKA;aACnF;IAEL;IAEA,OAAOX;AACT;AAEA,MAAMC,oBAAoB,CAAC,EAAEC,cAAc,EAAoC;IAC7E,IAAIA,eAAeU,GAAG,KAAK,MAAM;QAC/B,KAAK,MAAMC,aAAanB,mBAAoB;YAC1CQ,cAAc,CAACW,UAAU,GAAG;QAC9B;IACF;IAEA,OAAOX;AACT;AAEA,MAAMC,iBAAiB,CAACW,QACtB,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF"}
@@ -1,4 +1,5 @@
1
1
  import type { PayloadRequest } from 'payload';
2
+ import type { UploadReference } from '../types.js';
2
3
  type Args = {
3
4
  collectionPrefix?: string;
4
5
  collectionSlug: string;
@@ -8,17 +9,27 @@ type Args = {
8
9
  useCompositePrefixes?: boolean;
9
10
  };
10
11
  /**
11
- * Resolves the storage key for a clientUploads signed-URL request, deduping
12
+ * Resolves the storage key for an upload-instructions request, deduping
12
13
  * the filename via {@link getSafeFileName} so a duplicate upload does not
13
14
  * overwrite an existing blob.
14
15
  *
16
+ * A unique per-upload segment is included in the storage key so each issued
17
+ * key is distinct. The stored `filename` stays clean and the semantic `prefix`
18
+ * stays exactly what the collection configured — the per-upload entropy is
19
+ * persisted separately in `_objectKey`.
20
+ *
15
21
  * The resolved `sanitizedFilename` is returned so the browser-side handler
16
22
  * can update the form via `updateFilename`.
23
+ *
24
+ * The semantic prefix is resolved with {@link buildUploadPrefix} and the final
25
+ * key with {@link buildUploadStoragePathData}, so the receipt only ever signs a key
26
+ * beneath the configured collection prefix.
17
27
  */
18
28
  export declare function resolveSignedURLKey({ collectionPrefix, collectionSlug, docPrefix, filename, req, useCompositePrefixes, }: Args): Promise<{
19
- fileKey: string;
20
29
  sanitizedDocPrefix: string;
21
30
  sanitizedFilename: string;
31
+ storageFilePath: string;
32
+ uploadReference: UploadReference;
22
33
  }>;
23
34
  export {};
24
35
  //# sourceMappingURL=resolveSignedURLKey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveSignedURLKey.d.ts","sourceRoot":"","sources":["../../src/utilities/resolveSignedURLKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAM7C,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;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,EACxC,gBAAqB,EACrB,cAAc,EACd,SAAS,EACT,QAAQ,EACR,GAAG,EACH,oBAA4B,GAC7B,EAAE,IAAI;;;;GAgBN"}
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,29 +1,71 @@
1
- import { getSafeFileName } from 'payload/internal';
2
- import { getFileKey } from './getFileKey.js';
1
+ import { randomUUID } from 'node:crypto';
2
+ import { createClientUploadReceipt, getOriginalFilename, getSafeFileName, incrementName } from 'payload/internal';
3
+ import { getSanitizedUploadFilename } from 'payload/shared';
4
+ import { buildUploadPrefix, buildUploadStoragePathData } from './buildStoragePathData.js';
3
5
  /**
4
- * Resolves the storage key for a clientUploads signed-URL request, deduping
6
+ * Resolves the storage key for an upload-instructions request, deduping
5
7
  * the filename via {@link getSafeFileName} so a duplicate upload does not
6
8
  * overwrite an existing blob.
7
9
  *
10
+ * A unique per-upload segment is included in the storage key so each issued
11
+ * key is distinct. The stored `filename` stays clean and the semantic `prefix`
12
+ * stays exactly what the collection configured — the per-upload entropy is
13
+ * persisted separately in `_objectKey`.
14
+ *
8
15
  * The resolved `sanitizedFilename` is returned so the browser-side handler
9
16
  * can update the form via `updateFilename`.
17
+ *
18
+ * The semantic prefix is resolved with {@link buildUploadPrefix} and the final
19
+ * key with {@link buildUploadStoragePathData}, so the receipt only ever signs a key
20
+ * beneath the configured collection prefix.
10
21
  */ export async function resolveSignedURLKey({ collectionPrefix = '', collectionSlug, docPrefix, filename, req, useCompositePrefixes = false }) {
11
- 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({
12
28
  collectionSlug,
13
- desiredFilename: filename,
14
- prefix: docPrefix,
29
+ desiredFilename: originalFilename,
15
30
  req
31
+ }) !== originalFilename){
32
+ sanitizedFilename = incrementName(sanitizedFilename);
33
+ originalFilename = getOriginalFilename({
34
+ filename: sanitizedFilename
35
+ });
36
+ }
37
+ const rawBaseDocPrefix = useCompositePrefixes ? docPrefix : docPrefix || collectionPrefix;
38
+ const { sanitizedDocPrefix } = buildUploadPrefix({
39
+ collectionPrefix,
40
+ docPrefix: rawBaseDocPrefix,
41
+ useCompositePrefixes
16
42
  });
17
- const { fileKey, sanitizedDocPrefix } = getFileKey({
43
+ const _objectKey = randomUUID();
44
+ // Per-upload segment lives in the key; it is persisted in `_objectKey`, keeping `prefix` semantic.
45
+ const keyedDocPrefix = sanitizedDocPrefix ? `${sanitizedDocPrefix}/${_objectKey}` : _objectKey;
46
+ const { storageFilePath } = buildUploadStoragePathData({
18
47
  collectionPrefix,
19
- docPrefix,
20
- filename: sanitizedFilename,
48
+ docPrefix: keyedDocPrefix,
49
+ filename: originalFilename,
21
50
  useCompositePrefixes
22
51
  });
52
+ const uploadReference = {
53
+ _objectKey,
54
+ prefix: sanitizedDocPrefix,
55
+ signedReceipt: createClientUploadReceipt({
56
+ _objectKey,
57
+ collectionSlug,
58
+ filename: sanitizedFilename,
59
+ filePrefix: sanitizedDocPrefix,
60
+ req,
61
+ storageFilePath
62
+ })
63
+ };
23
64
  return {
24
- fileKey,
25
65
  sanitizedDocPrefix,
26
- sanitizedFilename
66
+ sanitizedFilename,
67
+ storageFilePath,
68
+ uploadReference
27
69
  };
28
70
  }
29
71
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/resolveSignedURLKey.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { getSafeFileName } from 'payload/internal'\n\nimport { getFileKey } from './getFileKey.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 a clientUploads signed-URL request, deduping\n * the filename via {@link getSafeFileName} so a duplicate upload does not\n * overwrite an existing blob.\n *\n * The resolved `sanitizedFilename` is returned so the browser-side handler\n * can update the form via `updateFilename`.\n */\nexport async function resolveSignedURLKey({\n collectionPrefix = '',\n collectionSlug,\n docPrefix,\n filename,\n req,\n useCompositePrefixes = false,\n}: Args) {\n const sanitizedFilename = await getSafeFileName({\n collectionSlug,\n desiredFilename: filename,\n prefix: docPrefix,\n req,\n })\n\n const { fileKey, sanitizedDocPrefix } = getFileKey({\n collectionPrefix,\n docPrefix,\n filename: sanitizedFilename,\n useCompositePrefixes,\n })\n\n return { fileKey, sanitizedDocPrefix, sanitizedFilename }\n}\n"],"names":["getSafeFileName","getFileKey","resolveSignedURLKey","collectionPrefix","collectionSlug","docPrefix","filename","req","useCompositePrefixes","sanitizedFilename","desiredFilename","prefix","fileKey","sanitizedDocPrefix"],"mappings":"AAEA,SAASA,eAAe,QAAQ,mBAAkB;AAElD,SAASC,UAAU,QAAQ,kBAAiB;AAW5C;;;;;;;CAOC,GACD,OAAO,eAAeC,oBAAoB,EACxCC,mBAAmB,EAAE,EACrBC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,GAAG,EACHC,uBAAuB,KAAK,EACvB;IACL,MAAMC,oBAAoB,MAAMT,gBAAgB;QAC9CI;QACAM,iBAAiBJ;QACjBK,QAAQN;QACRE;IACF;IAEA,MAAM,EAAEK,OAAO,EAAEC,kBAAkB,EAAE,GAAGZ,WAAW;QACjDE;QACAE;QACAC,UAAUG;QACVD;IACF;IAEA,OAAO;QAAEI;QAASC;QAAoBJ;IAAkB;AAC1D"}
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"}
@@ -1,10 +1,2 @@
1
- /**
2
- * Normalizes a storage prefix for use in object keys and URLs.
3
- *
4
- * Decodes URI components once (so query-style `%2F` becomes `/`), rejects
5
- * values that still contain percent-encodings after decoding (e.g. `%252f`),
6
- * then normalizes slashes, drops `.` / `..` segments, strips leading slashes,
7
- * and removes control characters.
8
- */
9
- export declare function sanitizePrefix(prefix: string): string;
1
+ export { sanitizeUploadPrefix as sanitizePrefix } from 'payload/shared';
10
2
  //# sourceMappingURL=sanitizePrefix.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizePrefix.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAwBrD"}
1
+ {"version":3,"file":"sanitizePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/sanitizePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,cAAc,EAAE,MAAM,gBAAgB,CAAA"}
@@ -1,23 +1,3 @@
1
- /**
2
- * Normalizes a storage prefix for use in object keys and URLs.
3
- *
4
- * Decodes URI components once (so query-style `%2F` becomes `/`), rejects
5
- * values that still contain percent-encodings after decoding (e.g. `%252f`),
6
- * then normalizes slashes, drops `.` / `..` segments, strips leading slashes,
7
- * and removes control characters.
8
- */ export function sanitizePrefix(prefix) {
9
- let decodedPrefix;
10
- try {
11
- decodedPrefix = decodeURIComponent(prefix);
12
- } catch {
13
- return '';
14
- }
15
- // Reject multi-encoded values (e.g. `%252f`) by allowing only a single decode pass.
16
- if (/%[0-9a-f]{2}/i.test(decodedPrefix)) {
17
- return '';
18
- }
19
- return decodedPrefix.replace(/\\/g, '/').split('/').filter((segment)=>segment !== '..' && segment !== '.').join('/').replace(/^\/+/, '')// eslint-disable-next-line no-control-regex
20
- .replace(/[\x00-\x1f\x80-\x9f]/g, '');
21
- }
1
+ export { sanitizeUploadPrefix as sanitizePrefix } from 'payload/shared';
22
2
 
23
3
  //# sourceMappingURL=sanitizePrefix.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/sanitizePrefix.ts"],"sourcesContent":["/**\n * Normalizes a storage prefix for use in object keys and URLs.\n *\n * Decodes URI components once (so query-style `%2F` becomes `/`), rejects\n * values that still contain percent-encodings after decoding (e.g. `%252f`),\n * then normalizes slashes, drops `.` / `..` segments, strips leading slashes,\n * and removes control characters.\n */\nexport function sanitizePrefix(prefix: string): string {\n let decodedPrefix: string\n\n try {\n decodedPrefix = decodeURIComponent(prefix)\n } catch {\n return ''\n }\n\n // Reject multi-encoded values (e.g. `%252f`) by allowing only a single decode pass.\n if (/%[0-9a-f]{2}/i.test(decodedPrefix)) {\n return ''\n }\n\n return (\n decodedPrefix\n .replace(/\\\\/g, '/')\n .split('/')\n .filter((segment) => segment !== '..' && segment !== '.')\n .join('/')\n .replace(/^\\/+/, '')\n // eslint-disable-next-line no-control-regex\n .replace(/[\\x00-\\x1f\\x80-\\x9f]/g, '')\n )\n}\n"],"names":["sanitizePrefix","prefix","decodedPrefix","decodeURIComponent","test","replace","split","filter","segment","join"],"mappings":"AAAA;;;;;;;CAOC,GACD,OAAO,SAASA,eAAeC,MAAc;IAC3C,IAAIC;IAEJ,IAAI;QACFA,gBAAgBC,mBAAmBF;IACrC,EAAE,OAAM;QACN,OAAO;IACT;IAEA,oFAAoF;IACpF,IAAI,gBAAgBG,IAAI,CAACF,gBAAgB;QACvC,OAAO;IACT;IAEA,OACEA,cACGG,OAAO,CAAC,OAAO,KACfC,KAAK,CAAC,KACNC,MAAM,CAAC,CAACC,UAAYA,YAAY,QAAQA,YAAY,KACpDC,IAAI,CAAC,KACLJ,OAAO,CAAC,QAAQ,GACjB,4CAA4C;KAC3CA,OAAO,CAAC,yBAAyB;AAExC"}
1
+ {"version":3,"sources":["../../src/utilities/sanitizePrefix.ts"],"sourcesContent":["export { sanitizeUploadPrefix as sanitizePrefix } from 'payload/shared'\n"],"names":["sanitizeUploadPrefix","sanitizePrefix"],"mappings":"AAAA,SAASA,wBAAwBC,cAAc,QAAQ,iBAAgB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-cloud-storage",
3
- "version": "4.0.0-internal.e55ccef",
3
+ "version": "4.0.0-internal.ea6e8f8",
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.e55ccef"
54
+ "@payloadcms/ui": "4.0.0-internal.ea6e8f8"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/find-node-modules": "^2.1.2",
58
- "@types/react": "19.2.14",
59
- "@types/react-dom": "19.2.3",
60
- "payload": "4.0.0-internal.e55ccef"
58
+ "@types/react": "19.3.0",
59
+ "@types/react-dom": "19.3.0",
60
+ "payload": "4.0.0-internal.ea6e8f8"
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.e55ccef"
65
+ "payload": "4.0.0-internal.ea6e8f8"
66
66
  },
67
67
  "publishConfig": {
68
68
  "registry": "https://registry.npmjs.org/"
@@ -1,17 +0,0 @@
1
- import type { CollectionConfig, Field } from 'payload';
2
- interface Args {
3
- /**
4
- * When true, always insert the prefix field regardless of whether a prefix is configured.
5
- */
6
- alwaysInsertFields?: boolean;
7
- collection: CollectionConfig;
8
- prefix?: string;
9
- /**
10
- * When true, do not default the `prefix` field to the collection prefix; the
11
- * document field holds only the document-level segment.
12
- */
13
- useCompositePrefixes?: boolean;
14
- }
15
- export declare const getFields: ({ alwaysInsertFields, collection, prefix, useCompositePrefixes, }: Args) => Field[];
16
- export {};
17
- //# sourceMappingURL=getFields.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getFields.d.ts","sourceRoot":"","sources":["../../../src/admin/fields/getFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAyB,MAAM,SAAS,CAAA;AAI7E,UAAU,IAAI;IACZ;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,UAAU,EAAE,gBAAgB,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,eAAO,MAAM,SAAS,sEAKnB,IAAI,KAAG,KAAK,EAsHd,CAAA"}