@payloadcms/plugin-cloud-storage 4.0.0-internal.688c4d0 → 4.0.0-internal.77191e5
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 +2 -0
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +2 -0
- 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 +41 -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 +79 -22
- 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 +178 -128
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +35 -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/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 +13 -2
- package/dist/utilities/resolveSignedURLKey.d.ts.map +1 -1
- package/dist/utilities/resolveSignedURLKey.js +43 -9
- 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 +4 -4
- 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
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { AllowList, PluginOptions } from './types.js'\n\nimport { getFields } from './fields/getFields.js'\nimport { getAfterChangeHook } from './hooks/afterChange.js'\nimport { getAfterDeleteHook } from './hooks/afterDelete.js'\nimport { getPreserveFileDataHook } from './hooks/preserveFileData.js'\n\n// This plugin extends all targeted collections by offloading uploaded files\n// to cloud storage instead of solely storing files locally.\n\n// It is based on an adapter approach, where adapters can be written for any cloud provider.\n// Adapters are responsible for providing four actions that this plugin will use:\n// 1. handleUpload, 2. handleDelete, 3. generateURL, 4. staticHandler\n\n// Optionally, the adapter can specify any Webpack config overrides if they are necessary.\n\nexport const cloudStoragePlugin =\n (pluginOptions: PluginOptions) =>\n (incomingConfig: Config): Config => {\n const {\n alwaysInsertFields,\n collections: allCollectionOptions,\n enabled,\n useCompositePrefixes,\n } = pluginOptions\n const config = { ...incomingConfig }\n\n // If disabled but alwaysInsertFields is true, only insert fields without full plugin functionality\n if (enabled === false) {\n if (alwaysInsertFields) {\n return {\n ...config,\n collections: (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options) {\n // If adapter is provided, use it to get fields\n const adapter = options.adapter\n ? options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n : undefined\n\n const fields = getFields({\n adapter,\n alwaysInsertFields: true,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n return {\n ...existingCollection,\n fields,\n }\n }\n\n return existingCollection\n }),\n }\n }\n\n return config\n }\n\n const initFunctions: Array<() => void> = []\n\n return {\n ...config,\n collections: (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options?.adapter) {\n const adapter = options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n\n if (adapter.onInit) {\n initFunctions.push(adapter.onInit)\n }\n\n const fields = getFields({\n adapter,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n const handlers = [\n ...(typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.handlers)\n ? existingCollection.upload.handlers\n : []),\n ]\n\n if (!options.disablePayloadAccessControl) {\n handlers.push(adapter.staticHandler)\n // Else if disablePayloadAccessControl: true and clientUploads is used\n // Build the \"proxied\" handler that responses only when the file was requested by client upload in addDataAndFileToRequest\n } else if (adapter.clientUploads) {\n handlers.push((req, args) => {\n if ('clientUploadContext' in args.params) {\n return adapter.staticHandler(req, args)\n }\n })\n }\n\n const getSkipSafeFetchSetting = (): AllowList | boolean => {\n if (options.disablePayloadAccessControl) {\n return true\n }\n const isBooleanTrueSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n existingCollection.upload.skipSafeFetch === true\n\n const isAllowListSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n\n if (isBooleanTrueSkipSafeFetch) {\n return true\n } else if (isAllowListSkipSafeFetch) {\n const existingSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n ? existingCollection.upload.skipSafeFetch\n : []\n\n const hasExactLocalhostMatch = existingSkipSafeFetch.some((entry) => {\n const entryKeys = Object.keys(entry)\n return entryKeys.length === 1 && entry.hostname === 'localhost'\n })\n\n const localhostEntry =\n process.env.NODE_ENV !== 'production' && !hasExactLocalhostMatch\n ? [{ hostname: 'localhost' }]\n : []\n\n return [...existingSkipSafeFetch, ...localhostEntry]\n }\n\n if (process.env.NODE_ENV !== 'production') {\n return [{ hostname: 'localhost' }]\n }\n\n return false\n }\n\n return {\n ...existingCollection,\n fields,\n hooks: {\n ...(existingCollection.hooks || {}),\n afterChange: [\n ...(existingCollection.hooks?.afterChange || []),\n getAfterChangeHook({ adapter, collection: existingCollection }),\n ],\n afterDelete: [\n ...(existingCollection.hooks?.afterDelete || []),\n getAfterDeleteHook({ adapter, collection: existingCollection }),\n ],\n beforeChange: [\n ...(existingCollection.hooks?.beforeChange || []),\n getPreserveFileDataHook(),\n ],\n },\n upload: {\n ...(typeof existingCollection.upload === 'object' ? existingCollection.upload : {}),\n adapter: adapter.name,\n disableLocalStorage:\n typeof options.disableLocalStorage === 'boolean'\n ? options.disableLocalStorage\n : true,\n handlers,\n skipSafeFetch: getSkipSafeFetchSetting(),\n },\n }\n }\n\n return existingCollection\n }),\n onInit: async (payload) => {\n initFunctions.forEach((fn) => fn())\n if (config.onInit) {\n await config.onInit(payload)\n }\n },\n }\n }\n"],"names":["getFields","getAfterChangeHook","getAfterDeleteHook","getPreserveFileDataHook","cloudStoragePlugin","pluginOptions","incomingConfig","alwaysInsertFields","collections","allCollectionOptions","enabled","useCompositePrefixes","config","map","existingCollection","options","slug","adapter","collection","prefix","undefined","fields","disablePayloadAccessControl","generateFileURL","initFunctions","onInit","push","handlers","upload","Array","isArray","staticHandler","clientUploads","req","args","params","getSkipSafeFetchSetting","isBooleanTrueSkipSafeFetch","skipSafeFetch","isAllowListSkipSafeFetch","existingSkipSafeFetch","hasExactLocalhostMatch","some","entry","entryKeys","Object","keys","length","hostname","localhostEntry","process","env","NODE_ENV","hooks","afterChange","afterDelete","beforeChange","name","disableLocalStorage","payload","forEach","fn"],"mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AACj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BACN/B;4BACAW,eAAeF;wBACjB;oBACF;gBACF;gBAEA,OAAOtB;YACT;YACAW,QAAQ,OAAOkC;gBACbnC,cAAcoC,OAAO,CAAC,CAACC,KAAOA;gBAC9B,IAAIjD,OAAOa,MAAM,EAAE;oBACjB,MAAMb,OAAOa,MAAM,CAACkC;gBACtB;YACF;QACF;IACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nimport type { Adapter, AllowList, PluginOptions } from './types.js'\n\nimport { getFields } from './fields/getFields.js'\nimport { getAfterChangeHook } from './hooks/afterChange.js'\nimport { getAfterDeleteHook } from './hooks/afterDelete.js'\nimport { getNormalizeUploadPrefixHook } from './hooks/normalizeUploadPrefix.js'\nimport { getPreserveFileDataHook } from './hooks/preserveFileData.js'\n\n// This plugin extends all targeted collections by offloading uploaded files\n// to cloud storage instead of solely storing files locally.\n\n// It is based on an adapter approach, where adapters can be written for any cloud provider.\n// Adapters are responsible for providing four actions that this plugin will use:\n// 1. handleUpload, 2. handleDelete, 3. generateURL, 4. staticHandler\n\n// Optionally, the adapter can specify any Webpack config overrides if they are necessary.\n\nexport const cloudStoragePlugin =\n (pluginOptions: PluginOptions) =>\n (incomingConfig: Config): Config => {\n const { collections: allCollectionOptions, enabled, useCompositePrefixes } = pluginOptions\n const config = { ...incomingConfig }\n\n // If disabled, only insert fields (e.g. prefix) without full plugin functionality,\n // so the collection schema stays consistent across environments.\n if (enabled === false) {\n return {\n ...config,\n collections: (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options) {\n // If adapter is provided, use it to get fields\n const adapter = options.adapter\n ? options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n : undefined\n\n const fields = getFields({\n adapter,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n return {\n ...existingCollection,\n fields,\n }\n }\n\n return existingCollection\n }),\n }\n }\n\n const initFunctions: Array<() => Promise<void> | void> = []\n const endpointPaths = new Map<Adapter, string>()\n\n const collections = (config.collections || []).map((existingCollection) => {\n const options = allCollectionOptions[existingCollection.slug]\n\n if (options?.adapter) {\n const adapter = options.adapter({\n collection: existingCollection,\n prefix: options.prefix,\n })\n\n if (adapter.onInit) {\n initFunctions.push(adapter.onInit)\n }\n\n let uploadInstructions\n\n if (adapter.uploadInstructions) {\n const { adminHandler, enabled, endpoint, ...instructions } = adapter.uploadInstructions\n let endpointPath = endpointPaths.get(options.adapter)\n\n if (enabled && endpoint && !endpointPath) {\n const endpointCount =\n config.endpoints?.filter(({ path }) => path?.startsWith(endpoint.path)).length || 0\n\n endpointPath = endpointCount ? `${endpoint.path}-${endpointCount}` : endpoint.path\n config.endpoints ??= []\n config.endpoints.push({\n handler: endpoint.handler,\n method: 'post',\n path: endpointPath,\n })\n endpointPaths.set(options.adapter, endpointPath)\n }\n\n if (enabled && adminHandler) {\n config.admin ??= {}\n config.admin.components ??= {}\n config.admin.components.providers ??= []\n config.admin.components.providers.push({\n clientProps: {\n collectionSlug: existingCollection.slug,\n endpointPath,\n prefix: options.prefix,\n props: adminHandler.props || {},\n },\n path: adminHandler.path,\n })\n }\n\n if (enabled) {\n uploadInstructions = instructions\n } else if (adminHandler) {\n /** Avoid importMap.js differences when client uploads vary between dev and production. */\n config.admin ??= {}\n config.admin.dependencies ??= {}\n config.admin.dependencies[adminHandler.path] = {\n type: 'component',\n path: adminHandler.path,\n }\n }\n }\n\n const fields = getFields({\n adapter,\n collection: existingCollection,\n disablePayloadAccessControl: options.disablePayloadAccessControl,\n generateFileURL: options.generateFileURL,\n prefix: options.prefix,\n useCompositePrefixes,\n })\n\n const handlers = [\n ...(typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.handlers)\n ? existingCollection.upload.handlers\n : []),\n ]\n\n if (!options.disablePayloadAccessControl) {\n handlers.push(adapter.staticHandler)\n // Else if disablePayloadAccessControl: true and upload instructions are used\n // Build the \"proxied\" handler that responds only when addDataAndFileToRequest fetches the uploaded file\n } else if (uploadInstructions) {\n handlers.push((req, args) => {\n if ('uploadReference' in args.params) {\n return adapter.staticHandler(req, args)\n }\n })\n }\n\n const getSkipSafeFetchSetting = (): AllowList | boolean => {\n const isBooleanTrueSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n existingCollection.upload.skipSafeFetch === true\n\n const isAllowListSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n\n if (isBooleanTrueSkipSafeFetch) {\n return true\n } else if (isAllowListSkipSafeFetch) {\n const existingSkipSafeFetch =\n typeof existingCollection.upload === 'object' &&\n Array.isArray(existingCollection.upload.skipSafeFetch)\n ? existingCollection.upload.skipSafeFetch\n : []\n\n const hasExactLocalhostMatch = existingSkipSafeFetch.some((entry) => {\n const entryKeys = Object.keys(entry)\n return entryKeys.length === 1 && entry.hostname === 'localhost'\n })\n\n const localhostEntry =\n process.env.NODE_ENV !== 'production' && !hasExactLocalhostMatch\n ? [{ hostname: 'localhost' }]\n : []\n\n return [...existingSkipSafeFetch, ...localhostEntry]\n }\n\n if (process.env.NODE_ENV !== 'production') {\n return [{ hostname: 'localhost' }]\n }\n\n return false\n }\n\n return {\n ...existingCollection,\n fields,\n hooks: {\n ...(existingCollection.hooks || {}),\n afterChange: [\n ...(existingCollection.hooks?.afterChange || []),\n getAfterChangeHook({\n adapter,\n collection: existingCollection,\n collectionPrefix: options.prefix,\n useCompositePrefixes,\n }),\n ],\n afterDelete: [\n ...(existingCollection.hooks?.afterDelete || []),\n getAfterDeleteHook({\n adapter,\n collection: existingCollection,\n collectionPrefix: options.prefix,\n useCompositePrefixes,\n }),\n ],\n beforeChange: [\n ...(existingCollection.hooks?.beforeChange || []),\n getNormalizeUploadPrefixHook({\n collectionPrefix: options.prefix,\n useCompositePrefixes,\n }),\n getPreserveFileDataHook(),\n ],\n },\n upload: {\n ...(typeof existingCollection.upload === 'object' ? existingCollection.upload : {}),\n adapter: adapter.name,\n ...(uploadInstructions && {\n uploadInstructions,\n }),\n disableLocalStorage:\n typeof options.disableLocalStorage === 'boolean' ? options.disableLocalStorage : true,\n handlers,\n skipSafeFetch: getSkipSafeFetchSetting(),\n },\n }\n }\n\n return existingCollection\n })\n\n return {\n ...config,\n collections,\n onInit: async (payload) => {\n // Await each init so a provisioning failure fails Payload startup\n // instead of becoming an unhandled rejection.\n await Promise.all(initFunctions.map((fn) => fn()))\n if (config.onInit) {\n await config.onInit(payload)\n }\n },\n }\n }\n"],"names":["getFields","getAfterChangeHook","getAfterDeleteHook","getNormalizeUploadPrefixHook","getPreserveFileDataHook","cloudStoragePlugin","pluginOptions","incomingConfig","collections","allCollectionOptions","enabled","useCompositePrefixes","config","map","existingCollection","options","slug","adapter","collection","prefix","undefined","fields","disablePayloadAccessControl","generateFileURL","initFunctions","endpointPaths","Map","onInit","push","uploadInstructions","adminHandler","endpoint","instructions","endpointPath","get","endpointCount","endpoints","filter","path","startsWith","length","handler","method","set","admin","components","providers","clientProps","collectionSlug","props","dependencies","type","handlers","upload","Array","isArray","staticHandler","req","args","params","getSkipSafeFetchSetting","isBooleanTrueSkipSafeFetch","skipSafeFetch","isAllowListSkipSafeFetch","existingSkipSafeFetch","hasExactLocalhostMatch","some","entry","entryKeys","Object","keys","hostname","localhostEntry","process","env","NODE_ENV","hooks","afterChange","collectionPrefix","afterDelete","beforeChange","name","disableLocalStorage","payload","Promise","all","fn"],"mappings":"AAIA,SAASA,SAAS,QAAQ,wBAAuB;AACjD,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,kBAAkB,QAAQ,yBAAwB;AAC3D,SAASC,4BAA4B,QAAQ,mCAAkC;AAC/E,SAASC,uBAAuB,QAAQ,8BAA6B;AAErE,4EAA4E;AAC5E,4DAA4D;AAE5D,4FAA4F;AAC5F,iFAAiF;AACjF,qEAAqE;AAErE,0FAA0F;AAE1F,OAAO,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AK,YAAYnE,QAAQmE,mBAAmB,GAAG;wBACnF9B;wBACAU,eAAeF;oBACjB;gBACF;YACF;YAEA,OAAO9C;QACT;QAEA,OAAO;YACL,GAAGF,MAAM;YACTJ;YACAmB,QAAQ,OAAOwD;gBACb,kEAAkE;gBAClE,8CAA8C;gBAC9C,MAAMC,QAAQC,GAAG,CAAC7D,cAAcX,GAAG,CAAC,CAACyE,KAAOA;gBAC5C,IAAI1E,OAAOe,MAAM,EAAE;oBACjB,MAAMf,OAAOe,MAAM,CAACwD;gBACtB;YACF;QACF;IACF,EAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
import type { CollectionConfig, Field, FileData, ImageSize, PayloadRequest, TypeWithID, UploadCollectionSlug } from 'payload';
|
|
1
|
+
import type { CollectionConfig, Field, FileData, ImageSize, PayloadHandler, PayloadRequest, TypeWithID, UploadCollectionSlug, UploadInstructionsAccess, UploadInstructionsCapability } from 'payload';
|
|
2
2
|
export interface File {
|
|
3
3
|
buffer: Buffer;
|
|
4
|
-
clientUploadContext?: unknown;
|
|
5
4
|
filename: string;
|
|
6
5
|
filesize: number;
|
|
7
6
|
mimeType: string;
|
|
8
7
|
tempFilePath?: string;
|
|
8
|
+
uploadReference?: unknown;
|
|
9
9
|
}
|
|
10
|
-
export type ClientUploadsAccess = (args: {
|
|
11
|
-
collectionSlug: UploadCollectionSlug;
|
|
12
|
-
req: PayloadRequest;
|
|
13
|
-
}) => boolean | Promise<boolean>;
|
|
14
10
|
export type ClientUploadsConfig = {
|
|
15
|
-
access?:
|
|
11
|
+
access?: UploadInstructionsAccess;
|
|
16
12
|
} | boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Reference to a client-uploaded object, returned by an upload handler and
|
|
15
|
+
* submitted with the document. Always carries the signed receipt; `prefix`
|
|
16
|
+
* locates the stored object.
|
|
17
|
+
*/
|
|
18
|
+
export type UploadReference = {
|
|
19
|
+
_objectKey?: string;
|
|
20
|
+
prefix: string;
|
|
21
|
+
signedReceipt: `${string}.${string}`;
|
|
22
|
+
};
|
|
17
23
|
export type HandleUpload = (args: {
|
|
18
|
-
clientUploadContext: unknown;
|
|
19
24
|
collection: CollectionConfig;
|
|
20
25
|
data: any;
|
|
21
26
|
file: File;
|
|
22
27
|
req: PayloadRequest;
|
|
28
|
+
/**
|
|
29
|
+
* Pre-resolved storage path (`_objectKey` folded in, contained beneath the collection prefix).
|
|
30
|
+
*/
|
|
31
|
+
storageFilePath: string;
|
|
23
32
|
}) => Partial<FileData & TypeWithID> | Promise<Partial<FileData & TypeWithID>> | Promise<void> | void;
|
|
24
33
|
export interface TypeWithPrefix {
|
|
25
34
|
prefix?: string;
|
|
@@ -29,6 +38,10 @@ export type HandleDelete = (args: {
|
|
|
29
38
|
doc: FileData & TypeWithID & TypeWithPrefix;
|
|
30
39
|
filename: string;
|
|
31
40
|
req: PayloadRequest;
|
|
41
|
+
/**
|
|
42
|
+
* Pre-resolved storage path of the object to delete.
|
|
43
|
+
*/
|
|
44
|
+
storageFilePath: string;
|
|
32
45
|
}) => Promise<void> | void;
|
|
33
46
|
export type GenerateURL = (args: {
|
|
34
47
|
collection: CollectionConfig;
|
|
@@ -40,14 +53,13 @@ export type StaticHandler = (req: PayloadRequest, args: {
|
|
|
40
53
|
doc?: TypeWithID;
|
|
41
54
|
headers?: Headers;
|
|
42
55
|
params: {
|
|
43
|
-
clientUploadContext?: unknown;
|
|
44
56
|
collection: string;
|
|
45
57
|
filename: string;
|
|
46
58
|
prefix?: string;
|
|
59
|
+
uploadReference?: unknown;
|
|
47
60
|
};
|
|
48
61
|
}) => Promise<Response> | Response;
|
|
49
62
|
export interface GeneratedAdapter {
|
|
50
|
-
clientUploads?: ClientUploadsConfig;
|
|
51
63
|
/**
|
|
52
64
|
* Additional fields to be injected into the base collection and image sizes
|
|
53
65
|
*/
|
|
@@ -59,8 +71,20 @@ export interface GeneratedAdapter {
|
|
|
59
71
|
handleDelete: HandleDelete;
|
|
60
72
|
handleUpload: HandleUpload;
|
|
61
73
|
name: string;
|
|
62
|
-
onInit?: () => void;
|
|
74
|
+
onInit?: () => Promise<void> | void;
|
|
63
75
|
staticHandler: StaticHandler;
|
|
76
|
+
/** Generates upload instructions when supported. */
|
|
77
|
+
uploadInstructions?: {
|
|
78
|
+
adminHandler?: {
|
|
79
|
+
path: string;
|
|
80
|
+
props?: Record<string, unknown>;
|
|
81
|
+
};
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
endpoint?: {
|
|
84
|
+
handler: PayloadHandler;
|
|
85
|
+
path: `/${string}`;
|
|
86
|
+
};
|
|
87
|
+
} & UploadInstructionsCapability;
|
|
64
88
|
}
|
|
65
89
|
export type Adapter = (args: {
|
|
66
90
|
collection: CollectionConfig;
|
|
@@ -87,16 +111,6 @@ export interface CollectionOptions {
|
|
|
87
111
|
prefix?: string;
|
|
88
112
|
}
|
|
89
113
|
export interface PluginOptions {
|
|
90
|
-
/**
|
|
91
|
-
* When enabled, fields (like the prefix field) will always be inserted into
|
|
92
|
-
* the collection schema regardless of whether the plugin is enabled. This
|
|
93
|
-
* ensures a consistent schema across all environments.
|
|
94
|
-
*
|
|
95
|
-
* This will be enabled by default in Payload v4.
|
|
96
|
-
*
|
|
97
|
-
* @default false
|
|
98
|
-
*/
|
|
99
|
-
alwaysInsertFields?: boolean;
|
|
100
114
|
collections: Partial<Record<UploadCollectionSlug, CollectionOptions>>;
|
|
101
115
|
/**
|
|
102
116
|
* Whether or not to enable the plugin
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACR,SAAS,EACT,cAAc,EACd,UAAU,EACV,oBAAoB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAC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AC,EAAE,OAAO,CAAA;CAC/B"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n FileData,\n ImageSize,\n PayloadRequest,\n TypeWithID,\n UploadCollectionSlug,\n} from 'payload'\n\nexport interface File {\n buffer: Buffer\n
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n CollectionConfig,\n Field,\n FileData,\n ImageSize,\n PayloadHandler,\n PayloadRequest,\n TypeWithID,\n UploadCollectionSlug,\n UploadInstructionsAccess,\n UploadInstructionsCapability,\n} from 'payload'\n\nexport interface File {\n buffer: Buffer\n filename: string\n filesize: number\n mimeType: string\n tempFilePath?: string\n uploadReference?: unknown\n}\n\nexport type ClientUploadsConfig = { access?: UploadInstructionsAccess } | boolean\n\n/**\n * Reference to a client-uploaded object, returned by an upload handler and\n * submitted with the document. Always carries the signed receipt; `prefix`\n * locates the stored object.\n */\nexport type UploadReference = {\n _objectKey?: string\n prefix: string\n signedReceipt: `${string}.${string}`\n}\n\nexport type HandleUpload = (args: {\n collection: CollectionConfig\n data: any\n file: File\n req: PayloadRequest\n /**\n * Pre-resolved storage path (`_objectKey` folded in, contained beneath the collection prefix).\n */\n storageFilePath: string\n}) =>\n | Partial<FileData & TypeWithID>\n | Promise<Partial<FileData & TypeWithID>>\n | Promise<void>\n | void\n\nexport interface TypeWithPrefix {\n prefix?: string\n}\n\nexport type HandleDelete = (args: {\n collection: CollectionConfig\n doc: FileData & TypeWithID & TypeWithPrefix\n filename: string\n req: PayloadRequest\n /**\n * Pre-resolved storage path of the object to delete.\n */\n storageFilePath: string\n}) => Promise<void> | void\n\nexport type GenerateURL = (args: {\n collection: CollectionConfig\n data: any\n filename: string\n prefix?: string\n}) => Promise<string> | string\n\nexport type StaticHandler = (\n req: PayloadRequest,\n args: {\n doc?: TypeWithID\n headers?: Headers\n params: { collection: string; filename: string; prefix?: string; uploadReference?: unknown }\n },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n /**\n * Additional fields to be injected into the base collection and image sizes\n */\n fields?: Field[]\n /**\n * Generates the public URL for a file\n */\n generateURL?: GenerateURL\n handleDelete: HandleDelete\n handleUpload: HandleUpload\n name: string\n onInit?: () => Promise<void> | void\n staticHandler: StaticHandler\n /** Generates upload instructions when supported. */\n uploadInstructions?: {\n adminHandler?: {\n path: string\n props?: Record<string, unknown>\n }\n enabled: boolean\n endpoint?: {\n handler: PayloadHandler\n path: `/${string}`\n }\n } & UploadInstructionsCapability\n}\n\nexport type Adapter = (args: { collection: CollectionConfig; prefix?: string }) => GeneratedAdapter\n\nexport type AllowList = Array<{\n hostname: string\n pathname?: string\n port?: string\n protocol?: 'http' | 'https'\n search?: string\n}>\n\nexport type GenerateFileURL = (args: {\n collection: CollectionConfig\n filename: string\n prefix?: string\n size?: ImageSize\n}) => Promise<string> | string\n\nexport interface CollectionOptions {\n adapter: Adapter | null\n disableLocalStorage?: boolean\n disablePayloadAccessControl?: true\n generateFileURL?: GenerateFileURL\n prefix?: string\n}\n\nexport interface PluginOptions {\n collections: Partial<Record<UploadCollectionSlug, CollectionOptions>>\n /**\n * Whether or not to enable the plugin\n *\n * Default: true\n */\n enabled?: boolean\n /**\n * When true (compositional prefixes), the stored `prefix` field is only the\n * document-level segment; the collection prefix comes from plugin options and\n * must not be pre-filled as the field default.\n *\n * Set by storage adapters that support compositional prefixes (e.g. S3, Azure, R2, Vercel Blob, GCS).\n *\n * @default false\n */\n useCompositePrefixes?: boolean\n}\n"],"names":[],"mappings":"AAsIA,WAkBC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.
|
|
3
|
+
*/
|
|
4
|
+
export declare const buildPrefixWithObjectKey: ({ objectKey, prefix, }: {
|
|
5
|
+
objectKey?: string;
|
|
6
|
+
prefix?: string;
|
|
7
|
+
}) => string;
|
|
8
|
+
//# sourceMappingURL=buildPrefixWithObjectKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildPrefixWithObjectKey.d.ts","sourceRoot":"","sources":["../../src/utilities/buildPrefixWithObjectKey.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,wBAAwB,2BAGlC;IACD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,KAAG,MASH,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { sanitizePrefix } from './sanitizePrefix.js';
|
|
2
|
+
/**
|
|
3
|
+
* Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.
|
|
4
|
+
*/ export const buildPrefixWithObjectKey = ({ objectKey, prefix })=>{
|
|
5
|
+
const safePrefix = sanitizePrefix(prefix ?? '');
|
|
6
|
+
const safeObjectKey = sanitizePrefix(objectKey ?? '');
|
|
7
|
+
if (safePrefix && safeObjectKey) {
|
|
8
|
+
return `${safePrefix}/${safeObjectKey}`;
|
|
9
|
+
}
|
|
10
|
+
return safePrefix || safeObjectKey;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=buildPrefixWithObjectKey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildPrefixWithObjectKey.ts"],"sourcesContent":["import { sanitizePrefix } from './sanitizePrefix.js'\n\n/**\n * Joins the semantic prefix and the `_objectKey` segment into the object's folder; either may be empty.\n */\nexport const buildPrefixWithObjectKey = ({\n objectKey,\n prefix,\n}: {\n objectKey?: string\n prefix?: string\n}): string => {\n const safePrefix = sanitizePrefix(prefix ?? '')\n const safeObjectKey = sanitizePrefix(objectKey ?? '')\n\n if (safePrefix && safeObjectKey) {\n return `${safePrefix}/${safeObjectKey}`\n }\n\n return safePrefix || safeObjectKey\n}\n"],"names":["sanitizePrefix","buildPrefixWithObjectKey","objectKey","prefix","safePrefix","safeObjectKey"],"mappings":"AAAA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD;;CAEC,GACD,OAAO,MAAMC,2BAA2B,CAAC,EACvCC,SAAS,EACTC,MAAM,EAIP;IACC,MAAMC,aAAaJ,eAAeG,UAAU;IAC5C,MAAME,gBAAgBL,eAAeE,aAAa;IAElD,IAAIE,cAAcC,eAAe;QAC/B,OAAO,GAAGD,WAAW,CAAC,EAAEC,eAAe;IACzC;IAEA,OAAOD,cAAcC;AACvB,EAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
type BuildFilePathDataArgs = {
|
|
2
|
+
collectionPrefix?: string;
|
|
3
|
+
docPrefix?: string;
|
|
4
|
+
filename: string;
|
|
5
|
+
useCompositePrefixes?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type BuildFilePathDataResult = {
|
|
8
|
+
sanitizedCollectionPrefix: string;
|
|
9
|
+
sanitizedDocPrefix: string;
|
|
10
|
+
sanitizedFilename: string;
|
|
11
|
+
/**
|
|
12
|
+
* The full path to the file within the storage backend.
|
|
13
|
+
*/
|
|
14
|
+
storageFilePath: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function isStoragePathWithinCollectionPrefix({ collectionPrefix, docPrefix, }: {
|
|
17
|
+
collectionPrefix?: string;
|
|
18
|
+
docPrefix: string;
|
|
19
|
+
}): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Resolves where a new upload must be stored, without needing a filename.
|
|
22
|
+
*
|
|
23
|
+
* In non-composite mode (useCompositePrefixes: false), docPrefix is treated as a complete prefix
|
|
24
|
+
* when it is already within collectionPrefix and is otherwise nested beneath collectionPrefix.
|
|
25
|
+
* In composite mode (useCompositePrefixes: true), the collection prefix is joined when the key is
|
|
26
|
+
* built, so the persisted document prefix stays relative to it.
|
|
27
|
+
*
|
|
28
|
+
* Prefix-only callers (such as the upload prefix hooks) use this directly; use
|
|
29
|
+
* {@link buildUploadStoragePathData} when a full object key is needed.
|
|
30
|
+
*/
|
|
31
|
+
export declare function buildUploadPrefix({ collectionPrefix, docPrefix, useCompositePrefixes, }: Omit<BuildFilePathDataArgs, 'filename'>): {
|
|
32
|
+
sanitizedCollectionPrefix: string;
|
|
33
|
+
sanitizedDocPrefix: string;
|
|
34
|
+
uploadPrefix: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Resolves a new upload destination beneath the configured collection prefix.
|
|
38
|
+
* Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildUploadStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes, }: BuildFilePathDataArgs): BuildFilePathDataResult;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the exact location represented by persisted upload metadata.
|
|
43
|
+
* Non-composite document prefixes historically override the collection prefix;
|
|
44
|
+
* keep that behavior for reads, URLs, and cleanup of pre-upgrade files.
|
|
45
|
+
* New writes must use buildUploadStoragePathData instead.
|
|
46
|
+
*/
|
|
47
|
+
export declare function buildStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes, }: BuildFilePathDataArgs): BuildFilePathDataResult;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=buildStoragePathData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildStoragePathData.d.ts","sourceRoot":"","sources":["../../src/utilities/buildStoragePathData.ts"],"names":[],"mappings":"AAKA,KAAK,qBAAqB,GAAG;IAC3B,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,uBAAuB,GAAG;IAC7B,yBAAyB,EAAE,MAAM,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,EAAE,MAAM,CAAA;IACzB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,wBAAgB,mCAAmC,CAAC,EAClD,gBAAgB,EAChB,SAAS,GACV,EAAE;IACD,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,EAAE,MAAM,CAAA;CAClB,GAAG,OAAO,CAQV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,gBAAgB,EAChB,SAAS,EACT,oBAA4B,GAC7B,EAAE,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,GAAG;IAC3C,yBAAyB,EAAE,MAAM,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,YAAY,EAAE,MAAM,CAAA;CACrB,CAiBA;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,qBAAqB,GAAG,uBAAuB,CAkBjD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,oBAA4B,GAC7B,EAAE,qBAAqB,GAAG,uBAAuB,CAcjD"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { sanitizeFilename } from 'payload/shared';
|
|
3
|
+
import { sanitizePrefix } from './sanitizePrefix.js';
|
|
4
|
+
export function isStoragePathWithinCollectionPrefix({ collectionPrefix, docPrefix }) {
|
|
5
|
+
const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '');
|
|
6
|
+
return !safeCollectionPrefix || docPrefix === safeCollectionPrefix || docPrefix.startsWith(`${safeCollectionPrefix}/`);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Resolves where a new upload must be stored, without needing a filename.
|
|
10
|
+
*
|
|
11
|
+
* In non-composite mode (useCompositePrefixes: false), docPrefix is treated as a complete prefix
|
|
12
|
+
* when it is already within collectionPrefix and is otherwise nested beneath collectionPrefix.
|
|
13
|
+
* In composite mode (useCompositePrefixes: true), the collection prefix is joined when the key is
|
|
14
|
+
* built, so the persisted document prefix stays relative to it.
|
|
15
|
+
*
|
|
16
|
+
* Prefix-only callers (such as the upload prefix hooks) use this directly; use
|
|
17
|
+
* {@link buildUploadStoragePathData} when a full object key is needed.
|
|
18
|
+
*/ export function buildUploadPrefix({ collectionPrefix, docPrefix, useCompositePrefixes = false }) {
|
|
19
|
+
const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '');
|
|
20
|
+
const safeDocPrefix = sanitizePrefix(docPrefix || '');
|
|
21
|
+
const uploadPrefix = safeDocPrefix && !isStoragePathWithinCollectionPrefix({
|
|
22
|
+
collectionPrefix: safeCollectionPrefix,
|
|
23
|
+
docPrefix: safeDocPrefix
|
|
24
|
+
}) ? path.posix.join(safeCollectionPrefix, safeDocPrefix) : safeDocPrefix || safeCollectionPrefix;
|
|
25
|
+
return {
|
|
26
|
+
sanitizedCollectionPrefix: safeCollectionPrefix,
|
|
27
|
+
sanitizedDocPrefix: !useCompositePrefixes && safeDocPrefix ? uploadPrefix : safeDocPrefix,
|
|
28
|
+
uploadPrefix
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a new upload destination beneath the configured collection prefix.
|
|
33
|
+
* Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.
|
|
34
|
+
*/ export function buildUploadStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes = false }) {
|
|
35
|
+
const { sanitizedCollectionPrefix, sanitizedDocPrefix, uploadPrefix } = buildUploadPrefix({
|
|
36
|
+
collectionPrefix,
|
|
37
|
+
docPrefix,
|
|
38
|
+
useCompositePrefixes
|
|
39
|
+
});
|
|
40
|
+
const safeFilename = sanitizeFilename(filename);
|
|
41
|
+
const storageFilePath = useCompositePrefixes ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, safeFilename) : path.posix.join(uploadPrefix, safeFilename);
|
|
42
|
+
return {
|
|
43
|
+
sanitizedCollectionPrefix,
|
|
44
|
+
sanitizedDocPrefix,
|
|
45
|
+
sanitizedFilename: safeFilename,
|
|
46
|
+
storageFilePath
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolves the exact location represented by persisted upload metadata.
|
|
51
|
+
* Non-composite document prefixes historically override the collection prefix;
|
|
52
|
+
* keep that behavior for reads, URLs, and cleanup of pre-upgrade files.
|
|
53
|
+
* New writes must use buildUploadStoragePathData instead.
|
|
54
|
+
*/ export function buildStoragePathData({ collectionPrefix, docPrefix, filename, useCompositePrefixes = false }) {
|
|
55
|
+
const sanitizedCollectionPrefix = sanitizePrefix(collectionPrefix || '');
|
|
56
|
+
const sanitizedDocPrefix = sanitizePrefix(docPrefix || '');
|
|
57
|
+
const sanitizedFilename = sanitizeFilename(filename);
|
|
58
|
+
const storageFilePath = useCompositePrefixes ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, sanitizedFilename) : path.posix.join(sanitizedDocPrefix || sanitizedCollectionPrefix, sanitizedFilename);
|
|
59
|
+
return {
|
|
60
|
+
sanitizedCollectionPrefix,
|
|
61
|
+
sanitizedDocPrefix,
|
|
62
|
+
sanitizedFilename,
|
|
63
|
+
storageFilePath
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=buildStoragePathData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/buildStoragePathData.ts"],"sourcesContent":["import path from 'path'\nimport { sanitizeFilename } from 'payload/shared'\n\nimport { sanitizePrefix } from './sanitizePrefix.js'\n\ntype BuildFilePathDataArgs = {\n collectionPrefix?: string\n docPrefix?: string\n filename: string\n useCompositePrefixes?: boolean\n}\n\ntype BuildFilePathDataResult = {\n sanitizedCollectionPrefix: string\n sanitizedDocPrefix: string\n sanitizedFilename: string\n /**\n * The full path to the file within the storage backend.\n */\n storageFilePath: string\n}\n\nexport function isStoragePathWithinCollectionPrefix({\n collectionPrefix,\n docPrefix,\n}: {\n collectionPrefix?: string\n docPrefix: string\n}): boolean {\n const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '')\n\n return (\n !safeCollectionPrefix ||\n docPrefix === safeCollectionPrefix ||\n docPrefix.startsWith(`${safeCollectionPrefix}/`)\n )\n}\n\n/**\n * Resolves where a new upload must be stored, without needing a filename.\n *\n * In non-composite mode (useCompositePrefixes: false), docPrefix is treated as a complete prefix\n * when it is already within collectionPrefix and is otherwise nested beneath collectionPrefix.\n * In composite mode (useCompositePrefixes: true), the collection prefix is joined when the key is\n * built, so the persisted document prefix stays relative to it.\n *\n * Prefix-only callers (such as the upload prefix hooks) use this directly; use\n * {@link buildUploadStoragePathData} when a full object key is needed.\n */\nexport function buildUploadPrefix({\n collectionPrefix,\n docPrefix,\n useCompositePrefixes = false,\n}: Omit<BuildFilePathDataArgs, 'filename'>): {\n sanitizedCollectionPrefix: string\n sanitizedDocPrefix: string\n uploadPrefix: string\n} {\n const safeCollectionPrefix = sanitizePrefix(collectionPrefix || '')\n const safeDocPrefix = sanitizePrefix(docPrefix || '')\n const uploadPrefix =\n safeDocPrefix &&\n !isStoragePathWithinCollectionPrefix({\n collectionPrefix: safeCollectionPrefix,\n docPrefix: safeDocPrefix,\n })\n ? path.posix.join(safeCollectionPrefix, safeDocPrefix)\n : safeDocPrefix || safeCollectionPrefix\n\n return {\n sanitizedCollectionPrefix: safeCollectionPrefix,\n sanitizedDocPrefix: !useCompositePrefixes && safeDocPrefix ? uploadPrefix : safeDocPrefix,\n uploadPrefix,\n }\n}\n\n/**\n * Resolves a new upload destination beneath the configured collection prefix.\n * Both prefixes are passed through {@link sanitizePrefix} so keys stay normalized.\n */\nexport function buildUploadStoragePathData({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes = false,\n}: BuildFilePathDataArgs): BuildFilePathDataResult {\n const { sanitizedCollectionPrefix, sanitizedDocPrefix, uploadPrefix } = buildUploadPrefix({\n collectionPrefix,\n docPrefix,\n useCompositePrefixes,\n })\n const safeFilename = sanitizeFilename(filename)\n\n const storageFilePath = useCompositePrefixes\n ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, safeFilename)\n : path.posix.join(uploadPrefix, safeFilename)\n\n return {\n sanitizedCollectionPrefix,\n sanitizedDocPrefix,\n sanitizedFilename: safeFilename,\n storageFilePath,\n }\n}\n\n/**\n * Resolves the exact location represented by persisted upload metadata.\n * Non-composite document prefixes historically override the collection prefix;\n * keep that behavior for reads, URLs, and cleanup of pre-upgrade files.\n * New writes must use buildUploadStoragePathData instead.\n */\nexport function buildStoragePathData({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes = false,\n}: BuildFilePathDataArgs): BuildFilePathDataResult {\n const sanitizedCollectionPrefix = sanitizePrefix(collectionPrefix || '')\n const sanitizedDocPrefix = sanitizePrefix(docPrefix || '')\n const sanitizedFilename = sanitizeFilename(filename)\n const storageFilePath = useCompositePrefixes\n ? path.posix.join(sanitizedCollectionPrefix, sanitizedDocPrefix, sanitizedFilename)\n : path.posix.join(sanitizedDocPrefix || sanitizedCollectionPrefix, sanitizedFilename)\n\n return {\n sanitizedCollectionPrefix,\n sanitizedDocPrefix,\n sanitizedFilename,\n storageFilePath,\n }\n}\n"],"names":["path","sanitizeFilename","sanitizePrefix","isStoragePathWithinCollectionPrefix","collectionPrefix","docPrefix","safeCollectionPrefix","startsWith","buildUploadPrefix","useCompositePrefixes","safeDocPrefix","uploadPrefix","posix","join","sanitizedCollectionPrefix","sanitizedDocPrefix","buildUploadStoragePathData","filename","safeFilename","storageFilePath","sanitizedFilename","buildStoragePathData"],"mappings":"AAAA,OAAOA,UAAU,OAAM;AACvB,SAASC,gBAAgB,QAAQ,iBAAgB;AAEjD,SAASC,cAAc,QAAQ,sBAAqB;AAmBpD,OAAO,SAASC,oCAAoC,EAClDC,gBAAgB,EAChBC,SAAS,EAIV;IACC,MAAMC,uBAAuBJ,eAAeE,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CAACC,2BAA2BC,oBAAoBK,qBAC/DpB,KAAKY,KAAK,CAACC,IAAI,CAACE,sBAAsBD,2BAA2BM;IAErE,OAAO;QACLN;QACAC;QACAK;QACAD;IACF;AACF"}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import type { CollectionConfig, PayloadRequest } from 'payload';
|
|
1
|
+
import type { CollectionConfig, PayloadRequest, TypeWithID } from 'payload';
|
|
2
2
|
/**
|
|
3
|
-
* Resolves the
|
|
4
|
-
* always returns a sanitized value.
|
|
3
|
+
* Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).
|
|
5
4
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Resolved values are passed through `sanitizePrefix`.
|
|
5
|
+
* An already-authorized `doc` wins outright. Otherwise an `uploadReference` is used (its
|
|
6
|
+
* `prefix` re-contained with {@link buildUploadStoragePathData}, since it hasn't been verified against
|
|
7
|
+
* a signed receipt by every adapter). Otherwise the document is resolved with
|
|
8
|
+
* `overrideAccess: false`, any query-param prefix only narrows that lookup, and `_objectKey`
|
|
9
|
+
* is read from the resolved document via `showHiddenFields`.
|
|
12
10
|
*/
|
|
13
|
-
export declare function getFilePrefix({
|
|
14
|
-
clientUploadContext?: unknown;
|
|
11
|
+
export declare function getFilePrefix({ collection, collectionPrefix, doc, filename, prefixQueryParam, req, uploadReference, useCompositePrefixes, }: {
|
|
15
12
|
collection: CollectionConfig;
|
|
13
|
+
collectionPrefix?: string;
|
|
14
|
+
doc?: {
|
|
15
|
+
_objectKey?: string;
|
|
16
|
+
prefix?: string;
|
|
17
|
+
} & TypeWithID;
|
|
16
18
|
filename: string;
|
|
19
|
+
/**
|
|
20
|
+
* Only narrows the access-controlled fallback lookup below; never trusted or
|
|
21
|
+
* returned directly. Prefer passing the access-checked document as `doc` instead.
|
|
22
|
+
*/
|
|
17
23
|
prefixQueryParam?: string;
|
|
18
24
|
req: PayloadRequest;
|
|
25
|
+
uploadReference?: unknown;
|
|
26
|
+
useCompositePrefixes?: boolean;
|
|
19
27
|
}): Promise<string>;
|
|
20
28
|
//# sourceMappingURL=getFilePrefix.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFilePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/getFilePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAgB,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"getFilePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/getFilePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAgB,MAAM,SAAS,CAAA;AAMzF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,UAAU,EACV,gBAAgB,EAChB,GAAG,EACH,QAAQ,EACR,gBAAgB,EAChB,GAAG,EACH,eAAe,EACf,oBAA4B,GAC7B,EAAE;IACD,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU,CAAA;IAC3D,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,GAAG,EAAE,cAAc,CAAA;IACnB,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,GAAG,OAAO,CAAC,MAAM,CAAC,CAqElB"}
|
|
@@ -1,46 +1,86 @@
|
|
|
1
|
+
import { buildPrefixWithObjectKey } from './buildPrefixWithObjectKey.js';
|
|
2
|
+
import { buildUploadStoragePathData } from './buildStoragePathData.js';
|
|
1
3
|
import { sanitizePrefix } from './sanitizePrefix.js';
|
|
2
4
|
/**
|
|
3
|
-
* Resolves the
|
|
4
|
-
* always returns a sanitized value.
|
|
5
|
+
* Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 buildPrefixWithObjectKey({
|
|
17
|
+
objectKey: doc._objectKey,
|
|
18
|
+
prefix: doc.prefix
|
|
19
|
+
});
|
|
15
20
|
}
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
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
|
}
|
|
36
|
+
// Reads without a query prefix or read-access constraints skip the endpoint's document lookup.
|
|
20
37
|
const imageSizes = collection?.upload?.imageSizes || [];
|
|
38
|
+
const filenameClause = {
|
|
39
|
+
or: [
|
|
40
|
+
{
|
|
41
|
+
filename: {
|
|
42
|
+
equals: filename
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
...imageSizes.map((imageSize)=>({
|
|
46
|
+
[`sizes.${imageSize.name}.filename`]: {
|
|
47
|
+
equals: filename
|
|
48
|
+
}
|
|
49
|
+
}))
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
// Only filter by prefix when the collection persists a `prefix` field (querying a missing field throws).
|
|
53
|
+
const hasPrefixField = collection.fields?.some((field)=>'name' in field && field.name === 'prefix');
|
|
54
|
+
const where = typeof prefixQueryParam === 'string' && hasPrefixField ? {
|
|
55
|
+
and: [
|
|
56
|
+
filenameClause,
|
|
57
|
+
{
|
|
58
|
+
prefix: {
|
|
59
|
+
equals: sanitizePrefix(prefixQueryParam)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
} : filenameClause;
|
|
21
64
|
const files = await req.payload.find({
|
|
22
65
|
collection: collection.slug,
|
|
23
66
|
depth: 0,
|
|
24
67
|
draft: true,
|
|
25
68
|
limit: 1,
|
|
69
|
+
overrideAccess: false,
|
|
26
70
|
pagination: false,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
]
|
|
40
|
-
}
|
|
71
|
+
req,
|
|
72
|
+
select: {
|
|
73
|
+
_objectKey: true,
|
|
74
|
+
prefix: true
|
|
75
|
+
},
|
|
76
|
+
showHiddenFields: true,
|
|
77
|
+
where
|
|
78
|
+
});
|
|
79
|
+
const found = files?.docs?.[0];
|
|
80
|
+
return buildPrefixWithObjectKey({
|
|
81
|
+
objectKey: found?._objectKey,
|
|
82
|
+
prefix: found?.prefix
|
|
41
83
|
});
|
|
42
|
-
const prefix = files?.docs?.[0]?.prefix;
|
|
43
|
-
return prefix ? sanitizePrefix(prefix) : '';
|
|
44
84
|
}
|
|
45
85
|
|
|
46
86
|
//# 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
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getFilePrefix.ts"],"sourcesContent":["import type { CollectionConfig, PayloadRequest, TypeWithID, UploadConfig } from 'payload'\n\nimport { buildPrefixWithObjectKey } from './buildPrefixWithObjectKey.js'\nimport { buildUploadStoragePathData } from './buildStoragePathData.js'\nimport { sanitizePrefix } from './sanitizePrefix.js'\n\n/**\n * Resolves the folder a stored object lives under (semantic `prefix` plus `_objectKey`).\n *\n * An already-authorized `doc` wins outright. Otherwise an `uploadReference` is used (its\n * `prefix` re-contained with {@link buildUploadStoragePathData}, since it hasn't been verified against\n * a signed receipt by every adapter). Otherwise the document is resolved with\n * `overrideAccess: false`, any query-param prefix only narrows that lookup, and `_objectKey`\n * is read from the resolved document via `showHiddenFields`.\n */\nexport async function getFilePrefix({\n collection,\n collectionPrefix,\n doc,\n filename,\n prefixQueryParam,\n req,\n uploadReference,\n useCompositePrefixes = false,\n}: {\n collection: CollectionConfig\n collectionPrefix?: string\n doc?: { _objectKey?: string; prefix?: string } & TypeWithID\n filename: string\n /**\n * Only narrows the access-controlled fallback lookup below; never trusted or\n * returned directly. Prefer passing the access-checked document as `doc` instead.\n */\n prefixQueryParam?: string\n req: PayloadRequest\n uploadReference?: unknown\n useCompositePrefixes?: boolean\n}): Promise<string> {\n // The serve path already loaded and authorized this document — trust it over any\n // client-supplied upload reference or query prefix.\n if (doc) {\n return buildPrefixWithObjectKey({ objectKey: doc._objectKey, prefix: doc.prefix })\n }\n\n // Upload instructions call handlers without a document yet. Re-contain the claimed\n // prefix — it hasn't been verified against a signed receipt by every adapter.\n if (\n uploadReference &&\n typeof uploadReference === 'object' &&\n 'prefix' in uploadReference &&\n typeof uploadReference.prefix === 'string'\n ) {\n const referenceObjectKey =\n '_objectKey' in uploadReference\n ? (uploadReference as { _objectKey?: string })._objectKey\n : undefined\n const containedPrefix = buildUploadStoragePathData({\n collectionPrefix,\n docPrefix: uploadReference.prefix,\n filename,\n useCompositePrefixes,\n }).sanitizedDocPrefix\n return buildPrefixWithObjectKey({ objectKey: referenceObjectKey, prefix: containedPrefix })\n }\n\n // Reads without a query prefix or read-access constraints skip the endpoint's document lookup.\n const imageSizes = (collection?.upload as UploadConfig)?.imageSizes || []\n\n const filenameClause = {\n or: [\n {\n filename: { equals: filename },\n },\n ...imageSizes.map((imageSize) => ({\n [`sizes.${imageSize.name}.filename`]: { equals: filename },\n })),\n ],\n }\n\n // Only filter by prefix when the collection persists a `prefix` field (querying a missing field throws).\n const hasPrefixField = collection.fields?.some(\n (field) => 'name' in field && field.name === 'prefix',\n )\n const where =\n typeof prefixQueryParam === 'string' && hasPrefixField\n ? { and: [filenameClause, { prefix: { equals: sanitizePrefix(prefixQueryParam) } }] }\n : filenameClause\n\n const files = await req.payload.find({\n collection: collection.slug,\n depth: 0,\n draft: true,\n limit: 1,\n overrideAccess: false,\n pagination: false,\n req,\n select: {\n _objectKey: true,\n prefix: true,\n },\n showHiddenFields: true,\n where,\n })\n\n const found = files?.docs?.[0] as { _objectKey?: string; prefix?: string } | undefined\n return buildPrefixWithObjectKey({ objectKey: found?._objectKey, prefix: found?.prefix })\n}\n"],"names":["buildPrefixWithObjectKey","buildUploadStoragePathData","sanitizePrefix","getFilePrefix","collection","collectionPrefix","doc","filename","prefixQueryParam","req","uploadReference","useCompositePrefixes","objectKey","_objectKey","prefix","referenceObjectKey","undefined","containedPrefix","docPrefix","sanitizedDocPrefix","imageSizes","upload","filenameClause","or","equals","map","imageSize","name","hasPrefixField","fields","some","field","where","and","files","payload","find","slug","depth","draft","limit","overrideAccess","pagination","select","showHiddenFields","found","docs"],"mappings":"AAEA,SAASA,wBAAwB,QAAQ,gCAA+B;AACxE,SAASC,0BAA0B,QAAQ,4BAA2B;AACtE,SAASC,cAAc,QAAQ,sBAAqB;AAEpD;;;;;;;;CAQC,GACD,OAAO,eAAeC,cAAc,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,OAAON,yBAAyB;YAAEY,WAAWN,IAAIO,UAAU;YAAEC,QAAQR,IAAIQ,MAAM;QAAC;IAClF;IAEA,mFAAmF;IACnF,8EAA8E;IAC9E,IACEJ,mBACA,OAAOA,oBAAoB,YAC3B,YAAYA,mBACZ,OAAOA,gBAAgBI,MAAM,KAAK,UAClC;QACA,MAAMC,qBACJ,gBAAgBL,kBACZ,AAACA,gBAA4CG,UAAU,GACvDG;QACN,MAAMC,kBAAkBhB,2BAA2B;YACjDI;YACAa,WAAWR,gBAAgBI,MAAM;YACjCP;YACAI;QACF,GAAGQ,kBAAkB;QACrB,OAAOnB,yBAAyB;YAAEY,WAAWG;YAAoBD,QAAQG;QAAgB;IAC3F;IAEA,+FAA+F;IAC/F,MAAMG,aAAa,AAAChB,YAAYiB,QAAyBD,cAAc,EAAE;IAEzE,MAAME,iBAAiB;QACrBC,IAAI;YACF;gBACEhB,UAAU;oBAAEiB,QAAQjB;gBAAS;YAC/B;eACGa,WAAWK,GAAG,CAAC,CAACC,YAAe,CAAA;oBAChC,CAAC,CAAC,MAAM,EAAEA,UAAUC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;wBAAEH,QAAQjB;oBAAS;gBAC3D,CAAA;SACD;IACH;IAEA,yGAAyG;IACzG,MAAMqB,iBAAiBxB,WAAWyB,MAAM,EAAEC,KACxC,CAACC,QAAU,UAAUA,SAASA,MAAMJ,IAAI,KAAK;IAE/C,MAAMK,QACJ,OAAOxB,qBAAqB,YAAYoB,iBACpC;QAAEK,KAAK;YAACX;YAAgB;gBAAER,QAAQ;oBAAEU,QAAQtB,eAAeM;gBAAkB;YAAE;SAAE;IAAC,IAClFc;IAEN,MAAMY,QAAQ,MAAMzB,IAAI0B,OAAO,CAACC,IAAI,CAAC;QACnChC,YAAYA,WAAWiC,IAAI;QAC3BC,OAAO;QACPC,OAAO;QACPC,OAAO;QACPC,gBAAgB;QAChBC,YAAY;QACZjC;QACAkC,QAAQ;YACN9B,YAAY;YACZC,QAAQ;QACV;QACA8B,kBAAkB;QAClBZ;IACF;IAEA,MAAMa,QAAQX,OAAOY,MAAM,CAAC,EAAE;IAC9B,OAAO9C,yBAAyB;QAAEY,WAAWiC,OAAOhC;QAAYC,QAAQ+B,OAAO/B;IAAO;AACxF"}
|
|
@@ -7,11 +7,11 @@ 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
|
|
@@ -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
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getIncomingFiles.ts"],"sourcesContent":["import type { FileData, PayloadRequest } from 'payload'\n\nimport type { File } from '../types.js'\n\ninterface CloudStorageContext {\n file: PayloadRequest['file']\n uploadSizes: PayloadRequest['payloadUploadSizes']\n}\n\nexport function getIncomingFiles({\n data,\n req,\n}: {\n data: Partial<FileData>\n req: PayloadRequest\n}): File[] {\n // Fall back to context if req.file was cleared\n const ctx = req.context?._payloadCloudStorage as CloudStorageContext | undefined\n const file = req.file ?? ctx?.file\n const payloadUploadSizes = req.payloadUploadSizes ?? ctx?.uploadSizes\n\n let files: File[] = []\n\n if (file && data.filename && data.mimeType) {\n const mainFile: File = {\n buffer: file.data,\n filename: data.filename,\n filesize: file.size,\n mimeType: data.mimeType,\n tempFilePath: file.tempFilePath,\n uploadReference: file.uploadReference,\n }\n\n files = [mainFile]\n\n if (data?.sizes) {\n Object.entries(data.sizes).forEach(([key, resizedFileData]) => {\n if (payloadUploadSizes?.[key] && resizedFileData.mimeType) {\n files = files.concat([\n {\n buffer: payloadUploadSizes[key],\n filename: `${resizedFileData.filename}`,\n filesize: payloadUploadSizes[key].length,\n mimeType: resizedFileData.mimeType,\n },\n ])\n }\n })\n }\n }\n\n return files\n}\n"],"names":["getIncomingFiles","data","req","ctx","context","_payloadCloudStorage","file","payloadUploadSizes","uploadSizes","files","filename","mimeType","mainFile","buffer","filesize","size","tempFilePath","uploadReference","sizes","Object","entries","forEach","key","resizedFileData","concat","length"],"mappings":"AASA,OAAO,SAASA,iBAAiB,EAC/BC,IAAI,EACJC,GAAG,EAIJ;IACC,+CAA+C;IAC/C,MAAMC,MAAMD,IAAIE,OAAO,EAAEC;IACzB,MAAMC,OAAOJ,IAAII,IAAI,IAAIH,KAAKG;IAC9B,MAAMC,qBAAqBL,IAAIK,kBAAkB,IAAIJ,KAAKK;IAE1D,IAAIC,QAAgB,EAAE;IAEtB,IAAIH,QAAQL,KAAKS,QAAQ,IAAIT,KAAKU,QAAQ,EAAE;QAC1C,MAAMC,WAAiB;YACrBC,QAAQP,KAAKL,IAAI;YACjBS,UAAUT,KAAKS,QAAQ;YACvBI,UAAUR,KAAKS,IAAI;YACnBJ,UAAUV,KAAKU,QAAQ;YACvBK,cAAcV,KAAKU,YAAY;YAC/BC,iBAAiBX,KAAKW,eAAe;QACvC;QAEAR,QAAQ;YAACG;SAAS;QAElB,IAAIX,MAAMiB,OAAO;YACfC,OAAOC,OAAO,CAACnB,KAAKiB,KAAK,EAAEG,OAAO,CAAC,CAAC,CAACC,KAAKC,gBAAgB;gBACxD,IAAIhB,oBAAoB,CAACe,IAAI,IAAIC,gBAAgBZ,QAAQ,EAAE;oBACzDF,QAAQA,MAAMe,MAAM,CAAC;wBACnB;4BACEX,QAAQN,kBAAkB,CAACe,IAAI;4BAC/BZ,UAAU,GAAGa,gBAAgBb,QAAQ,EAAE;4BACvCI,UAAUP,kBAAkB,CAACe,IAAI,CAACG,MAAM;4BACxCd,UAAUY,gBAAgBZ,QAAQ;wBACpC;qBACD;gBACH;YACF;QACF;IACF;IAEA,OAAOF;AACT"}
|