@payloadcms/plugin-cloud-storage 4.0.0-internal.435b2d6 → 4.0.0-internal.442e8b6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/utilities.d.ts +1 -1
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +1 -1
- package/dist/exports/utilities.js.map +1 -1
- package/dist/fields/getFields.d.ts +1 -5
- package/dist/fields/getFields.d.ts.map +1 -1
- package/dist/fields/getFields.js +47 -18
- package/dist/fields/getFields.js.map +1 -1
- package/dist/hooks/afterChange.d.ts +3 -1
- package/dist/hooks/afterChange.d.ts.map +1 -1
- package/dist/hooks/afterChange.js +77 -21
- package/dist/hooks/afterChange.js.map +1 -1
- package/dist/hooks/afterDelete.d.ts +3 -1
- package/dist/hooks/afterDelete.d.ts.map +1 -1
- package/dist/hooks/afterDelete.js +16 -2
- package/dist/hooks/afterDelete.js.map +1 -1
- package/dist/hooks/afterRead.d.ts.map +1 -1
- package/dist/hooks/afterRead.js +15 -2
- package/dist/hooks/afterRead.js.map +1 -1
- package/dist/hooks/beforeChange.d.ts.map +1 -1
- package/dist/hooks/beforeChange.js +12 -1
- package/dist/hooks/beforeChange.js.map +1 -1
- package/dist/hooks/normalizeUploadPrefix.d.ts +11 -0
- package/dist/hooks/normalizeUploadPrefix.d.ts.map +1 -0
- package/dist/hooks/normalizeUploadPrefix.js +42 -0
- package/dist/hooks/normalizeUploadPrefix.js.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +177 -168
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +23 -14
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/buildPrefixWithObjectKey.d.ts +8 -0
- package/dist/utilities/buildPrefixWithObjectKey.d.ts.map +1 -0
- package/dist/utilities/buildPrefixWithObjectKey.js +13 -0
- package/dist/utilities/buildPrefixWithObjectKey.js.map +1 -0
- package/dist/utilities/buildStoragePathData.d.ts +49 -0
- package/dist/utilities/buildStoragePathData.d.ts.map +1 -0
- package/dist/utilities/buildStoragePathData.js +67 -0
- package/dist/utilities/buildStoragePathData.js.map +1 -0
- package/dist/utilities/getFilePrefix.d.ts +19 -11
- package/dist/utilities/getFilePrefix.d.ts.map +1 -1
- package/dist/utilities/getFilePrefix.js +70 -30
- package/dist/utilities/getFilePrefix.js.map +1 -1
- package/dist/utilities/getIncomingFiles.js +2 -2
- package/dist/utilities/getIncomingFiles.js.map +1 -1
- package/dist/utilities/resolveSignedURLKey.d.ts +12 -1
- package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
- package/dist/utilities/resolveSignedURLKey.js +42 -8
- package/dist/utilities/resolveSignedURLKey.js.map +1 -1
- package/dist/utilities/sanitizePrefix.d.ts +1 -9
- package/dist/utilities/sanitizePrefix.d.ts.map +1 -1
- package/dist/utilities/sanitizePrefix.js +1 -21
- package/dist/utilities/sanitizePrefix.js.map +1 -1
- package/package.json +6 -6
- package/dist/admin/fields/getFields.d.ts +0 -17
- package/dist/admin/fields/getFields.d.ts.map +0 -1
- package/dist/admin/fields/getFields.js +0 -98
- package/dist/admin/fields/getFields.js.map +0 -1
- package/dist/admin/index.d.ts +0 -4
- package/dist/admin/index.d.ts.map +0 -1
- package/dist/admin/index.js +0 -34
- package/dist/admin/index.js.map +0 -1
- package/dist/utilities/getFileKey.d.ts +0 -22
- package/dist/utilities/getFileKey.d.ts.map +0 -1
- package/dist/utilities/getFileKey.js +0 -23
- package/dist/utilities/getFileKey.js.map +0 -1
- package/dist/utilities/getFileKey.spec.js +0 -174
- package/dist/utilities/getFileKey.spec.js.map +0 -1
- package/dist/utilities/getFilePrefix.spec.js +0 -105
- package/dist/utilities/getFilePrefix.spec.js.map +0 -1
|
@@ -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 direct upload 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
|
-
directUpload: {
|
|
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 direct upload prefix over the database query', async () => {\n const req = makeReq([{ prefix: 'db-prefix' }])\n\n const result = await getFilePrefix({\n collection: makeCollection(),\n directUpload: { 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","directUpload"],"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,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