@payloadcms/plugin-cloud-storage 4.0.0-internal.4804abd → 4.0.0-internal.4c2ee12
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/LICENSE.md +1 -1
- package/README.md +2 -0
- package/dist/client/createClientUploadHandler.d.ts +8 -7
- package/dist/client/createClientUploadHandler.d.ts.map +1 -1
- package/dist/client/createClientUploadHandler.js +26 -22
- package/dist/client/createClientUploadHandler.js.map +1 -1
- 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 -2
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +1 -2
- 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 +118 -24
- package/dist/fields/getFields.js.map +1 -1
- package/dist/hooks/afterChange.d.ts +5 -1
- package/dist/hooks/afterChange.d.ts.map +1 -1
- package/dist/hooks/afterChange.js +138 -25
- 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 +26 -4
- package/dist/hooks/afterDelete.js.map +1 -1
- package/dist/hooks/afterRead.d.ts +6 -1
- package/dist/hooks/afterRead.d.ts.map +1 -1
- package/dist/hooks/afterRead.js +34 -7
- package/dist/hooks/afterRead.js.map +1 -1
- package/dist/hooks/beforeChange.d.ts +2 -1
- package/dist/hooks/beforeChange.d.ts.map +1 -1
- package/dist/hooks/beforeChange.js +18 -4
- 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/hooks/publicOriginalURL.d.ts +8 -0
- package/dist/hooks/publicOriginalURL.d.ts.map +1 -0
- package/dist/hooks/publicOriginalURL.js +34 -0
- package/dist/hooks/publicOriginalURL.js.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +203 -128
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +60 -21
- 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/createFileOperations.d.ts +13 -0
- package/dist/utilities/createFileOperations.d.ts.map +1 -0
- package/dist/utilities/createFileOperations.js +258 -0
- package/dist/utilities/createFileOperations.js.map +1 -0
- package/dist/utilities/getFilePrefix.d.ts +16 -11
- package/dist/utilities/getFilePrefix.d.ts.map +1 -1
- package/dist/utilities/getFilePrefix.js +86 -31
- package/dist/utilities/getFilePrefix.js.map +1 -1
- package/dist/utilities/getIncomingFiles.js +4 -4
- package/dist/utilities/getIncomingFiles.js.map +1 -1
- package/dist/utilities/getStorageLocationSelect.d.ts +9 -0
- package/dist/utilities/getStorageLocationSelect.d.ts.map +1 -0
- package/dist/utilities/getStorageLocationSelect.js +54 -0
- package/dist/utilities/getStorageLocationSelect.js.map +1 -0
- package/dist/utilities/resolveSignedURLKey.d.ts +13 -2
- package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
- package/dist/utilities/resolveSignedURLKey.js +53 -11
- 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
- package/dist/utilities/initClientUploads.d.ts +0 -13
- package/dist/utilities/initClientUploads.d.ts.map +0 -1
- package/dist/utilities/initClientUploads.js +0 -63
- package/dist/utilities/initClientUploads.js.map +0 -1
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
export const getFields = ({ alwaysInsertFields, collection, prefix, useCompositePrefixes = false })=>{
|
|
3
|
-
const baseURLField = {
|
|
4
|
-
name: 'url',
|
|
5
|
-
type: 'text',
|
|
6
|
-
admin: {
|
|
7
|
-
hidden: true,
|
|
8
|
-
readOnly: true
|
|
9
|
-
},
|
|
10
|
-
label: 'URL'
|
|
11
|
-
};
|
|
12
|
-
const basePrefixField = {
|
|
13
|
-
name: 'prefix',
|
|
14
|
-
type: 'text',
|
|
15
|
-
admin: {
|
|
16
|
-
hidden: true,
|
|
17
|
-
readOnly: true
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const fields = [
|
|
21
|
-
...collection.fields
|
|
22
|
-
];
|
|
23
|
-
// Inject a hook into all URL fields to generate URLs
|
|
24
|
-
let existingURLFieldIndex = -1;
|
|
25
|
-
const existingURLField = fields.find((existingField, i)=>{
|
|
26
|
-
if ('name' in existingField && existingField.name === 'url') {
|
|
27
|
-
existingURLFieldIndex = i;
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
});
|
|
32
|
-
if (existingURLFieldIndex > -1) {
|
|
33
|
-
fields.splice(existingURLFieldIndex, 1);
|
|
34
|
-
}
|
|
35
|
-
fields.push({
|
|
36
|
-
...baseURLField,
|
|
37
|
-
...existingURLField || {}
|
|
38
|
-
});
|
|
39
|
-
if (typeof collection.upload === 'object' && collection.upload.imageSizes) {
|
|
40
|
-
let existingSizesFieldIndex = -1;
|
|
41
|
-
const existingSizesField = fields.find((existingField, i)=>{
|
|
42
|
-
if ('name' in existingField && existingField.name === 'sizes') {
|
|
43
|
-
existingSizesFieldIndex = i;
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
});
|
|
48
|
-
if (existingSizesFieldIndex > -1) {
|
|
49
|
-
fields.splice(existingSizesFieldIndex, 1);
|
|
50
|
-
}
|
|
51
|
-
const sizesField = {
|
|
52
|
-
...existingSizesField || {},
|
|
53
|
-
name: 'sizes',
|
|
54
|
-
type: 'group',
|
|
55
|
-
admin: {
|
|
56
|
-
hidden: true
|
|
57
|
-
},
|
|
58
|
-
fields: collection.upload.imageSizes.map((size)=>{
|
|
59
|
-
const existingSizeField = existingSizesField?.fields.find((existingField)=>'name' in existingField && existingField.name === size.name);
|
|
60
|
-
const existingSizeURLField = existingSizeField?.fields.find((existingField)=>'name' in existingField && existingField.name === 'url');
|
|
61
|
-
return {
|
|
62
|
-
...existingSizeField,
|
|
63
|
-
name: size.name,
|
|
64
|
-
type: 'group',
|
|
65
|
-
fields: [
|
|
66
|
-
{
|
|
67
|
-
...existingSizeURLField || {},
|
|
68
|
-
...baseURLField
|
|
69
|
-
}
|
|
70
|
-
]
|
|
71
|
-
};
|
|
72
|
-
})
|
|
73
|
-
};
|
|
74
|
-
fields.push(sizesField);
|
|
75
|
-
}
|
|
76
|
-
// If prefix is enabled or alwaysInsertFields is true, save it to db
|
|
77
|
-
if (typeof prefix !== 'undefined' || alwaysInsertFields) {
|
|
78
|
-
let existingPrefixFieldIndex = -1;
|
|
79
|
-
const existingPrefixField = fields.find((existingField, i)=>{
|
|
80
|
-
if ('name' in existingField && existingField.name === 'prefix') {
|
|
81
|
-
existingPrefixFieldIndex = i;
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
return false;
|
|
85
|
-
});
|
|
86
|
-
if (existingPrefixFieldIndex > -1) {
|
|
87
|
-
fields.splice(existingPrefixFieldIndex, 1);
|
|
88
|
-
}
|
|
89
|
-
fields.push({
|
|
90
|
-
...basePrefixField,
|
|
91
|
-
...existingPrefixField || {},
|
|
92
|
-
defaultValue: existingPrefixField?.defaultValue ?? (useCompositePrefixes ? '' : prefix ? path.posix.join(prefix) : '')
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
return fields;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
//# sourceMappingURL=getFields.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/fields/getFields.ts"],"sourcesContent":["import type { CollectionConfig, Field, GroupField, TextField } from 'payload'\n\nimport path from 'path'\n\ninterface Args {\n /**\n * When true, always insert the prefix field regardless of whether a prefix is configured.\n */\n alwaysInsertFields?: boolean\n collection: CollectionConfig\n prefix?: string\n /**\n * When true, do not default the `prefix` field to the collection prefix; the\n * document field holds only the document-level segment.\n */\n useCompositePrefixes?: boolean\n}\n\nexport const getFields = ({\n alwaysInsertFields,\n collection,\n prefix,\n useCompositePrefixes = false,\n}: Args): Field[] => {\n const baseURLField: TextField = {\n name: 'url',\n type: 'text',\n admin: {\n hidden: true,\n readOnly: true,\n },\n label: 'URL',\n }\n\n const basePrefixField: TextField = {\n name: 'prefix',\n type: 'text',\n admin: {\n hidden: true,\n readOnly: true,\n },\n }\n\n const fields = [...collection.fields]\n\n // Inject a hook into all URL fields to generate URLs\n\n let existingURLFieldIndex = -1\n\n const existingURLField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'url') {\n existingURLFieldIndex = i\n return true\n }\n return false\n }) as TextField\n\n if (existingURLFieldIndex > -1) {\n fields.splice(existingURLFieldIndex, 1)\n }\n\n fields.push({\n ...baseURLField,\n ...(existingURLField || {}),\n } as TextField)\n\n if (typeof collection.upload === 'object' && collection.upload.imageSizes) {\n let existingSizesFieldIndex = -1\n\n const existingSizesField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'sizes') {\n existingSizesFieldIndex = i\n return true\n }\n\n return false\n }) as GroupField\n\n if (existingSizesFieldIndex > -1) {\n fields.splice(existingSizesFieldIndex, 1)\n }\n\n const sizesField: Field = {\n ...(existingSizesField || {}),\n name: 'sizes',\n type: 'group',\n admin: {\n hidden: true,\n },\n fields: collection.upload.imageSizes.map((size) => {\n const existingSizeField = existingSizesField?.fields.find(\n (existingField) => 'name' in existingField && existingField.name === size.name,\n ) as GroupField\n\n const existingSizeURLField = existingSizeField?.fields.find(\n (existingField) => 'name' in existingField && existingField.name === 'url',\n ) as GroupField\n\n return {\n ...existingSizeField,\n name: size.name,\n type: 'group',\n fields: [\n {\n ...(existingSizeURLField || {}),\n ...baseURLField,\n },\n ],\n } as Field\n }),\n }\n\n fields.push(sizesField)\n }\n\n // If prefix is enabled or alwaysInsertFields is true, save it to db\n if (typeof prefix !== 'undefined' || alwaysInsertFields) {\n let existingPrefixFieldIndex = -1\n\n const existingPrefixField = fields.find((existingField, i) => {\n if ('name' in existingField && existingField.name === 'prefix') {\n existingPrefixFieldIndex = i\n return true\n }\n return false\n }) as TextField\n\n if (existingPrefixFieldIndex > -1) {\n fields.splice(existingPrefixFieldIndex, 1)\n }\n\n fields.push({\n ...basePrefixField,\n ...(existingPrefixField || {}),\n defaultValue:\n existingPrefixField?.defaultValue ??\n (useCompositePrefixes ? '' : prefix ? path.posix.join(prefix) : ''),\n } as TextField)\n }\n\n return fields\n}\n"],"names":["path","getFields","alwaysInsertFields","collection","prefix","useCompositePrefixes","baseURLField","name","type","admin","hidden","readOnly","label","basePrefixField","fields","existingURLFieldIndex","existingURLField","find","existingField","i","splice","push","upload","imageSizes","existingSizesFieldIndex","existingSizesField","sizesField","map","size","existingSizeField","existingSizeURLField","existingPrefixFieldIndex","existingPrefixField","defaultValue","posix","join"],"mappings":"AAEA,OAAOA,UAAU,OAAM;AAgBvB,OAAO,MAAMC,YAAY,CAAC,EACxBC,kBAAkB,EAClBC,UAAU,EACVC,MAAM,EACNC,uBAAuB,KAAK,EACvB;IACL,MAAMC,eAA0B;QAC9BC,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,QAAQ;YACRC,UAAU;QACZ;QACAC,OAAO;IACT;IAEA,MAAMC,kBAA6B;QACjCN,MAAM;QACNC,MAAM;QACNC,OAAO;YACLC,QAAQ;YACRC,UAAU;QACZ;IACF;IAEA,MAAMG,SAAS;WAAIX,WAAWW,MAAM;KAAC;IAErC,qDAAqD;IAErD,IAAIC,wBAAwB,CAAC;IAE7B,MAAMC,mBAAmBF,OAAOG,IAAI,CAAC,CAACC,eAAeC;QACnD,IAAI,UAAUD,iBAAiBA,cAAcX,IAAI,KAAK,OAAO;YAC3DQ,wBAAwBI;YACxB,OAAO;QACT;QACA,OAAO;IACT;IAEA,IAAIJ,wBAAwB,CAAC,GAAG;QAC9BD,OAAOM,MAAM,CAACL,uBAAuB;IACvC;IAEAD,OAAOO,IAAI,CAAC;QACV,GAAGf,YAAY;QACf,GAAIU,oBAAoB,CAAC,CAAC;IAC5B;IAEA,IAAI,OAAOb,WAAWmB,MAAM,KAAK,YAAYnB,WAAWmB,MAAM,CAACC,UAAU,EAAE;QACzE,IAAIC,0BAA0B,CAAC;QAE/B,MAAMC,qBAAqBX,OAAOG,IAAI,CAAC,CA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qBAAqBC,gBACpB5B,CAAAA,uBAAuB,KAAKD,SAASJ,KAAKkC,KAAK,CAACC,IAAI,CAAC/B,UAAU,EAAC;QACrE;IACF;IAEA,OAAOU;AACT,EAAC"}
|
package/dist/admin/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAOhD,eAAO,MAAM,YAAY,GACtB,eAAe,aAAa,MAC5B,gBAAgB,MAAM,KAAG,MA+BzB,CAAA"}
|
package/dist/admin/index.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { getFields } from './fields/getFields.js';
|
|
2
|
-
// This is the admin plugin cloud-storage stubfile.
|
|
3
|
-
// It only extends the config that are required by the admin UI.
|
|
4
|
-
export const cloudStorage = (pluginOptions)=>(incomingConfig)=>{
|
|
5
|
-
const { alwaysInsertFields, collections: allCollectionOptions, enabled } = pluginOptions;
|
|
6
|
-
const config = {
|
|
7
|
-
...incomingConfig
|
|
8
|
-
};
|
|
9
|
-
// If disabled and alwaysInsertFields is not true, skip processing
|
|
10
|
-
if (enabled === false && !alwaysInsertFields) {
|
|
11
|
-
return config;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
...config,
|
|
15
|
-
collections: (config.collections || []).map((existingCollection)=>{
|
|
16
|
-
const options = allCollectionOptions[existingCollection.slug];
|
|
17
|
-
// Process if adapter exists OR if alwaysInsertFields is true and this collection is configured
|
|
18
|
-
if (options?.adapter || alwaysInsertFields && options) {
|
|
19
|
-
const fields = getFields({
|
|
20
|
-
alwaysInsertFields,
|
|
21
|
-
collection: existingCollection,
|
|
22
|
-
prefix: options.prefix
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
...existingCollection,
|
|
26
|
-
fields
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
return existingCollection;
|
|
30
|
-
})
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=index.js.map
|
package/dist/admin/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/admin/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { PluginOptions } from '../types.js'\n\nimport { getFields } from './fields/getFields.js'\n\n// This is the admin plugin cloud-storage stubfile.\n// It only extends the config that are required by the admin UI.\n\nexport const cloudStorage =\n (pluginOptions: PluginOptions) =>\n (incomingConfig: Config): Config => {\n const { alwaysInsertFields, collections: allCollectionOptions, enabled } = pluginOptions\n const config = { ...incomingConfig }\n\n // If disabled and alwaysInsertFields is not true, skip processing\n if (enabled === false && !alwaysInsertFields) {\n return config\n }\n\n return {\n ...config,\n collections: (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n // Process if adapter exists OR if alwaysInsertFields is true and this collection is configured\n if (options?.adapter || (alwaysInsertFields && options)) {\n const fields = getFields({\n alwaysInsertFields,\n collection: existingCollection,\n prefix: options.prefix,\n })\n\n return {\n ...existingCollection,\n fields,\n }\n }\n\n return existingCollection\n }),\n }\n }\n"],"names":["getFields","cloudStorage","pluginOptions","incomingConfig","alwaysInsertFields","collections","allCollectionOptions","enabled","config","map","existingCollection","options","slug","adapter","fields","collection","prefix"],"mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AAEjD,mDAAmD;AACnD,gEAAgE;AAEhE,OAAO,MAAMC,eACX,CAACC,gBACD,CAACC;QACC,MAAM,EAAEC,kBAAkB,EAAEC,aAAaC,oBAAoB,EAAEC,OAAO,EAAE,GAAGL;QAC3E,MAAMM,SAAS;YAAE,GAAGL,cAAc;QAAC;QAEnC,kEAAkE;QAClE,IAAII,YAAY,SAAS,CAACH,oBAAoB;YAC5C,OAAOI;QACT;QAEA,OAAO;YACL,GAAGA,MAAM;YACTH,aAAa,AAACG,CAAAA,OAAOH,WAAW,IAAI,EAAE,AAAD,EAAGI,GAAG,CAAC,CAACC;gBAC3C,MAAMC,UAAUL,oBAAoB,CAACI,mBAAmBE,IAAI,CAAC;gBAE7D,+FAA+F;gBAC/F,IAAID,SAASE,WAAYT,sBAAsBO,SAAU;oBACvD,MAAMG,SAASd,UAAU;wBACvBI;wBACAW,YAAYL;wBACZM,QAAQL,QAAQK,MAAM;oBACxB;oBAEA,OAAO;wBACL,GAAGN,kBAAkB;wBACrBI;oBACF;gBACF;gBAEA,OAAOJ;YACT;QACF;IACF,EAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
type GetFileKeyArgs = {
|
|
2
|
-
collectionPrefix?: string;
|
|
3
|
-
docPrefix?: string;
|
|
4
|
-
filename: string;
|
|
5
|
-
useCompositePrefixes?: boolean;
|
|
6
|
-
};
|
|
7
|
-
type GetFileKeyResult = {
|
|
8
|
-
fileKey: string;
|
|
9
|
-
sanitizedCollectionPrefix: string;
|
|
10
|
-
sanitizedDocPrefix: string;
|
|
11
|
-
sanitizedFilename: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Computes the file key (path) for storage.
|
|
15
|
-
*
|
|
16
|
-
* In non-composite mode (useCompositePrefixes: false), docPrefix overrides collectionPrefix.
|
|
17
|
-
* In composite mode (useCompositePrefixes: true), both are combined.
|
|
18
|
-
* Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.
|
|
19
|
-
*/
|
|
20
|
-
export declare function getFileKey({ collectionPrefix, docPrefix, filename, useCompositePrefixes, }: GetFileKeyArgs): GetFileKeyResult;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=getFileKey.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFileKey.d.ts","sourceRoot":"","sources":["../../src/utilities/getFileKey.ts"],"names":[],"mappings":"AAKA,KAAK,cAAc,GAAG;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,yBAAyB,EAAE,MAAM,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,EAAE,MAAM,CAAA;CAC1B,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EACzB,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,cAAc,GAAG,gBAAgB,CAenC"}
|
|
@@ -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,GAAG,iEAAiE;YAClE,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;QACF;QAEAV,GAAG,+DAA+D;YAChE,MAAMC,SAASJ,WAAW;gBACxBK,kBAAkB;gBAClBC,WAAW;gBACXC,UAAU;gBACVC,sBAAsB;YACxB;YACAN,OAAOE,QAAQK,OAAO,CAAC;gBACrBC,SAAS;gBACTC,2BAA2B;gBAC3BC,oBAAoB;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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 clientUploadContext prefix over database query', async ()=>{
|
|
86
|
-
const req = makeReq([
|
|
87
|
-
{
|
|
88
|
-
prefix: 'db-prefix'
|
|
89
|
-
}
|
|
90
|
-
]);
|
|
91
|
-
const result = await getFilePrefix({
|
|
92
|
-
clientUploadContext: {
|
|
93
|
-
prefix: 'context-prefix'
|
|
94
|
-
},
|
|
95
|
-
collection: makeCollection(),
|
|
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 clientUploadContext prefix over database query', async () => {\n const req = makeReq([{ prefix: 'db-prefix' }])\n\n const result = await getFilePrefix({\n clientUploadContext: { prefix: 'context-prefix' },\n collection: makeCollection(),\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","clientUploadContext"],"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;YAC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AEAb,OAAOc,QAAQI,IAAI,CAAC;QACtB;QAEAjB,GAAG,oEAAoE;YACrE,MAAMY,MAAMT,QAAQ;gBAAC;oBAAEiB,QAAQ;gBAAY;aAAE;YAE7C,MAAMP,SAAS,MAAMX,cAAc;gBACjCoB,qBAAqB;oBAAEF,QAAQ;gBAAiB;gBAChDN,YAAYL;gBACZO,UAAU;gBACVJ;YACF;YAEAb,OAAOc,QAAQI,IAAI,CAAC;YACpBlB,OAAOa,IAAIP,OAAO,CAACC,IAAI,EAAEY,GAAG,CAACC,gBAAgB;QAC/C;IACF;AACF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Config, PayloadHandler } from 'payload';
|
|
2
|
-
export declare const initClientUploads: <ExtraProps extends Record<string, unknown>, T>({ clientHandler, collections, config, enabled, extraClientHandlerProps, serverHandler, serverHandlerPath, }: {
|
|
3
|
-
/** Path to clientHandler component */
|
|
4
|
-
clientHandler: string;
|
|
5
|
-
collections: Record<string, T>;
|
|
6
|
-
config: Config;
|
|
7
|
-
enabled: boolean;
|
|
8
|
-
/** extra props to pass to the client handler */
|
|
9
|
-
extraClientHandlerProps?: (collection: T) => ExtraProps;
|
|
10
|
-
serverHandler: PayloadHandler;
|
|
11
|
-
serverHandlerPath: string;
|
|
12
|
-
}) => void;
|
|
13
|
-
//# sourceMappingURL=initClientUploads.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initClientUploads.d.ts","sourceRoot":"","sources":["../../src/utilities/initClientUploads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAErD,eAAO,MAAM,iBAAiB,GAAI,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,EAAE,6GAQ9E;IACD,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;IAChB,gDAAgD;IAChD,uBAAuB,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,KAAK,UAAU,CAAA;IACvD,aAAa,EAAE,cAAc,CAAA;IAC7B,iBAAiB,EAAE,MAAM,CAAA;CAC1B,SA8EA,CAAA"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export const initClientUploads = ({ clientHandler, collections, config, enabled, extraClientHandlerProps, serverHandler, serverHandlerPath })=>{
|
|
2
|
-
if (enabled) {
|
|
3
|
-
if (!config.endpoints) {
|
|
4
|
-
config.endpoints = [];
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Tracks how many times the same handler was already applied.
|
|
8
|
-
* This allows to apply the same plugin multiple times, for example
|
|
9
|
-
* to use different buckets for different collections.
|
|
10
|
-
*/ let handlerCount = 0;
|
|
11
|
-
for (const endpoint of config.endpoints){
|
|
12
|
-
// We want to match on 'path', 'path-1', 'path-2', etc.
|
|
13
|
-
if (endpoint.path?.startsWith(serverHandlerPath)) {
|
|
14
|
-
handlerCount++;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (handlerCount) {
|
|
18
|
-
serverHandlerPath = `${serverHandlerPath}-${handlerCount}`;
|
|
19
|
-
}
|
|
20
|
-
config.endpoints.push({
|
|
21
|
-
handler: serverHandler,
|
|
22
|
-
method: 'post',
|
|
23
|
-
path: serverHandlerPath
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
if (!config.admin) {
|
|
27
|
-
config.admin = {};
|
|
28
|
-
}
|
|
29
|
-
if (!config.admin.dependencies) {
|
|
30
|
-
config.admin.dependencies = {};
|
|
31
|
-
}
|
|
32
|
-
// Ensure client handler is always part of the import map, to avoid
|
|
33
|
-
// import map discrepancies between dev and prod
|
|
34
|
-
config.admin.dependencies[clientHandler] = {
|
|
35
|
-
type: 'function',
|
|
36
|
-
path: clientHandler
|
|
37
|
-
};
|
|
38
|
-
if (!config.admin.components) {
|
|
39
|
-
config.admin.components = {};
|
|
40
|
-
}
|
|
41
|
-
if (!config.admin.components.providers) {
|
|
42
|
-
config.admin.components.providers = [];
|
|
43
|
-
}
|
|
44
|
-
for(const collectionSlug in collections){
|
|
45
|
-
const collection = collections[collectionSlug];
|
|
46
|
-
let collectionPrefix;
|
|
47
|
-
if (collection && typeof collection === 'object' && 'prefix' in collection && typeof collection.prefix === 'string') {
|
|
48
|
-
collectionPrefix = collection.prefix;
|
|
49
|
-
}
|
|
50
|
-
config.admin.components.providers.push({
|
|
51
|
-
clientProps: {
|
|
52
|
-
collectionSlug,
|
|
53
|
-
enabled,
|
|
54
|
-
extra: extraClientHandlerProps ? extraClientHandlerProps(collection) : undefined,
|
|
55
|
-
prefix: collectionPrefix,
|
|
56
|
-
serverHandlerPath
|
|
57
|
-
},
|
|
58
|
-
path: clientHandler
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=initClientUploads.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/initClientUploads.ts"],"sourcesContent":["import type { Config, PayloadHandler } from 'payload'\n\nexport const initClientUploads = <ExtraProps extends Record<string, unknown>, T>({\n clientHandler,\n collections,\n config,\n enabled,\n extraClientHandlerProps,\n serverHandler,\n serverHandlerPath,\n}: {\n /** Path to clientHandler component */\n clientHandler: string\n collections: Record<string, T>\n config: Config\n enabled: boolean\n /** extra props to pass to the client handler */\n extraClientHandlerProps?: (collection: T) => ExtraProps\n serverHandler: PayloadHandler\n serverHandlerPath: string\n}) => {\n if (enabled) {\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n /**\n * Tracks how many times the same handler was already applied.\n * This allows to apply the same plugin multiple times, for example\n * to use different buckets for different collections.\n */\n let handlerCount = 0\n\n for (const endpoint of config.endpoints) {\n // We want to match on 'path', 'path-1', 'path-2', etc.\n if (endpoint.path?.startsWith(serverHandlerPath)) {\n handlerCount++\n }\n }\n\n if (handlerCount) {\n serverHandlerPath = `${serverHandlerPath}-${handlerCount}`\n }\n\n config.endpoints.push({\n handler: serverHandler,\n method: 'post',\n path: serverHandlerPath,\n })\n }\n\n if (!config.admin) {\n config.admin = {}\n }\n\n if (!config.admin.dependencies) {\n config.admin.dependencies = {}\n }\n // Ensure client handler is always part of the import map, to avoid\n // import map discrepancies between dev and prod\n config.admin.dependencies[clientHandler] = {\n type: 'function',\n path: clientHandler,\n }\n\n if (!config.admin.components) {\n config.admin.components = {}\n }\n\n if (!config.admin.components.providers) {\n config.admin.components.providers = []\n }\n\n for (const collectionSlug in collections) {\n const collection = collections[collectionSlug]\n\n let collectionPrefix: string | undefined\n\n if (\n collection &&\n typeof collection === 'object' &&\n 'prefix' in collection &&\n typeof collection.prefix === 'string'\n ) {\n collectionPrefix = collection.prefix\n }\n\n config.admin.components.providers.push({\n clientProps: {\n collectionSlug,\n enabled,\n extra: extraClientHandlerProps ? extraClientHandlerProps(collection!) : undefined,\n prefix: collectionPrefix,\n serverHandlerPath,\n },\n path: clientHandler,\n })\n }\n}\n"],"names":["initClientUploads","clientHandler","collections","config","enabled","extraClientHandlerProps","serverHandler","serverHandlerPath","endpoints","handlerCount","endpoint","path","startsWith","push","handler","method","admin","dependencies","type","components","providers","collectionSlug","collection","collectionPrefix","prefix","clientProps","extra","undefined"],"mappings":"AAEA,OAAO,MAAMA,oBAAoB,CAAgD,EAC/EC,aAAa,EACbC,WAAW,EACXC,MAAM,EACNC,OAAO,EACPC,uBAAuB,EACvBC,aAAa,EACbC,iBAAiB,EAWlB;IACC,IAAIH,SAAS;QACX,IAAI,CAACD,OAAOK,SAAS,EAAE;YACrBL,OAAOK,SAAS,GAAG,EAAE;QACvB;QAEA;;;;KAIC,GACD,IAAIC,eAAe;QAEnB,KAAK,MAAMC,YAAYP,OAAOK,SAAS,CAAE;YACvC,uDAAuD;YACvD,IAAIE,SAASC,IAAI,EA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