@payloadcms/plugin-cloud-storage 4.0.0-internal.45cfa3d → 4.0.0-internal.4a6b4c3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/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
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,EACV,gBAAgB,EAChB,KAAK,EACL,QAAQ,EACR,oBAAoB,EACpB,SAAS,EACT,cAAc,EACd,cAAc,EACd,yBAAyB,EACzB,UAAU,EACV,oBAAoB,EACpB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,SAAS,CAAA;AAEhB,YAAY,EAAE,oBA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AAO,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAC,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IACnC,UAAU,EAAE,gBAAgB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,SAAS,CAAA;CACjB,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAA;AAE9B,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IACvB,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,2BAA2B,CAAC,EAAE,IAAI,CAAA;IAClC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,CAAC,CAAC,CAAA;IACrE;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;;;;OAQG;IACH,oBAAoB,CAAC,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 FileHandlerOperation,\n ImageSize,\n PayloadHandler,\n PayloadRequest,\n SanitizedCollectionConfig,\n TypeWithID,\n UploadCollectionSlug,\n UploadInstructionsAccess,\n UploadInstructionsCapability,\n} from 'payload'\n\nexport type { FileHandlerOperation } 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\n/** Deletes a stored object without requiring a saved document. */\nexport type DeleteFile = (args: {\n collection: CollectionConfig\n req: PayloadRequest\n /** Complete storage path, with prefixes and `_objectKey` already resolved. */\n storageFilePath: string\n}) => Promise<void> | void\n\n/** Complete storage keys are resolved before invoking a provider operation. */\nexport type FileOperationArgs = {\n collection: SanitizedCollectionConfig\n from: string\n mimeType?: string\n req: PayloadRequest\n to: string\n}\n\nexport type CopyFile = (args: FileOperationArgs) => Promise<void>\nexport type MoveFile = (args: FileOperationArgs) => Promise<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: {\n collection: string\n filename: string\n operation?: FileHandlerOperation\n prefix?: string\n uploadReference?: unknown\n }\n },\n) => Promise<Response> | Response\n\nexport interface GeneratedAdapter {\n /** Preserve object metadata and fail if `to` already exists. Rename retains `from` for history. */\n copyFile: CopyFile\n deleteFile: DeleteFile\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 moveFile?: MoveFile\n name: string\n onInit?: () => Promise<void> | void\n staticHandler: StaticHandler\n /** Reads source files by path when staging server-mediated uploads. */\n supportsTempFiles?: boolean\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":"AA0KA,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,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BAAkBV,uBACpBT,KAAKY,KAAK,CAACC,IAAI,CAACC,2BAA2BC,oBAAoBK,qBAC/DpB,KAAKY,KAAK,CAACC,IAAI,CAACE,sBAAsBD,2BAA2BM;IAErE,OAAO;QACLN;QACAC;QACAK;QACAD;IACF;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CollectionConfig, UploadConfig } from 'payload';
|
|
2
|
+
import type { GeneratedAdapter, GenerateFileURL } from '../types.js';
|
|
3
|
+
type Args = {
|
|
4
|
+
adapter: GeneratedAdapter;
|
|
5
|
+
collection: CollectionConfig;
|
|
6
|
+
collectionPrefix?: string;
|
|
7
|
+
disablePayloadAccessControl?: boolean;
|
|
8
|
+
generateFileURL?: GenerateFileURL;
|
|
9
|
+
useCompositePrefixes?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const createFileOperations: ({ adapter, collection, collectionPrefix, disablePayloadAccessControl, generateFileURL, useCompositePrefixes, }: Args) => NonNullable<UploadConfig['fileOperations']>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=createFileOperations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFileOperations.d.ts","sourceRoot":"","sources":["../../src/utilities/createFileOperations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAyB,YAAY,EAAE,MAAM,SAAS,CAAA;AAOpF,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AASpE,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,gBAAgB,CAAA;IACzB,UAAU,EAAE,gBAAgB,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,2BAA2B,CAAC,EAAE,OAAO,CAAA;IACrC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B,CAAA;AAED,eAAO,MAAM,oBAAoB,mHAO9B,IAAI,KAAG,WAAW,CAAC,YAAY,CAAC,gBAAgB,CAAC,CA+OnD,CAAA"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
4
|
+
import { deepCopyObjectSimple, generatePayloadFileURL } from 'payload';
|
|
5
|
+
import { buildPrefixWithObjectKey } from './buildPrefixWithObjectKey.js';
|
|
6
|
+
import { buildStoragePathData, buildUploadPrefix, buildUploadStoragePathData } from './buildStoragePathData.js';
|
|
7
|
+
export const createFileOperations = ({ adapter, collection, collectionPrefix, disablePayloadAccessControl, generateFileURL, useCompositePrefixes })=>{
|
|
8
|
+
if (typeof adapter.deleteFile !== 'function') {
|
|
9
|
+
throw new Error(`Storage adapter "${adapter.name}" must implement deleteFile for collection "${collection.slug}".`);
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
copy: async ({ from, req, to, trackStagedObject })=>{
|
|
13
|
+
await adapter.copyFile({
|
|
14
|
+
collection: req.payload.collections[collection.slug].config,
|
|
15
|
+
from,
|
|
16
|
+
req,
|
|
17
|
+
to
|
|
18
|
+
});
|
|
19
|
+
trackStagedObject({
|
|
20
|
+
key: to,
|
|
21
|
+
remove: async ()=>{
|
|
22
|
+
await adapter.deleteFile({
|
|
23
|
+
collection,
|
|
24
|
+
req,
|
|
25
|
+
storageFilePath: to
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
delete: async ({ key, req })=>{
|
|
31
|
+
await adapter.deleteFile({
|
|
32
|
+
collection,
|
|
33
|
+
req,
|
|
34
|
+
storageFilePath: key
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
hasLegacyFile: async ({ doc, req })=>{
|
|
38
|
+
if (typeof doc.filename !== 'string' || typeof doc.url !== 'string') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const docPrefix = typeof doc.prefix === 'string' ? doc.prefix : undefined;
|
|
42
|
+
const objectFolder = buildPrefixWithObjectKey({
|
|
43
|
+
objectKey: typeof doc._objectKey === 'string' ? doc._objectKey : undefined,
|
|
44
|
+
prefix: docPrefix
|
|
45
|
+
});
|
|
46
|
+
const expectedURL = async ({ filename, size })=>{
|
|
47
|
+
if (generateFileURL) {
|
|
48
|
+
return generateFileURL({
|
|
49
|
+
collection,
|
|
50
|
+
filename,
|
|
51
|
+
prefix: objectFolder,
|
|
52
|
+
size
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (disablePayloadAccessControl && adapter.generateURL) {
|
|
56
|
+
return adapter.generateURL({
|
|
57
|
+
collection,
|
|
58
|
+
data: doc,
|
|
59
|
+
filename,
|
|
60
|
+
prefix: objectFolder
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return generatePayloadFileURL({
|
|
64
|
+
collectionSlug: collection.slug,
|
|
65
|
+
config: req.payload.config,
|
|
66
|
+
filename,
|
|
67
|
+
relative: true
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
if (!isSameFileLocation({
|
|
71
|
+
actual: doc.url,
|
|
72
|
+
expected: await expectedURL({
|
|
73
|
+
filename: doc.filename
|
|
74
|
+
})
|
|
75
|
+
})) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (doc.variants && typeof doc.variants === 'object' && !Array.isArray(doc.variants)) {
|
|
79
|
+
for (const [sizeKey, size] of Object.entries(doc.variants)){
|
|
80
|
+
if (size && typeof size === 'object' && 'filename' in size && typeof size.filename === 'string') {
|
|
81
|
+
const imageSize = req.payload.collections[collection.slug]?.config.upload.variants?.find(({ name })=>name === sizeKey);
|
|
82
|
+
if (!('url' in size) || typeof size.url !== 'string' || !isSameFileLocation({
|
|
83
|
+
actual: size.url,
|
|
84
|
+
expected: await expectedURL({
|
|
85
|
+
filename: size.filename,
|
|
86
|
+
size: imageSize
|
|
87
|
+
})
|
|
88
|
+
})) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
},
|
|
96
|
+
resolveStorageKey: ({ _objectKey, filename, prefix })=>buildStoragePathData({
|
|
97
|
+
collectionPrefix,
|
|
98
|
+
docPrefix: buildPrefixWithObjectKey({
|
|
99
|
+
objectKey: _objectKey,
|
|
100
|
+
prefix
|
|
101
|
+
}),
|
|
102
|
+
filename,
|
|
103
|
+
useCompositePrefixes
|
|
104
|
+
}).storageFilePath,
|
|
105
|
+
...adapter.moveFile && {
|
|
106
|
+
move: async ({ from, req, to, trackStagedObject })=>{
|
|
107
|
+
await adapter.moveFile({
|
|
108
|
+
collection: req.payload.collections[collection.slug].config,
|
|
109
|
+
from,
|
|
110
|
+
req,
|
|
111
|
+
to
|
|
112
|
+
});
|
|
113
|
+
trackStagedObject({
|
|
114
|
+
key: to,
|
|
115
|
+
remove: ()=>adapter.moveFile({
|
|
116
|
+
collection: req.payload.collections[collection.slug].config,
|
|
117
|
+
from: to,
|
|
118
|
+
req,
|
|
119
|
+
to: from
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
stage: async ({ data, files, req, trackStagedObject })=>{
|
|
125
|
+
const uploadedNames = new Set();
|
|
126
|
+
const metadata = {};
|
|
127
|
+
const verifiedOriginal = req.context?._payloadVerifiedProviderOriginal;
|
|
128
|
+
for (const file of files){
|
|
129
|
+
const filename = path.basename(file.path);
|
|
130
|
+
const representations = [
|
|
131
|
+
data
|
|
132
|
+
];
|
|
133
|
+
if (data.original && typeof data.original === 'object') {
|
|
134
|
+
representations.push(data.original);
|
|
135
|
+
}
|
|
136
|
+
if (data.variants && typeof data.variants === 'object') {
|
|
137
|
+
representations.push(...Object.values(data.variants).filter((value)=>Boolean(value) && typeof value === 'object'));
|
|
138
|
+
}
|
|
139
|
+
const destinations = representations.filter((value)=>value.filename === filename);
|
|
140
|
+
// Provider-direct uploads already placed the source object at its verified location.
|
|
141
|
+
// A bounded content probe can still appear in files, but it is not a representation
|
|
142
|
+
// Payload should upload again.
|
|
143
|
+
if (!destinations.length && verifiedOriginal) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (!destinations.length) {
|
|
147
|
+
throw new Error(`No stored representation describes ${filename}`);
|
|
148
|
+
}
|
|
149
|
+
const prefixLocation = destinations.find((destination)=>typeof destination.prefix === 'string');
|
|
150
|
+
const objectKeyLocation = destinations.find((destination)=>typeof destination._objectKey === 'string');
|
|
151
|
+
const prefix = typeof prefixLocation?.prefix === 'string' ? prefixLocation.prefix : undefined;
|
|
152
|
+
const objectKey = typeof objectKeyLocation?._objectKey === 'string' ? objectKeyLocation._objectKey : undefined;
|
|
153
|
+
const prefixData = buildUploadPrefix({
|
|
154
|
+
collectionPrefix,
|
|
155
|
+
docPrefix: typeof prefix === 'string' ? prefix : undefined,
|
|
156
|
+
useCompositePrefixes
|
|
157
|
+
});
|
|
158
|
+
const uploadPrefix = useCompositePrefixes ? prefixData.sanitizedDocPrefix : prefixData.uploadPrefix;
|
|
159
|
+
for (const destination of destinations){
|
|
160
|
+
destination.prefix = uploadPrefix;
|
|
161
|
+
destination._objectKey = objectKey;
|
|
162
|
+
}
|
|
163
|
+
const docPrefix = buildPrefixWithObjectKey({
|
|
164
|
+
objectKey,
|
|
165
|
+
prefix: uploadPrefix
|
|
166
|
+
});
|
|
167
|
+
const dataForUpload = {
|
|
168
|
+
...data,
|
|
169
|
+
prefix: docPrefix
|
|
170
|
+
};
|
|
171
|
+
const storageFilePath = buildUploadStoragePathData({
|
|
172
|
+
collectionPrefix,
|
|
173
|
+
docPrefix,
|
|
174
|
+
filename,
|
|
175
|
+
useCompositePrefixes
|
|
176
|
+
}).storageFilePath;
|
|
177
|
+
if (uploadedNames.has(filename)) {
|
|
178
|
+
throw new Error(`Duplicate managed cloud filename: ${filename}`);
|
|
179
|
+
}
|
|
180
|
+
uploadedNames.add(filename);
|
|
181
|
+
const buffer = 'buffer' in file ? file.buffer : adapter.supportsTempFiles ? Buffer.alloc(0) : await fs.readFile(file.sourcePath);
|
|
182
|
+
const uploadFile = {
|
|
183
|
+
buffer,
|
|
184
|
+
filename,
|
|
185
|
+
filesize: 'buffer' in file ? file.buffer.length : (await fs.stat(file.sourcePath)).size,
|
|
186
|
+
mimeType: getMimeType({
|
|
187
|
+
data,
|
|
188
|
+
filename
|
|
189
|
+
}),
|
|
190
|
+
...'sourcePath' in file ? {
|
|
191
|
+
tempFilePath: file.sourcePath
|
|
192
|
+
} : {}
|
|
193
|
+
};
|
|
194
|
+
// A new object folder is allocated for every server upload, so an interrupted
|
|
195
|
+
// provider write can be removed without touching an earlier revision.
|
|
196
|
+
trackStagedObject({
|
|
197
|
+
key: storageFilePath,
|
|
198
|
+
remove: async ()=>{
|
|
199
|
+
await adapter.deleteFile({
|
|
200
|
+
collection,
|
|
201
|
+
req,
|
|
202
|
+
storageFilePath
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
const dataBeforeUpload = deepCopyObjectSimple(dataForUpload);
|
|
207
|
+
const result = await adapter.handleUpload({
|
|
208
|
+
collection,
|
|
209
|
+
data: dataForUpload,
|
|
210
|
+
file: uploadFile,
|
|
211
|
+
req,
|
|
212
|
+
storageFilePath
|
|
213
|
+
});
|
|
214
|
+
if (result && typeof result === 'object') {
|
|
215
|
+
// Adapters may return the entire input document, including fields made stale by this upload.
|
|
216
|
+
for (const [key, value] of Object.entries(result)){
|
|
217
|
+
if (!isDeepStrictEqual(value, dataBeforeUpload[key])) {
|
|
218
|
+
metadata[key] = value;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
delete metadata.prefix;
|
|
224
|
+
delete metadata._objectKey;
|
|
225
|
+
return {
|
|
226
|
+
metadata
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
const getMimeType = ({ data, filename })=>{
|
|
232
|
+
if (data.original && typeof data.original === 'object') {
|
|
233
|
+
const original = data.original;
|
|
234
|
+
if (original.filename === filename && original.mimeType) {
|
|
235
|
+
return original.mimeType;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (data.variants && typeof data.variants === 'object') {
|
|
239
|
+
for (const size of Object.values(data.variants)){
|
|
240
|
+
const candidate = size;
|
|
241
|
+
if (candidate?.filename === filename && candidate.mimeType) {
|
|
242
|
+
return candidate.mimeType;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return typeof data.mimeType === 'string' ? data.mimeType : 'application/octet-stream';
|
|
247
|
+
};
|
|
248
|
+
/** Signed and time-limited URLs change their query on every generation, so only the location is compared. */ const isSameFileLocation = ({ actual, expected })=>typeof expected === 'string' && getFileLocation({
|
|
249
|
+
url: actual
|
|
250
|
+
}) === getFileLocation({
|
|
251
|
+
url: expected
|
|
252
|
+
});
|
|
253
|
+
const getFileLocation = ({ url })=>{
|
|
254
|
+
const parsed = new URL(url, 'http://payload.local');
|
|
255
|
+
return url.startsWith('/') ? parsed.pathname : `${parsed.origin}${parsed.pathname}`;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
//# sourceMappingURL=createFileOperations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/createFileOperations.ts"],"sourcesContent":["import type { CollectionConfig, ImageSize, JsonObject, UploadConfig } from 'payload'\n\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\nimport { isDeepStrictEqual } from 'node:util'\nimport { deepCopyObjectSimple, generatePayloadFileURL } from 'payload'\n\nimport type { GeneratedAdapter, GenerateFileURL } from '../types.js'\n\nimport { buildPrefixWithObjectKey } from './buildPrefixWithObjectKey.js'\nimport {\n buildStoragePathData,\n buildUploadPrefix,\n buildUploadStoragePathData,\n} from './buildStoragePathData.js'\n\ntype Args = {\n adapter: GeneratedAdapter\n collection: CollectionConfig\n collectionPrefix?: string\n disablePayloadAccessControl?: boolean\n generateFileURL?: GenerateFileURL\n useCompositePrefixes?: boolean\n}\n\nexport const createFileOperations = ({\n adapter,\n collection,\n collectionPrefix,\n disablePayloadAccessControl,\n generateFileURL,\n useCompositePrefixes,\n}: Args): NonNullable<UploadConfig['fileOperations']> => {\n if (typeof adapter.deleteFile !== 'function') {\n throw new Error(\n `Storage adapter \"${adapter.name}\" must implement deleteFile for collection \"${collection.slug}\".`,\n )\n }\n\n return {\n copy: async ({ from, req, to, trackStagedObject }) => {\n await adapter.copyFile({\n collection: req.payload.collections[collection.slug]!.config,\n from,\n req,\n to,\n })\n trackStagedObject({\n key: to,\n remove: async () => {\n await adapter.deleteFile({\n collection,\n req,\n storageFilePath: to,\n })\n },\n })\n },\n delete: async ({ key, req }) => {\n await adapter.deleteFile({\n collection,\n req,\n storageFilePath: key,\n })\n },\n hasLegacyFile: async ({ doc, req }) => {\n if (typeof doc.filename !== 'string' || typeof doc.url !== 'string') {\n return false\n }\n\n const docPrefix = typeof doc.prefix === 'string' ? doc.prefix : undefined\n const objectFolder = buildPrefixWithObjectKey({\n objectKey: typeof doc._objectKey === 'string' ? doc._objectKey : undefined,\n prefix: docPrefix,\n })\n const expectedURL = async ({ filename, size }: { filename: string; size?: ImageSize }) => {\n if (generateFileURL) {\n return generateFileURL({ collection, filename, prefix: objectFolder, size })\n }\n if (disablePayloadAccessControl && adapter.generateURL) {\n return adapter.generateURL({ collection, data: doc, filename, prefix: objectFolder })\n }\n return generatePayloadFileURL({\n collectionSlug: collection.slug,\n config: req.payload.config as unknown as Parameters<\n typeof generatePayloadFileURL\n >[0]['config'],\n filename,\n relative: true,\n })\n }\n if (\n !isSameFileLocation({\n actual: doc.url,\n expected: await expectedURL({ filename: doc.filename }),\n })\n ) {\n return false\n }\n if (doc.variants && typeof doc.variants === 'object' && !Array.isArray(doc.variants)) {\n for (const [sizeKey, size] of Object.entries(doc.variants)) {\n if (\n size &&\n typeof size === 'object' &&\n 'filename' in size &&\n typeof size.filename === 'string'\n ) {\n const imageSize = req.payload.collections[\n collection.slug\n ]?.config.upload.variants?.find(({ name }) => name === sizeKey)\n if (\n !('url' in size) ||\n typeof size.url !== 'string' ||\n !isSameFileLocation({\n actual: size.url,\n expected: await expectedURL({ filename: size.filename, size: imageSize }),\n })\n ) {\n return false\n }\n }\n }\n }\n return true\n },\n resolveStorageKey: ({ _objectKey, filename, prefix }) =>\n buildStoragePathData({\n collectionPrefix,\n docPrefix: buildPrefixWithObjectKey({ objectKey: _objectKey, prefix }),\n filename,\n useCompositePrefixes,\n }).storageFilePath,\n ...(adapter.moveFile && {\n move: async ({ from, req, to, trackStagedObject }) => {\n await adapter.moveFile!({\n collection: req.payload.collections[collection.slug]!.config,\n from,\n req,\n to,\n })\n trackStagedObject({\n key: to,\n remove: () =>\n adapter.moveFile!({\n collection: req.payload.collections[collection.slug]!.config,\n from: to,\n req,\n to: from,\n }),\n })\n },\n }),\n stage: async ({ data, files, req, trackStagedObject }) => {\n const uploadedNames = new Set<string>()\n const metadata: Record<string, unknown> = {}\n const verifiedOriginal = req.context?._payloadVerifiedProviderOriginal as\n | { filename: string }\n | undefined\n for (const file of files) {\n const filename = path.basename(file.path)\n const representations: Record<string, unknown>[] = [data]\n if (data.original && typeof data.original === 'object') {\n representations.push(data.original as Record<string, unknown>)\n }\n if (data.variants && typeof data.variants === 'object') {\n representations.push(\n ...Object.values(data.variants).filter(\n (value): value is Record<string, unknown> =>\n Boolean(value) && typeof value === 'object',\n ),\n )\n }\n const destinations = representations.filter((value) => value.filename === filename)\n // Provider-direct uploads already placed the source object at its verified location.\n // A bounded content probe can still appear in files, but it is not a representation\n // Payload should upload again.\n if (!destinations.length && verifiedOriginal) {\n continue\n }\n if (!destinations.length) {\n throw new Error(`No stored representation describes ${filename}`)\n }\n const prefixLocation = destinations.find(\n (destination) => typeof destination.prefix === 'string',\n )\n const objectKeyLocation = destinations.find(\n (destination) => typeof destination._objectKey === 'string',\n )\n const prefix =\n typeof prefixLocation?.prefix === 'string' ? prefixLocation.prefix : undefined\n const objectKey =\n typeof objectKeyLocation?._objectKey === 'string'\n ? objectKeyLocation._objectKey\n : undefined\n const prefixData = buildUploadPrefix({\n collectionPrefix,\n docPrefix: typeof prefix === 'string' ? prefix : undefined,\n useCompositePrefixes,\n })\n const uploadPrefix = useCompositePrefixes\n ? prefixData.sanitizedDocPrefix\n : prefixData.uploadPrefix\n for (const destination of destinations) {\n destination.prefix = uploadPrefix\n destination._objectKey = objectKey\n }\n const docPrefix = buildPrefixWithObjectKey({ objectKey, prefix: uploadPrefix })\n const dataForUpload = { ...data, prefix: docPrefix }\n const storageFilePath = buildUploadStoragePathData({\n collectionPrefix,\n docPrefix,\n filename,\n useCompositePrefixes,\n }).storageFilePath\n\n if (uploadedNames.has(filename)) {\n throw new Error(`Duplicate managed cloud filename: ${filename}`)\n }\n\n uploadedNames.add(filename)\n const buffer =\n 'buffer' in file\n ? file.buffer\n : adapter.supportsTempFiles\n ? Buffer.alloc(0)\n : await fs.readFile(file.sourcePath)\n const uploadFile = {\n buffer,\n filename,\n filesize: 'buffer' in file ? file.buffer.length : (await fs.stat(file.sourcePath)).size,\n mimeType: getMimeType({ data, filename }),\n ...('sourcePath' in file ? { tempFilePath: file.sourcePath } : {}),\n }\n\n // A new object folder is allocated for every server upload, so an interrupted\n // provider write can be removed without touching an earlier revision.\n trackStagedObject({\n key: storageFilePath,\n remove: async () => {\n await adapter.deleteFile({\n collection,\n req,\n storageFilePath,\n })\n },\n })\n\n const dataBeforeUpload = deepCopyObjectSimple(dataForUpload as JsonObject)\n const result = await adapter.handleUpload({\n collection,\n data: dataForUpload,\n file: uploadFile,\n req,\n storageFilePath,\n })\n\n if (result && typeof result === 'object') {\n // Adapters may return the entire input document, including fields made stale by this upload.\n for (const [key, value] of Object.entries(result)) {\n if (!isDeepStrictEqual(value, dataBeforeUpload[key])) {\n metadata[key] = value\n }\n }\n }\n }\n\n delete metadata.prefix\n delete metadata._objectKey\n return { metadata }\n },\n }\n}\n\nconst getMimeType = ({\n data,\n filename,\n}: {\n data: Record<string, unknown>\n filename: string\n}): string => {\n if (data.original && typeof data.original === 'object') {\n const original = data.original as { filename?: string; mimeType?: string }\n if (original.filename === filename && original.mimeType) {\n return original.mimeType\n }\n }\n if (data.variants && typeof data.variants === 'object') {\n for (const size of Object.values(data.variants)) {\n const candidate = size as { filename?: string; mimeType?: string } | null\n if (candidate?.filename === filename && candidate.mimeType) {\n return candidate.mimeType\n }\n }\n }\n return typeof data.mimeType === 'string' ? data.mimeType : 'application/octet-stream'\n}\n\n/** Signed and time-limited URLs change their query on every generation, so only the location is compared. */\nconst isSameFileLocation = ({\n actual,\n expected,\n}: {\n actual: string\n expected: null | string | undefined\n}): boolean =>\n typeof expected === 'string' &&\n getFileLocation({ url: actual }) === getFileLocation({ url: expected })\n\nconst getFileLocation = ({ url }: { url: string }): string => {\n const parsed = new URL(url, 'http://payload.local')\n\n return url.startsWith('/') ? parsed.pathname : `${parsed.origin}${parsed.pathname}`\n}\n"],"names":["fs","path","isDeepStrictEqual","deepCopyObjectSimple","generatePayloadFileURL","buildPrefixWithObjectKey","buildStoragePathData","buildUploadPrefix","buildUploadStoragePathData","createFileOperations","adapter","collection","collectionPrefix","disablePayloadAccessControl","generateFileURL","useCompositePrefixes","deleteFile","Error","name","slug","copy","from","req","to","trackStagedObject","copyFile","payload","collections","config","key","remove","storageFilePath","delete","hasLegacyFile","doc","filename","url","docPrefix","prefix","undefined","objectFolder","objectKey","_objectKey","expectedURL","size","generateURL","data","collectionSlug","relative","isSameFileLocation","actual","expected","variants","Array","isArray","sizeKey","Object","entries","imageSize","upload","find","resolveStorageKey","moveFile","move","stage","files","uploadedNames","Set","metadata","verifiedOriginal","context","_payloadVerifiedProviderOriginal","file","basename","representations","original","push","values","filter","value","Boolean","destinations","length","prefixLocation","destination","objectKeyLocation","prefixData","uploadPrefix","sanitizedDocPrefix","dataForUpload","has","add","buffer","supportsTempFiles","Buffer","alloc","readFile","sourcePath","uploadFile","filesize","stat","mimeType","getMimeType","tempFilePath","dataBeforeUpload","result","handleUpload","candidate","getFileLocation","parsed","URL","startsWith","pathname","origin"],"mappings":"AAEA,OAAOA,QAAQ,mBAAkB;AACjC,OAAOC,UAAU,YAAW;AAC5B,SAASC,iBAAiB,QAAQ,YAAW;AAC7C,SAASC,oBAAoB,EAAEC,sBAAsB,QAAQ,UAAS;AAItE,SAASC,wBAAwB,QAAQ,gCAA+B;AACxE,SACEC,oBAAoB,EACpBC,iBAAiB,EACjBC,0BAA0B,QACrB,4BAA2B;AAWlC,OAAO,MAAMC,uBAAuB,CAAC,EACnCC,OAAO,EACPC,UAAU,EACVC,gBAAgB,EAChBC,2BAA2B,EAC3BC,eAAe,EACfC,oBAAoB,EACf;IACL,IAAI,OAAOL,QAAQM,UAAU,KAAK,YAAY;QAC5C,MAAM,IAAIC,MACR,CAAC,iBAAiB,EAAEP,QAAQQ,IAAI,CAAC,4CAA4C,EAAEP,WAAWQ,IAAI,CAAC,EAAE,CAAC;IAEtG;IAEA,OAAO;QACLC,MAAM,OAAO,EAAEC,IAAI,EAAEC,GAAG,EAAEC,EAAE,EAAEC,iBAAiB,EAAE;YAC/C,MAAMd,QAAQe,QAAQ,CAAC;gBACrBd,YAAYW,IAAII,OAAO,CAACC,WAAW,CAAChB,WAAWQ,IAAI,CAAC,CAAES,MAAM;gBAC5DP;gBACAC;gBACAC;YACF;YACAC,kBAAkB;gBAChBK,KAAKN;gBACLO,QAAQ;oBACN,MAAMpB,QAAQM,UAAU,CAAC;wBACvBL;wBACAW;wBACAS,iBAAiBR;oBACnB;gBACF;YACF;QACF;QACAS,QAAQ,OAAO,EAAEH,GAAG,EAAEP,GAAG,EAAE;YACzB,MAAMZ,QAAQM,UAAU,CAAC;gBACvBL;gBACAW;gBACAS,iBAAiBF;YACnB;QACF;QACAI,eAAe,OAAO,EAAEC,GAAG,EAAEZ,GAAG,EAAE;YAChC,IAAI,OAAOY,IAAIC,QAAQ,KAAK,Y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2E,UAAU,CAAC,OAAOF,OAAOG,QAAQ,GAAG,GAAGH,OAAOI,MAAM,GAAGJ,OAAOG,QAAQ,EAAE;AACrF"}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import type { CollectionConfig, PayloadRequest } from 'payload';
|
|
1
|
+
import type { CollectionConfig, FileData, 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?: Partial<FileData> & TypeWithID;
|
|
16
15
|
filename: string;
|
|
16
|
+
/**
|
|
17
|
+
* Only narrows the access-controlled fallback lookup below; never trusted or
|
|
18
|
+
* returned directly. Prefer passing the access-checked document as `doc` instead.
|
|
19
|
+
*/
|
|
17
20
|
prefixQueryParam?: string;
|
|
18
21
|
req: PayloadRequest;
|
|
22
|
+
uploadReference?: unknown;
|
|
23
|
+
useCompositePrefixes?: boolean;
|
|
19
24
|
}): Promise<string>;
|
|
20
25
|
//# 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,
|
|
1
|
+
{"version":3,"file":"getFilePrefix.d.ts","sourceRoot":"","sources":["../../src/utilities/getFilePrefix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,QAAQ,EACR,cAAc,EAEd,UAAU,EACX,MAAM,SAAS,CAAA;AAMhB;;;;;;;;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,OAAO,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAA;IACpC,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,CA2ElB"}
|