@payloadcms/plugin-cloud-storage 4.0.0-internal.7e57eed → 4.0.0-internal.8001944

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 (74) hide show
  1. package/README.md +2 -0
  2. package/dist/exports/client.d.ts +1 -1
  3. package/dist/exports/client.d.ts.map +1 -1
  4. package/dist/exports/client.js +1 -1
  5. package/dist/exports/client.js.map +1 -1
  6. package/dist/exports/utilities.d.ts +1 -1
  7. package/dist/exports/utilities.d.ts.map +1 -1
  8. package/dist/exports/utilities.js +1 -1
  9. package/dist/exports/utilities.js.map +1 -1
  10. package/dist/fields/getFields.d.ts +1 -5
  11. package/dist/fields/getFields.d.ts.map +1 -1
  12. package/dist/fields/getFields.js +47 -18
  13. package/dist/fields/getFields.js.map +1 -1
  14. package/dist/hooks/afterChange.d.ts +3 -1
  15. package/dist/hooks/afterChange.d.ts.map +1 -1
  16. package/dist/hooks/afterChange.js +76 -20
  17. package/dist/hooks/afterChange.js.map +1 -1
  18. package/dist/hooks/afterDelete.d.ts +3 -1
  19. package/dist/hooks/afterDelete.d.ts.map +1 -1
  20. package/dist/hooks/afterDelete.js +16 -2
  21. package/dist/hooks/afterDelete.js.map +1 -1
  22. package/dist/hooks/afterRead.d.ts.map +1 -1
  23. package/dist/hooks/afterRead.js +15 -2
  24. package/dist/hooks/afterRead.js.map +1 -1
  25. package/dist/hooks/beforeChange.d.ts.map +1 -1
  26. package/dist/hooks/beforeChange.js +12 -1
  27. package/dist/hooks/beforeChange.js.map +1 -1
  28. package/dist/hooks/normalizeUploadPrefix.d.ts +11 -0
  29. package/dist/hooks/normalizeUploadPrefix.d.ts.map +1 -0
  30. package/dist/hooks/normalizeUploadPrefix.js +42 -0
  31. package/dist/hooks/normalizeUploadPrefix.js.map +1 -0
  32. package/dist/plugin.d.ts.map +1 -1
  33. package/dist/plugin.js +43 -38
  34. package/dist/plugin.js.map +1 -1
  35. package/dist/types.d.ts +19 -11
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js.map +1 -1
  38. package/dist/utilities/buildPrefixWithObjectKey.d.ts +8 -0
  39. package/dist/utilities/buildPrefixWithObjectKey.d.ts.map +1 -0
  40. package/dist/utilities/buildPrefixWithObjectKey.js +13 -0
  41. package/dist/utilities/buildPrefixWithObjectKey.js.map +1 -0
  42. package/dist/utilities/buildStoragePathData.d.ts +49 -0
  43. package/dist/utilities/buildStoragePathData.d.ts.map +1 -0
  44. package/dist/utilities/buildStoragePathData.js +67 -0
  45. package/dist/utilities/buildStoragePathData.js.map +1 -0
  46. package/dist/utilities/getFilePrefix.d.ts +18 -10
  47. package/dist/utilities/getFilePrefix.d.ts.map +1 -1
  48. package/dist/utilities/getFilePrefix.js +69 -29
  49. package/dist/utilities/getFilePrefix.js.map +1 -1
  50. package/dist/utilities/resolveSignedURLKey.d.ts +12 -1
  51. package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
  52. package/dist/utilities/resolveSignedURLKey.js +42 -8
  53. package/dist/utilities/resolveSignedURLKey.js.map +1 -1
  54. package/dist/utilities/sanitizePrefix.d.ts +1 -9
  55. package/dist/utilities/sanitizePrefix.d.ts.map +1 -1
  56. package/dist/utilities/sanitizePrefix.js +1 -21
  57. package/dist/utilities/sanitizePrefix.js.map +1 -1
  58. package/package.json +6 -6
  59. package/dist/admin/fields/getFields.d.ts +0 -17
  60. package/dist/admin/fields/getFields.d.ts.map +0 -1
  61. package/dist/admin/fields/getFields.js +0 -98
  62. package/dist/admin/fields/getFields.js.map +0 -1
  63. package/dist/admin/index.d.ts +0 -4
  64. package/dist/admin/index.d.ts.map +0 -1
  65. package/dist/admin/index.js +0 -34
  66. package/dist/admin/index.js.map +0 -1
  67. package/dist/utilities/getFileKey.d.ts +0 -22
  68. package/dist/utilities/getFileKey.d.ts.map +0 -1
  69. package/dist/utilities/getFileKey.js +0 -23
  70. package/dist/utilities/getFileKey.js.map +0 -1
  71. package/dist/utilities/getFileKey.spec.js +0 -174
  72. package/dist/utilities/getFileKey.spec.js.map +0 -1
  73. package/dist/utilities/getFilePrefix.spec.js +0 -105
  74. package/dist/utilities/getFilePrefix.spec.js.map +0 -1
@@ -1,23 +0,0 @@
1
- import path from 'path';
2
- import { sanitizeFilename } from 'payload/shared';
3
- import { sanitizePrefix } from './sanitizePrefix.js';
4
- /**
5
- * Computes the file key (path) for storage.
6
- *
7
- * In non-composite mode (useCompositePrefixes: false), docPrefix overrides collectionPrefix.
8
- * In composite mode (useCompositePrefixes: true), both are combined.
9
- * Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.
10
- */ export function getFileKey({ collectionPrefix, docPrefix, filename, useCompositePrefixes = false }) {
11
- const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '');
12
- const safeDocPrefix = sanitizePrefix(docPrefix || '');
13
- const safeFilename = sanitizeFilename(filename);
14
- const fileKey = useCompositePrefixes ? path.posix.join(safeCollectionPrefix, safeDocPrefix, safeFilename) : path.posix.join(safeDocPrefix || safeCollectionPrefix, safeFilename);
15
- return {
16
- fileKey,
17
- sanitizedCollectionPrefix: safeCollectionPrefix,
18
- sanitizedDocPrefix: safeDocPrefix,
19
- sanitizedFilename: safeFilename
20
- };
21
- }
22
-
23
- //# sourceMappingURL=getFileKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utilities/getFileKey.ts"],"sourcesContent":["import path from 'path'\nimport { sanitizeFilename } from 'payload/shared'\n\nimport { sanitizePrefix } from './sanitizePrefix.js'\n\ntype GetFileKeyArgs = {\n collectionPrefix?: string\n docPrefix?: string\n filename: string\n useCompositePrefixes?: boolean\n}\n\ntype GetFileKeyResult = {\n fileKey: string\n sanitizedCollectionPrefix: string\n sanitizedDocPrefix: string\n sanitizedFilename: string\n}\n\n/**\n * Computes the file key (path) for storage.\n *\n * In non-composite mode (useCompositePrefixes: false), docPrefix overrides collectionPrefix.\n * In composite mode (useCompositePrefixes: true), both are combined.\n * Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.\n */\nexport function getFileKey({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes = false,\n}: GetFileKeyArgs): GetFileKeyResult {\n const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '')\n const safeDocPrefix = sanitizePrefix(docPrefix || '')\n const safeFilename = sanitizeFilename(filename)\n\n const fileKey = useCompositePrefixes\n ? path.posix.join(safeCollectionPrefix, safeDocPrefix, safeFilename)\n : path.posix.join(safeDocPrefix || safeCollectionPrefix, safeFilename)\n\n return {\n fileKey,\n sanitizedCollectionPrefix: safeCollectionPrefix,\n sanitizedDocPrefix: safeDocPrefix,\n sanitizedFilename: safeFilename,\n }\n}\n"],"names":["path","sanitizeFilename","sanitizePrefix","getFileKey","collectionPrefix","docPrefix","filename","useCompositePrefixes","safeCollectionPrefix","safeDocPrefix","safeFilename","fileKey","posix","join","sanitizedCollectionPrefix","sanitizedDocPrefix","sanitizedFilename"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AACvB,SAASC,gBAAgB,QAAQ,iBAAgB;AAEjD,SAASC,cAAc,QAAQ,sBAAqB;AAgBpD;;;;;;CAMC,GACD,OAAO,SAASC,WAAW,EACzBC,gBAAgB,EAChBC,SAAS,EACTC,QAAQ,EACRC,uBAAuB,KAAK,EACb;IACf,MAAMC,uBAAuBN,eAAeE,oBAAoB;IAChE,MAAMK,gBAAgBP,eAAeG,aAAa;IAClD,MAAMK,eAAeT,iBAAiBK;IAEtC,MAAMK,UAAUJ,uBACZP,KAAKY,KAAK,CAACC,IAAI,CAACL,sBAAsBC,eAAeC,gBACrDV,KAAKY,KAAK,CAACC,IAAI,CAACJ,iBAAiBD,sBAAsBE;IAE3D,OAAO;QACLC;QACAG,2BAA2BN;QAC3BO,oBAAoBN;QACpBO,mBAAmBN;IACrB;AACF"}
@@ -1,174 +0,0 @@
1
- import { getFileKey } from './getFileKey.js';
2
- import { describe, expect, it } from 'vitest';
3
- describe('getFileKey', ()=>{
4
- describe('non-composite mode (useCompositePrefixes: false)', ()=>{
5
- it('should use docPrefix when provided, ignoring collectionPrefix', ()=>{
6
- const result = getFileKey({
7
- collectionPrefix: 'collection',
8
- docPrefix: 'document',
9
- filename: 'test.png',
10
- useCompositePrefixes: false
11
- });
12
- expect(result).toEqual({
13
- fileKey: 'document/test.png',
14
- sanitizedCollectionPrefix: 'collection',
15
- sanitizedDocPrefix: 'document',
16
- sanitizedFilename: 'test.png'
17
- });
18
- });
19
- it('should fallback to collectionPrefix when docPrefix is empty', ()=>{
20
- const result = getFileKey({
21
- collectionPrefix: 'collection',
22
- docPrefix: '',
23
- filename: 'test.png',
24
- useCompositePrefixes: false
25
- });
26
- expect(result).toEqual({
27
- fileKey: 'collection/test.png',
28
- sanitizedCollectionPrefix: 'collection',
29
- sanitizedDocPrefix: '',
30
- sanitizedFilename: 'test.png'
31
- });
32
- });
33
- it('should fallback to collectionPrefix when docPrefix is undefined', ()=>{
34
- const result = getFileKey({
35
- collectionPrefix: 'collection',
36
- filename: 'test.png',
37
- useCompositePrefixes: false
38
- });
39
- expect(result).toEqual({
40
- fileKey: 'collection/test.png',
41
- sanitizedCollectionPrefix: 'collection',
42
- sanitizedDocPrefix: '',
43
- sanitizedFilename: 'test.png'
44
- });
45
- });
46
- it('should return only filename when both prefixes are empty', ()=>{
47
- const result = getFileKey({
48
- filename: 'test.png',
49
- useCompositePrefixes: false
50
- });
51
- expect(result).toEqual({
52
- fileKey: 'test.png',
53
- sanitizedCollectionPrefix: '',
54
- sanitizedDocPrefix: '',
55
- sanitizedFilename: 'test.png'
56
- });
57
- });
58
- });
59
- describe('composite mode (useCompositePrefixes: true)', ()=>{
60
- it('should combine collectionPrefix and docPrefix', ()=>{
61
- const result = getFileKey({
62
- collectionPrefix: 'collection',
63
- docPrefix: 'document',
64
- filename: 'test.png',
65
- useCompositePrefixes: true
66
- });
67
- expect(result).toEqual({
68
- fileKey: 'collection/document/test.png',
69
- sanitizedCollectionPrefix: 'collection',
70
- sanitizedDocPrefix: 'document',
71
- sanitizedFilename: 'test.png'
72
- });
73
- });
74
- it('should work with only collectionPrefix', ()=>{
75
- const result = getFileKey({
76
- collectionPrefix: 'collection',
77
- filename: 'test.png',
78
- useCompositePrefixes: true
79
- });
80
- expect(result).toEqual({
81
- fileKey: 'collection/test.png',
82
- sanitizedCollectionPrefix: 'collection',
83
- sanitizedDocPrefix: '',
84
- sanitizedFilename: 'test.png'
85
- });
86
- });
87
- it('should work with only docPrefix', ()=>{
88
- const result = getFileKey({
89
- docPrefix: 'document',
90
- filename: 'test.png',
91
- useCompositePrefixes: true
92
- });
93
- expect(result).toEqual({
94
- fileKey: 'document/test.png',
95
- sanitizedCollectionPrefix: '',
96
- sanitizedDocPrefix: 'document',
97
- sanitizedFilename: 'test.png'
98
- });
99
- });
100
- it('should return only filename when both prefixes are empty', ()=>{
101
- const result = getFileKey({
102
- filename: 'test.png',
103
- useCompositePrefixes: true
104
- });
105
- expect(result).toEqual({
106
- fileKey: 'test.png',
107
- sanitizedCollectionPrefix: '',
108
- sanitizedDocPrefix: '',
109
- sanitizedFilename: 'test.png'
110
- });
111
- });
112
- });
113
- describe('sanitization', ()=>{
114
- it('should remove path traversal segments from collectionPrefix', ()=>{
115
- const result = getFileKey({
116
- collectionPrefix: '../../../etc',
117
- filename: 'test.png',
118
- useCompositePrefixes: false
119
- });
120
- expect(result).toEqual({
121
- fileKey: 'etc/test.png',
122
- sanitizedCollectionPrefix: 'etc',
123
- sanitizedDocPrefix: '',
124
- sanitizedFilename: 'test.png'
125
- });
126
- expect(result.fileKey).not.toContain('..');
127
- });
128
- it('should remove path traversal segments from docPrefix', ()=>{
129
- const result = getFileKey({
130
- docPrefix: 'a/../../outside',
131
- filename: 'test.png',
132
- useCompositePrefixes: false
133
- });
134
- expect(result).toEqual({
135
- fileKey: 'a/outside/test.png',
136
- sanitizedCollectionPrefix: '',
137
- sanitizedDocPrefix: 'a/outside',
138
- sanitizedFilename: 'test.png'
139
- });
140
- expect(result.fileKey).not.toContain('..');
141
- });
142
- it('should remove control characters from prefixes', ()=>{
143
- const result = getFileKey({
144
- collectionPrefix: 'test\x00\x1fprefix',
145
- filename: 'test.png',
146
- useCompositePrefixes: false
147
- });
148
- expect(result).toEqual({
149
- fileKey: 'testprefix/test.png',
150
- sanitizedCollectionPrefix: 'testprefix',
151
- sanitizedDocPrefix: '',
152
- sanitizedFilename: 'test.png'
153
- });
154
- expect(result.fileKey).not.toMatch(/[\x00-\x1f]/);
155
- });
156
- it('should sanitize both prefixes in composite mode', ()=>{
157
- const result = getFileKey({
158
- collectionPrefix: '../collection',
159
- docPrefix: '../../doc',
160
- filename: 'test.png',
161
- useCompositePrefixes: true
162
- });
163
- expect(result).toEqual({
164
- fileKey: 'collection/doc/test.png',
165
- sanitizedCollectionPrefix: 'collection',
166
- sanitizedDocPrefix: 'doc',
167
- sanitizedFilename: 'test.png'
168
- });
169
- expect(result.fileKey).not.toContain('..');
170
- });
171
- });
172
- });
173
-
174
- //# sourceMappingURL=getFileKey.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utilities/getFileKey.spec.ts"],"sourcesContent":["import { getFileKey } from './getFileKey.js'\nimport { describe, expect, it } from 'vitest'\n\ndescribe('getFileKey', () => {\n describe('non-composite mode (useCompositePrefixes: false)', () => {\n it('should use docPrefix when provided, ignoring collectionPrefix', () => {\n const result = getFileKey({\n collectionPrefix: 'collection',\n docPrefix: 'document',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n fileKey: 'document/test.png',\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: 'document',\n sanitizedFilename: 'test.png',\n })\n })\n\n it('should fallback to collectionPrefix when docPrefix is empty', () => {\n const result = getFileKey({\n collectionPrefix: 'collection',\n docPrefix: '',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n fileKey: 'collection/test.png',\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n })\n })\n\n it('should fallback to collectionPrefix when docPrefix is undefined', () => {\n const result = getFileKey({\n collectionPrefix: 'collection',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n fileKey: 'collection/test.png',\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n })\n })\n\n it('should return only filename when both prefixes are empty', () => {\n const result = getFileKey({\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n fileKey: 'test.png',\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n })\n })\n })\n\n describe('composite mode (useCompositePrefixes: true)', () => {\n it('should combine collectionPrefix and docPrefix', () => {\n const result = getFileKey({\n collectionPrefix: 'collection',\n docPrefix: 'document',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n fileKey: 'collection/document/test.png',\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: 'document',\n sanitizedFilename: 'test.png',\n })\n })\n\n it('should work with only collectionPrefix', () => {\n const result = getFileKey({\n collectionPrefix: 'collection',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n fileKey: 'collection/test.png',\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n })\n })\n\n it('should work with only docPrefix', () => {\n const result = getFileKey({\n docPrefix: 'document',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n fileKey: 'document/test.png',\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: 'document',\n sanitizedFilename: 'test.png',\n })\n })\n\n it('should return only filename when both prefixes are empty', () => {\n const result = getFileKey({\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n fileKey: 'test.png',\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n })\n })\n })\n\n describe('sanitization', () => {\n it('should remove path traversal segments from collectionPrefix', () => {\n const result = getFileKey({\n collectionPrefix: '../../../etc',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n fileKey: 'etc/test.png',\n sanitizedCollectionPrefix: 'etc',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n })\n expect(result.fileKey).not.toContain('..')\n })\n\n it('should remove path traversal segments from docPrefix', () => {\n const result = getFileKey({\n docPrefix: 'a/../../outside',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n fileKey: 'a/outside/test.png',\n sanitizedCollectionPrefix: '',\n sanitizedDocPrefix: 'a/outside',\n sanitizedFilename: 'test.png',\n })\n expect(result.fileKey).not.toContain('..')\n })\n\n it('should remove control characters from prefixes', () => {\n const result = getFileKey({\n collectionPrefix: 'test\\x00\\x1fprefix',\n filename: 'test.png',\n useCompositePrefixes: false,\n })\n expect(result).toEqual({\n fileKey: 'testprefix/test.png',\n sanitizedCollectionPrefix: 'testprefix',\n sanitizedDocPrefix: '',\n sanitizedFilename: 'test.png',\n })\n expect(result.fileKey).not.toMatch(/[\\x00-\\x1f]/)\n })\n\n it('should sanitize both prefixes in composite mode', () => {\n const result = getFileKey({\n collectionPrefix: '../collection',\n docPrefix: '../../doc',\n filename: 'test.png',\n useCompositePrefixes: true,\n })\n expect(result).toEqual({\n fileKey: 'collection/doc/test.png',\n sanitizedCollectionPrefix: 'collection',\n sanitizedDocPrefix: 'doc',\n sanitizedFilename: 'test.png',\n })\n expect(result.fileKey).not.toContain('..')\n })\n })\n})\n"],"names":["getFileKey","describe","expect","it","result","collectionPrefix","docPrefix","filename","useCompositePrefixes","toEqual","fileKey","sanitizedCollectionPrefix","sanitizedDocPrefix","sanitizedFilename","not","toContain","toMatch"],"mappings":"AAAA,SAASA,UAAU,QAAQ,kBAAiB;AAC5C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7CF,SAAS,cAAc;IACrBA,SAAS,oDAAoD;QAC3DE,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ACrB;YACAX,OAAOE,OAAOM,OAAO,EAAEI,GAAG,CAACE,OAAO,CAAC;QACrC;QAEAb,GAAG,mDAAmD;YACpD,MAAMC,SAASJ,WAAW;gBACxBK,kBAAkB;gBAClBC,WAAW;gBACXC,UAAU;gBACVC,sBAAsB;YACxB;YACAN,OAAOE,QAAQK,OAAO,CAAC;gBACrBC,SAAS;gBACTC,2BAA2B;gBAC3BC,oBAAoB;gBACpBC,mBAAmB;YACrB;YACAX,OAAOE,OAAOM,OAAO,EAAEI,GAAG,CAACC,SAAS,CAAC;QACvC;IACF;AACF"}
@@ -1,105 +0,0 @@
1
- import { describe, expect, it, vi } from 'vitest';
2
- import { getFilePrefix } from './getFilePrefix.js';
3
- const makeReq = (docs = [])=>({
4
- payload: {
5
- find: vi.fn().mockResolvedValue({
6
- docs
7
- })
8
- }
9
- });
10
- const makeCollection = ()=>({
11
- slug: 'media',
12
- upload: {}
13
- });
14
- describe('getFilePrefix', ()=>{
15
- describe('prefixQueryParam shortcut', ()=>{
16
- it('should return prefixQueryParam immediately without querying the database', async ()=>{
17
- const req = makeReq();
18
- const result = await getFilePrefix({
19
- collection: makeCollection(),
20
- prefixQueryParam: 'uuid-prefix',
21
- filename: 'logo.png',
22
- req
23
- });
24
- expect(result).toBe('uuid-prefix');
25
- expect(req.payload.find).not.toHaveBeenCalled();
26
- });
27
- it('should return an empty string when prefixQueryParam is an empty string', async ()=>{
28
- const req = makeReq();
29
- const result = await getFilePrefix({
30
- collection: makeCollection(),
31
- prefixQueryParam: '',
32
- filename: 'logo.png',
33
- req
34
- });
35
- expect(result).toBe('');
36
- expect(req.payload.find).not.toHaveBeenCalled();
37
- });
38
- it('should reject multi-encoded values', async ()=>{
39
- const req = makeReq();
40
- const result = await getFilePrefix({
41
- collection: makeCollection(),
42
- prefixQueryParam: '%252e%252e%252fsecret%252f..%252fok',
43
- filename: 'logo.png',
44
- req
45
- });
46
- expect(result).toBe('');
47
- expect(req.payload.find).not.toHaveBeenCalled();
48
- });
49
- it('should reject malformed percent-encoding', async ()=>{
50
- const req = makeReq();
51
- const result = await getFilePrefix({
52
- collection: makeCollection(),
53
- prefixQueryParam: '%E0%A4%A',
54
- filename: 'logo.png',
55
- req
56
- });
57
- expect(result).toBe('');
58
- expect(req.payload.find).not.toHaveBeenCalled();
59
- });
60
- });
61
- describe('database fallback', ()=>{
62
- it('should query the database when prefixQueryParam is not provided', async ()=>{
63
- const req = makeReq([
64
- {
65
- prefix: 'db-prefix'
66
- }
67
- ]);
68
- const result = await getFilePrefix({
69
- collection: makeCollection(),
70
- filename: 'logo.png',
71
- req
72
- });
73
- expect(result).toBe('db-prefix');
74
- expect(req.payload.find).toHaveBeenCalledOnce();
75
- });
76
- it('should return empty string when no document is found', async ()=>{
77
- const req = makeReq([]);
78
- const result = await getFilePrefix({
79
- collection: makeCollection(),
80
- filename: 'logo.png',
81
- req
82
- });
83
- expect(result).toBe('');
84
- });
85
- it('should prioritize the upload reference prefix over the database query', async ()=>{
86
- const req = makeReq([
87
- {
88
- prefix: 'db-prefix'
89
- }
90
- ]);
91
- const result = await getFilePrefix({
92
- collection: makeCollection(),
93
- uploadReference: {
94
- prefix: 'context-prefix'
95
- },
96
- filename: 'logo.png',
97
- req
98
- });
99
- expect(result).toBe('context-prefix');
100
- expect(req.payload.find).not.toHaveBeenCalled();
101
- });
102
- });
103
- });
104
-
105
- //# sourceMappingURL=getFilePrefix.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utilities/getFilePrefix.spec.ts"],"sourcesContent":["import { describe, expect, it, vi } from 'vitest'\n\nimport type { CollectionConfig, PayloadRequest } from 'payload'\n\nimport { getFilePrefix } from './getFilePrefix.js'\n\nconst makeReq = (docs: unknown[] = []) =>\n ({\n payload: {\n find: vi.fn().mockResolvedValue({ docs }),\n },\n }) as unknown as PayloadRequest\n\nconst makeCollection = (): CollectionConfig =>\n ({ slug: 'media', upload: {} }) as unknown as CollectionConfig\n\ndescribe('getFilePrefix', () => {\n describe('prefixQueryParam shortcut', () => {\n it('should return prefixQueryParam immediately without querying the database', async () => {\n const req = makeReq()\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n prefixQueryParam: 'uuid-prefix',\n filename: 'logo.png',\n req,\n })\n\n expect(result).toBe('uuid-prefix')\n expect(req.payload.find).not.toHaveBeenCalled()\n })\n\n it('should return an empty string when prefixQueryParam is an empty string', async () => {\n const req = makeReq()\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n prefixQueryParam: '',\n filename: 'logo.png',\n req,\n })\n\n expect(result).toBe('')\n expect(req.payload.find).not.toHaveBeenCalled()\n })\n\n it('should reject multi-encoded values', async () => {\n const req = makeReq()\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n prefixQueryParam: '%252e%252e%252fsecret%252f..%252fok',\n filename: 'logo.png',\n req,\n })\n\n expect(result).toBe('')\n expect(req.payload.find).not.toHaveBeenCalled()\n })\n\n it('should reject malformed percent-encoding', async () => {\n const req = makeReq()\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n prefixQueryParam: '%E0%A4%A',\n filename: 'logo.png',\n req,\n })\n\n expect(result).toBe('')\n expect(req.payload.find).not.toHaveBeenCalled()\n })\n })\n\n describe('database fallback', () => {\n it('should query the database when prefixQueryParam is not provided', async () => {\n const req = makeReq([{ prefix: 'db-prefix' }])\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n filename: 'logo.png',\n req,\n })\n\n expect(result).toBe('db-prefix')\n expect(req.payload.find).toHaveBeenCalledOnce()\n })\n\n it('should return empty string when no document is found', async () => {\n const req = makeReq([])\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n filename: 'logo.png',\n req,\n })\n\n expect(result).toBe('')\n })\n\n it('should prioritize the upload reference prefix over the database query', async () => {\n const req = makeReq([{ prefix: 'db-prefix' }])\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n uploadReference: { prefix: 'context-prefix' },\n filename: 'logo.png',\n req,\n })\n\n expect(result).toBe('context-prefix')\n expect(req.payload.find).not.toHaveBeenCalled()\n })\n })\n})\n"],"names":["describe","expect","it","vi","getFilePrefix","makeReq","docs","payload","find","fn","mockResolvedValue","makeCollection","slug","upload","req","result","collection","prefixQueryParam","filename","toBe","not","toHaveBeenCalled","prefix","toHaveBeenCalledOnce","uploadReference"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAIjD,SAASC,aAAa,QAAQ,qBAAoB;AAElD,MAAMC,UAAU,CAACC,OAAkB,EAAE,GAClC,CAAA;QACCC,SAAS;YACPC,MAAML,GAAGM,EAAE,GAAGC,iBAAiB,CAAC;gBAAEJ;YAAK;QACzC;IACF,CAAA;AAEF,MAAMK,iBAAiB,IACpB,CAAA;QAAEC,MAAM;QAASC,QAAQ,CAAC;IAAE,CAAA;AAE/Bb,SAAS,iBAAiB;IACxBA,SAAS,6BAA6B;QACpCE,GAAG,4EAA4E;YAC7E,MAAMY,MAAMT;YAEZ,MAAMU,SAAS,MAAMX,cAAc;gBACjCY,YAAYL;gBACZM,kBAAkB;gBAClBC,UAAU;gBACVJ;YACF;YAEAb,OAAOc,QAAQI,IAAI,CAAC;YACpBlB,OAAOa,IAAIP,OAAO,CAACC,IAAI,EAAEY,GAAG,CAACC,gBAAgB;QAC/C;QAEAnB,GAAG,0EAA0E;YAC3E,MAAMY,MAAMT;YAEZ,MAAMU,SAAS,MAAMX,cAAc;gBACjCY,YAAYL;gBACZM,kBAAkB;gBAClBC,UAAU;gBACVJ;YACF;YAEAb,OAAOc,QAAQI,IAAI,CAAC;YACpBlB,OAAOa,IAAIP,OAAO,CAACC,IAAI,EAAEY,GAAG,CAACC,gBAAgB;QAC/C;QAEAnB,GAAG,sCAAsC;YACvC,MAAMY,MAAMT;YAEZ,MAAMU,SAAS,MAAMX,cAAc;gBACjCY,YAAYL;gBACZM,kBAAkB;gBAClBC,UAAU;gBACVJ;YACF;YAEAb,OAAOc,QAAQI,IAAI,CAAC;YACpBlB,OAAO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