payload 4.0.0-beta.8 → 4.0.0-beta.9
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/dist/auth/baseFields/sessions.d.ts.map +1 -1
- package/dist/auth/baseFields/sessions.js +12 -0
- package/dist/auth/baseFields/sessions.js.map +1 -1
- package/dist/auth/createAuthToken.d.ts +3 -3
- package/dist/auth/createAuthToken.d.ts.map +1 -1
- package/dist/auth/createAuthToken.js +4 -1
- package/dist/auth/createAuthToken.js.map +1 -1
- package/dist/auth/getUserAgentLabel.d.ts +8 -0
- package/dist/auth/getUserAgentLabel.d.ts.map +1 -0
- package/dist/auth/getUserAgentLabel.js +70 -0
- package/dist/auth/getUserAgentLabel.js.map +1 -0
- package/dist/auth/operations/login.d.ts.map +1 -1
- package/dist/auth/operations/login.js +5 -0
- package/dist/auth/operations/login.js.map +1 -1
- package/dist/auth/operations/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/resetPassword.js +5 -0
- package/dist/auth/operations/resetPassword.js.map +1 -1
- package/dist/auth/sessions.d.ts +2 -2
- package/dist/auth/sessions.d.ts.map +1 -1
- package/dist/auth/sessions.js +5 -2
- package/dist/auth/sessions.js.map +1 -1
- package/dist/auth/types.d.ts +9 -0
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/cli/commands/generateImportMap/utilities/resolveImportMapFilePath.d.ts.map +1 -1
- package/dist/cli/commands/generateImportMap/utilities/resolveImportMapFilePath.js +7 -3
- package/dist/cli/commands/generateImportMap/utilities/resolveImportMapFilePath.js.map +1 -1
- package/dist/collections/operations/create.js +1 -1
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +1 -3
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/local/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/local/restoreVersion.js +2 -1
- package/dist/collections/operations/local/restoreVersion.js.map +1 -1
- package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/restoreVersion.js +22 -6
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/collections/operations/update.js +1 -1
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.js +1 -1
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/exports/internal.d.ts +1 -1
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js.map +1 -1
- package/dist/index.bundled.d.ts +48 -63
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/uploads/checkFileAccess.d.ts.map +1 -1
- package/dist/uploads/checkFileAccess.js +1 -0
- package/dist/uploads/checkFileAccess.js.map +1 -1
- package/dist/uploads/endpoints/getFile.d.ts.map +1 -1
- package/dist/uploads/endpoints/getFile.js +17 -5
- package/dist/uploads/endpoints/getFile.js.map +1 -1
- package/dist/uploads/fileSelectionParams.d.ts +10 -0
- package/dist/uploads/fileSelectionParams.d.ts.map +1 -0
- package/dist/uploads/fileSelectionParams.js +10 -0
- package/dist/uploads/fileSelectionParams.js.map +1 -0
- package/dist/uploads/fileVersioning/cloudStorage.d.ts +7 -0
- package/dist/uploads/fileVersioning/cloudStorage.d.ts.map +1 -1
- package/dist/uploads/fileVersioning/cloudStorage.js +43 -19
- package/dist/uploads/fileVersioning/cloudStorage.js.map +1 -1
- package/dist/uploads/fileVersioning/resolveHistoricalFile.d.ts +18 -4
- package/dist/uploads/fileVersioning/resolveHistoricalFile.d.ts.map +1 -1
- package/dist/uploads/fileVersioning/resolveHistoricalFile.js +73 -30
- package/dist/uploads/fileVersioning/resolveHistoricalFile.js.map +1 -1
- package/dist/uploads/fileVersioning/restore.d.ts +17 -3
- package/dist/uploads/fileVersioning/restore.d.ts.map +1 -1
- package/dist/uploads/fileVersioning/restore.js +42 -1
- package/dist/uploads/fileVersioning/restore.js.map +1 -1
- package/dist/uploads/fileVersioning/restoreRequestTime.d.ts +15 -0
- package/dist/uploads/fileVersioning/restoreRequestTime.d.ts.map +1 -0
- package/dist/uploads/fileVersioning/restoreRequestTime.js +176 -0
- package/dist/uploads/fileVersioning/restoreRequestTime.js.map +1 -0
- package/dist/uploads/fileVersioning/storedFiles.d.ts +4 -0
- package/dist/uploads/fileVersioning/storedFiles.d.ts.map +1 -1
- package/dist/uploads/fileVersioning/storedFiles.js +10 -1
- package/dist/uploads/fileVersioning/storedFiles.js.map +1 -1
- package/dist/uploads/generateFileData/edits/legacyUploadEdits.d.ts +122 -0
- package/dist/uploads/generateFileData/edits/legacyUploadEdits.d.ts.map +1 -0
- package/dist/uploads/generateFileData/edits/legacyUploadEdits.js +261 -0
- package/dist/uploads/generateFileData/edits/legacyUploadEdits.js.map +1 -0
- package/dist/uploads/generateFileData/edits/resolveUploadEdits.d.ts +30 -0
- package/dist/uploads/generateFileData/edits/resolveUploadEdits.d.ts.map +1 -0
- package/dist/uploads/generateFileData/edits/resolveUploadEdits.js +131 -0
- package/dist/uploads/generateFileData/edits/resolveUploadEdits.js.map +1 -0
- package/dist/uploads/generateFileData/index.d.ts +47 -0
- package/dist/uploads/generateFileData/index.d.ts.map +1 -0
- package/dist/uploads/generateFileData/index.js +365 -0
- package/dist/uploads/generateFileData/index.js.map +1 -0
- package/dist/uploads/generateFileData/output/buildUploadOutput.d.ts +52 -0
- package/dist/uploads/generateFileData/output/buildUploadOutput.d.ts.map +1 -0
- package/dist/uploads/generateFileData/output/buildUploadOutput.js +394 -0
- package/dist/uploads/generateFileData/output/buildUploadOutput.js.map +1 -0
- package/dist/uploads/generateFileData/output/buildVariantOutputs.d.ts +33 -0
- package/dist/uploads/generateFileData/output/buildVariantOutputs.d.ts.map +1 -0
- package/dist/uploads/generateFileData/output/buildVariantOutputs.js +100 -0
- package/dist/uploads/generateFileData/output/buildVariantOutputs.js.map +1 -0
- package/dist/uploads/generateFileData/output/resolveTempFileHandling.d.ts +20 -0
- package/dist/uploads/generateFileData/output/resolveTempFileHandling.d.ts.map +1 -0
- package/dist/uploads/generateFileData/output/resolveTempFileHandling.js +20 -0
- package/dist/uploads/generateFileData/output/resolveTempFileHandling.js.map +1 -0
- package/dist/uploads/generateFileData/plan/planSourceRebuild.d.ts +35 -0
- package/dist/uploads/generateFileData/plan/planSourceRebuild.d.ts.map +1 -0
- package/dist/uploads/generateFileData/plan/planSourceRebuild.js +54 -0
- package/dist/uploads/generateFileData/plan/planSourceRebuild.js.map +1 -0
- package/dist/uploads/generateFileData/plan/planUploadStages.d.ts +44 -0
- package/dist/uploads/generateFileData/plan/planUploadStages.d.ts.map +1 -0
- package/dist/uploads/generateFileData/plan/planUploadStages.js +63 -0
- package/dist/uploads/generateFileData/plan/planUploadStages.js.map +1 -0
- package/dist/uploads/generateFileData/runUploadTransformers.d.ts +46 -0
- package/dist/uploads/generateFileData/runUploadTransformers.d.ts.map +1 -0
- package/dist/uploads/generateFileData/runUploadTransformers.js +93 -0
- package/dist/uploads/generateFileData/runUploadTransformers.js.map +1 -0
- package/dist/uploads/generateFileData/source/downloadClientUpload.d.ts +32 -0
- package/dist/uploads/generateFileData/source/downloadClientUpload.d.ts.map +1 -0
- package/dist/uploads/generateFileData/source/downloadClientUpload.js +43 -0
- package/dist/uploads/generateFileData/source/downloadClientUpload.js.map +1 -0
- package/dist/uploads/generateFileData/source/readUploadSource.d.ts +27 -0
- package/dist/uploads/generateFileData/source/readUploadSource.d.ts.map +1 -0
- package/dist/uploads/generateFileData/source/readUploadSource.js +97 -0
- package/dist/uploads/generateFileData/source/readUploadSource.js.map +1 -0
- package/dist/uploads/generateFileData/source/selectUploadSource.d.ts +50 -0
- package/dist/uploads/generateFileData/source/selectUploadSource.d.ts.map +1 -0
- package/dist/uploads/generateFileData/source/selectUploadSource.js +42 -0
- package/dist/uploads/generateFileData/source/selectUploadSource.js.map +1 -0
- package/dist/uploads/generateFileData/utils/checkFileAndUseDetectedType.d.ts +9 -0
- package/dist/uploads/generateFileData/utils/checkFileAndUseDetectedType.d.ts.map +1 -0
- package/dist/uploads/generateFileData/utils/checkFileAndUseDetectedType.js +19 -0
- package/dist/uploads/generateFileData/utils/checkFileAndUseDetectedType.js.map +1 -0
- package/dist/uploads/generateFileData/utils/generateImageSizeFilename.d.ts.map +1 -0
- package/dist/uploads/generateFileData/utils/generateImageSizeFilename.js.map +1 -0
- package/dist/uploads/generateFileData/utils/getUploadStorage.d.ts +27 -0
- package/dist/uploads/generateFileData/utils/getUploadStorage.d.ts.map +1 -0
- package/dist/uploads/generateFileData/utils/getUploadStorage.js +22 -0
- package/dist/uploads/generateFileData/utils/getUploadStorage.js.map +1 -0
- package/dist/uploads/generateFileData/utils/toFileUploadError.d.ts +11 -0
- package/dist/uploads/generateFileData/utils/toFileUploadError.d.ts.map +1 -0
- package/dist/uploads/generateFileData/utils/toFileUploadError.js +15 -0
- package/dist/uploads/generateFileData/utils/toFileUploadError.js.map +1 -0
- package/dist/uploads/getFileFromUploadInstructions.js +2 -2
- package/dist/uploads/getFileFromUploadInstructions.js.map +1 -1
- package/dist/uploads/requestTimeFileData.d.ts +36 -0
- package/dist/uploads/requestTimeFileData.d.ts.map +1 -0
- package/dist/uploads/requestTimeFileData.js +56 -0
- package/dist/uploads/requestTimeFileData.js.map +1 -0
- package/dist/uploads/transformState/planUpload.d.ts +27 -2
- package/dist/uploads/transformState/planUpload.d.ts.map +1 -1
- package/dist/uploads/transformState/planUpload.js +27 -4
- package/dist/uploads/transformState/planUpload.js.map +1 -1
- package/dist/uploads/transformState/transformStateInput.d.ts +52 -0
- package/dist/uploads/transformState/transformStateInput.d.ts.map +1 -0
- package/dist/uploads/transformState/transformStateInput.js +113 -0
- package/dist/uploads/transformState/transformStateInput.js.map +1 -0
- package/dist/uploads/transformers/handleDynamicFileRequest.d.ts +7 -1
- package/dist/uploads/transformers/handleDynamicFileRequest.d.ts.map +1 -1
- package/dist/uploads/transformers/handleDynamicFileRequest.js +40 -10
- package/dist/uploads/transformers/handleDynamicFileRequest.js.map +1 -1
- package/dist/uploads/transformers/transformUploadFile.js +1 -1
- package/dist/uploads/transformers/transformUploadFile.js.map +1 -1
- package/dist/uploads/transformers/uploadTransformerBridge.d.ts +16 -6
- package/dist/uploads/transformers/uploadTransformerBridge.d.ts.map +1 -1
- package/dist/uploads/transformers/uploadTransformerBridge.js +3 -1
- package/dist/uploads/transformers/uploadTransformerBridge.js.map +1 -1
- package/dist/utilities/initTransaction.d.ts.map +1 -1
- package/dist/utilities/initTransaction.js +35 -7
- package/dist/utilities/initTransaction.js.map +1 -1
- package/dist/versions/getLatestCollectionVersion.d.ts +1 -2
- package/dist/versions/getLatestCollectionVersion.d.ts.map +1 -1
- package/dist/versions/getLatestCollectionVersion.js +7 -23
- package/dist/versions/getLatestCollectionVersion.js.map +1 -1
- package/dist/versions/getLatestGlobalVersion.d.ts +1 -2
- package/dist/versions/getLatestGlobalVersion.d.ts.map +1 -1
- package/dist/versions/getLatestGlobalVersion.js +2 -6
- package/dist/versions/getLatestGlobalVersion.js.map +1 -1
- package/package.json +3 -3
- package/skills/payload/SKILL.md +12 -9
- package/skills/payload/reference/ADAPTERS.md +21 -27
- package/skills/payload/reference/FIELDS.md +1 -1
- package/skills/payload/reference/HOOKS.md +1 -1
- package/skills/payload/reference/PLUGIN-DEVELOPMENT.md +1 -1
- package/skills/payload/reference/QUERIES.md +6 -6
- package/dist/uploads/generateFileData.d.ts +0 -60
- package/dist/uploads/generateFileData.d.ts.map +0 -1
- package/dist/uploads/generateFileData.js +0 -1022
- package/dist/uploads/generateFileData.js.map +0 -1
- package/dist/uploads/generateImageSizeFilename.d.ts.map +0 -1
- package/dist/uploads/generateImageSizeFilename.js.map +0 -1
- package/dist/uploads/transformState/resolveUploadEdits.d.ts +0 -91
- package/dist/uploads/transformState/resolveUploadEdits.d.ts.map +0 -1
- package/dist/uploads/transformState/resolveUploadEdits.js +0 -397
- package/dist/uploads/transformState/resolveUploadEdits.js.map +0 -1
- /package/dist/uploads/{generateImageSizeFilename.d.ts → generateFileData/utils/generateImageSizeFilename.d.ts} +0 -0
- /package/dist/uploads/{generateImageSizeFilename.js → generateFileData/utils/generateImageSizeFilename.js} +0 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility with the inputs that predate `_transforms`: the `uploadEdits` query (the admin
|
|
3
|
+
* crop and focal point editor), `focalX`/`focalY`, and the `UploadEdits` that core still reads to
|
|
4
|
+
* decide on rebuilds, crop resets and the crop size for the upload bridge. The general
|
|
5
|
+
* `_transforms` rules are in transformState/transformStateInput.ts.
|
|
6
|
+
*/ import { isDeepStrictEqual } from 'node:util';
|
|
7
|
+
import { isNumber } from '../../../utilities/isNumber.js';
|
|
8
|
+
import { hasCropOrResizeEdit } from '../../hasCropOrResizeEdit.js';
|
|
9
|
+
import { cropToPercent, cropToPixels, isFullCrop } from '../../transformState/cropUnits.js';
|
|
10
|
+
export const centerFocalPoint = {
|
|
11
|
+
x: 50,
|
|
12
|
+
y: 50
|
|
13
|
+
};
|
|
14
|
+
const fullCrop = {
|
|
15
|
+
height: 100,
|
|
16
|
+
unit: '%',
|
|
17
|
+
width: 100,
|
|
18
|
+
x: 0,
|
|
19
|
+
y: 0
|
|
20
|
+
};
|
|
21
|
+
/** The edits sent through the `uploadEdits` query, or a focal point sent through `focalX`/`focalY`. */ export function parseLegacyUploadEdits({ data, isDuplicating, operation, originalDoc, req }) {
|
|
22
|
+
// Get intended focal point change from query string or incoming data
|
|
23
|
+
const uploadEdits = req.query?.uploadEdits && typeof req.query.uploadEdits === 'object' ? req.query.uploadEdits : {};
|
|
24
|
+
if (uploadEdits.focalPoint) {
|
|
25
|
+
return uploadEdits;
|
|
26
|
+
}
|
|
27
|
+
const incomingData = data;
|
|
28
|
+
const origDoc = originalDoc;
|
|
29
|
+
if (origDoc && 'focalX' in origDoc && 'focalY' in origDoc) {
|
|
30
|
+
// Admin always resends the current focal point, so treat an unchanged value as no edit.
|
|
31
|
+
if (incomingData?.focalX === origDoc.focalX && incomingData?.focalY === origDoc.focalY) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (isDuplicating) {
|
|
35
|
+
uploadEdits.focalPoint = {
|
|
36
|
+
x: incomingData?.focalX || origDoc.focalX,
|
|
37
|
+
y: incomingData?.focalY || origDoc.focalY
|
|
38
|
+
};
|
|
39
|
+
return uploadEdits;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (incomingData?.focalX && incomingData?.focalY) {
|
|
43
|
+
uploadEdits.focalPoint = {
|
|
44
|
+
x: incomingData.focalX,
|
|
45
|
+
y: incomingData.focalY
|
|
46
|
+
};
|
|
47
|
+
return uploadEdits;
|
|
48
|
+
}
|
|
49
|
+
// If no focal point is set, default to center
|
|
50
|
+
if (operation === 'create') {
|
|
51
|
+
uploadEdits.focalPoint = {
|
|
52
|
+
x: 50,
|
|
53
|
+
y: 50
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return uploadEdits;
|
|
57
|
+
}
|
|
58
|
+
/** The stored focal point: the saved `_transforms` one, else `focalX`/`focalY`, else the center. */ export function getCurrentFocalPoint({ current, previous }) {
|
|
59
|
+
return previous?.focalPoint ?? (isNumber(current?.focalX) && isNumber(current?.focalY) ? {
|
|
60
|
+
x: current.focalX,
|
|
61
|
+
y: current.focalY
|
|
62
|
+
} : centerFocalPoint);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The focal point written through the query or through `focalX`/`focalY`. Each of `focalX` and
|
|
66
|
+
* `focalY` can be sent alone. The admin sends back the stored, rounded values on every save, so a
|
|
67
|
+
* value equal to the stored one is not a write and the exact saved value is kept.
|
|
68
|
+
*/ export function getFocalPointWrite({ current, currentFocalPoint, incoming, queryFocalPoint }) {
|
|
69
|
+
if (queryFocalPoint) {
|
|
70
|
+
// Query values arrive as strings.
|
|
71
|
+
return {
|
|
72
|
+
x: Number(queryFocalPoint.x),
|
|
73
|
+
y: Number(queryFocalPoint.y)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Form data can send numbers as strings.
|
|
77
|
+
const x = isNumber(incoming.focalX) && Number(incoming.focalX) !== current?.focalX ? Number(incoming.focalX) : undefined;
|
|
78
|
+
const y = isNumber(incoming.focalY) && Number(incoming.focalY) !== current?.focalY ? Number(incoming.focalY) : undefined;
|
|
79
|
+
if (x === undefined && y === undefined) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
x: x ?? currentFocalPoint.x,
|
|
84
|
+
y: y ?? currentFocalPoint.y
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Applies the legacy inputs to the next `_transforms` value, in this order:
|
|
89
|
+
* 1. An admin editor crop (percent of the original) sets or removes `crop`.
|
|
90
|
+
* 2. A focal point written through `focalX`/`focalY` or the query is saved when it changes. A
|
|
91
|
+
* submitted `_transforms.focalPoint` wins over it.
|
|
92
|
+
* 3. The first write on a document saved before `_transforms` existed keeps its focal point.
|
|
93
|
+
* The center means the same as no focal point, so it is not copied.
|
|
94
|
+
*/ export function applyLegacyEdits({ adminCrop, currentFocalPoint, focalPointWrite, isLegacyDocument, original, state, submitted }) {
|
|
95
|
+
let next = state;
|
|
96
|
+
if (adminCrop && original) {
|
|
97
|
+
const { crop: _crop, ...rest } = next ?? {};
|
|
98
|
+
next = isFullCrop(adminCrop) ? rest : {
|
|
99
|
+
...rest,
|
|
100
|
+
crop: cropToPixels({
|
|
101
|
+
crop: adminCrop,
|
|
102
|
+
original
|
|
103
|
+
})
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const writtenFocalPoint = submitted?.focalPoint ?? focalPointWrite;
|
|
107
|
+
if (writtenFocalPoint && !isDeepStrictEqual(writtenFocalPoint, currentFocalPoint)) {
|
|
108
|
+
next = {
|
|
109
|
+
...next,
|
|
110
|
+
focalPoint: writtenFocalPoint
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (next && !next.focalPoint && isLegacyDocument && !isDeepStrictEqual(currentFocalPoint, centerFocalPoint)) {
|
|
114
|
+
next = {
|
|
115
|
+
...next,
|
|
116
|
+
focalPoint: currentFocalPoint
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return next;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The focal point that `focalX`/`focalY` and the pipeline use. A state without a focal point uses
|
|
123
|
+
* the center, unless it never had one. A new file starts from the center too: the stored focal
|
|
124
|
+
* point belongs to the replaced file. A submitted `null` removes all edits, including a focal point
|
|
125
|
+
* saved before `_transforms` existed.
|
|
126
|
+
*/ export function getNextFocalPoint({ currentFocalPoint, hasNewFile, next, previous, submitted }) {
|
|
127
|
+
const nextFocalPoint = next?.focalPoint ?? (previous?.focalPoint || hasNewFile || submitted === null ? centerFocalPoint : currentFocalPoint);
|
|
128
|
+
return {
|
|
129
|
+
hasChange: !isDeepStrictEqual(nextFocalPoint, currentFocalPoint),
|
|
130
|
+
rounded: {
|
|
131
|
+
x: Math.round(nextFocalPoint.x),
|
|
132
|
+
y: Math.round(nextFocalPoint.y)
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The edits for the upload pipeline. Without a query crop, the crop comes from the saved state:
|
|
138
|
+
* a changed crop or focal point reprocesses the original, and an unchanged crop does not. A
|
|
139
|
+
* removed crop is sent as a crop of the whole original: the rebuild decision and the crop reset
|
|
140
|
+
* (`getCropResetAndFocalPointChange`) read it that way, and the upload bridge gets its size.
|
|
141
|
+
*/ export function toPipelineEdits({ hasFocalPointChange, hasNewFile, next, nextFocalPoint, original, parsedEdits, previous }) {
|
|
142
|
+
let edits = parsedEdits;
|
|
143
|
+
if (parsedEdits?.focalPoint || hasFocalPointChange) {
|
|
144
|
+
edits = {
|
|
145
|
+
...edits,
|
|
146
|
+
focalPoint: nextFocalPoint
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (!original) {
|
|
150
|
+
return edits;
|
|
151
|
+
}
|
|
152
|
+
// A rebuilt file rebuilds its sizes, which must keep the saved focal point.
|
|
153
|
+
const savedFocalPoint = isDeepStrictEqual(nextFocalPoint, centerFocalPoint) ? undefined : {
|
|
154
|
+
focalPoint: nextFocalPoint
|
|
155
|
+
};
|
|
156
|
+
// A query crop is applied as sent: its `widthInPixels`/`heightInPixels` can also resize it.
|
|
157
|
+
if (edits?.crop) {
|
|
158
|
+
return {
|
|
159
|
+
...savedFocalPoint,
|
|
160
|
+
...edits
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const hasCropChange = !isDeepStrictEqual(previous?.crop, next?.crop);
|
|
164
|
+
if (next?.crop && (hasNewFile || hasCropChange || hasFocalPointChange)) {
|
|
165
|
+
return {
|
|
166
|
+
...savedFocalPoint,
|
|
167
|
+
...edits,
|
|
168
|
+
...toCropEdits({
|
|
169
|
+
crop: next.crop,
|
|
170
|
+
original
|
|
171
|
+
})
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (previous?.crop && !next?.crop) {
|
|
175
|
+
return {
|
|
176
|
+
...savedFocalPoint,
|
|
177
|
+
...edits,
|
|
178
|
+
crop: fullCrop,
|
|
179
|
+
heightInPixels: original.height,
|
|
180
|
+
widthInPixels: original.width
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return edits;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The edits for a rebuild from the retained original. Another key can cause the rebuild, so the
|
|
187
|
+
* saved crop and focal point are applied again, unless the edits already set them. Without the
|
|
188
|
+
* focal point, the sizes would be built around the center.
|
|
189
|
+
*/ export function withSavedEdits({ edits, original, transforms }) {
|
|
190
|
+
const savedCrop = transforms?.crop;
|
|
191
|
+
const savedFocalPoint = transforms?.focalPoint;
|
|
192
|
+
const canApplySavedCrop = !edits?.crop && savedCrop && original.width && original.height;
|
|
193
|
+
return {
|
|
194
|
+
...edits,
|
|
195
|
+
...canApplySavedCrop ? toCropEdits({
|
|
196
|
+
crop: savedCrop,
|
|
197
|
+
original: {
|
|
198
|
+
height: original.height,
|
|
199
|
+
width: original.width
|
|
200
|
+
}
|
|
201
|
+
}) : {},
|
|
202
|
+
...!edits?.focalPoint && savedFocalPoint ? {
|
|
203
|
+
focalPoint: savedFocalPoint
|
|
204
|
+
} : {}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A crop or resize in the edits, or a focal point that differs from the one in `fileData`. These
|
|
209
|
+
* triggers rebuilt the stored file before `_transforms` existed.
|
|
210
|
+
*/ export function hasLegacyCropOrFocalPointEdit({ fileData, uploadEdits }) {
|
|
211
|
+
if (!fileData || !uploadEdits) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
if (hasCropOrResizeEdit(uploadEdits)) {
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
// Since uploadEdits always has focalPoint, compare to the value in the data if it was changed
|
|
218
|
+
if (uploadEdits.focalPoint) {
|
|
219
|
+
const currentFocalX = 'focalX' in fileData && fileData.focalX;
|
|
220
|
+
const currentFocalY = 'focalY' in fileData && fileData.focalY;
|
|
221
|
+
return !(uploadEdits.focalPoint.x === currentFocalX && uploadEdits.focalPoint.y === currentFocalY);
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Whether the edits reset the crop of a document that keeps its original, and whether they change
|
|
227
|
+
* the focal point. A crop reset is a crop of the whole original at its own size. With no other
|
|
228
|
+
* change it reuses the retained original, so the upload bridge does not get its crop size.
|
|
229
|
+
*/ export function getCropResetAndFocalPointChange({ currentFileData, retainedOriginal, uploadEdits }) {
|
|
230
|
+
const crop = uploadEdits?.crop;
|
|
231
|
+
const isResettingCrop = Boolean(retainedOriginal && crop && isFullCrop(crop) && (uploadEdits.widthInPixels === undefined || Number(uploadEdits.widthInPixels) === retainedOriginal.width) && (uploadEdits.heightInPixels === undefined || Number(uploadEdits.heightInPixels) === retainedOriginal.height));
|
|
232
|
+
const hasFocalPointChange = Boolean(uploadEdits?.focalPoint && (Number(uploadEdits.focalPoint.x) !== (currentFileData?.focalX ?? 50) || Number(uploadEdits.focalPoint.y) !== (currentFileData?.focalY ?? 50)));
|
|
233
|
+
return {
|
|
234
|
+
cropSize: isResettingCrop ? undefined : getCropSize({
|
|
235
|
+
edits: uploadEdits
|
|
236
|
+
}),
|
|
237
|
+
hasFocalPointChange,
|
|
238
|
+
isResettingCrop
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/** A saved crop in pixels as the `uploadEdits` crop: percent, plus its output size in pixels. */ function toCropEdits({ crop, original }) {
|
|
242
|
+
return {
|
|
243
|
+
crop: cropToPercent({
|
|
244
|
+
crop,
|
|
245
|
+
original
|
|
246
|
+
}),
|
|
247
|
+
heightInPixels: crop.height,
|
|
248
|
+
widthInPixels: crop.width
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
/** The crop size in the edits, when the edits have a crop and both pixel sizes. */ function getCropSize({ edits }) {
|
|
252
|
+
if (!edits?.crop || edits.widthInPixels === undefined || edits.heightInPixels === undefined) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
height: Number(edits.heightInPixels),
|
|
257
|
+
width: Number(edits.widthInPixels)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=legacyUploadEdits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/uploads/generateFileData/edits/legacyUploadEdits.ts"],"sourcesContent":["/**\n * Compatibility with the inputs that predate `_transforms`: the `uploadEdits` query (the admin\n * crop and focal point editor), `focalX`/`focalY`, and the `UploadEdits` that core still reads to\n * decide on rebuilds, crop resets and the crop size for the upload bridge. The general\n * `_transforms` rules are in transformState/transformStateInput.ts.\n */\nimport { isDeepStrictEqual } from 'node:util'\n\nimport type { Document, PayloadRequest } from '../../../types/index.js'\nimport type { Dimensions, TransformState } from '../../transformState/transformStateInput.js'\nimport type { FileData, FocalPoint, OriginalFileData, UploadEdits } from '../../types.js'\n\nimport { isNumber } from '../../../utilities/isNumber.js'\nimport { hasCropOrResizeEdit } from '../../hasCropOrResizeEdit.js'\nimport { cropToPercent, cropToPixels, isFullCrop } from '../../transformState/cropUnits.js'\n\nexport const centerFocalPoint: FocalPoint = { x: 50, y: 50 }\nconst fullCrop = { height: 100, unit: '%', width: 100, x: 0, y: 0 } as const\n\n/** The edits sent through the `uploadEdits` query, or a focal point sent through `focalX`/`focalY`. */\nexport function parseLegacyUploadEdits({\n data,\n isDuplicating,\n operation,\n originalDoc,\n req,\n}: {\n data: unknown\n isDuplicating?: boolean\n operation: 'create' | 'update'\n /** Only a duplication source informs edit parsing. */\n originalDoc: unknown\n req: PayloadRequest\n}): UploadEdits {\n // Get intended focal point change from query string or incoming data\n const uploadEdits =\n req.query?.uploadEdits && typeof req.query.uploadEdits === 'object'\n ? (req.query.uploadEdits as UploadEdits)\n : {}\n\n if (uploadEdits.focalPoint) {\n return uploadEdits\n }\n\n const incomingData = data as FileData\n const origDoc = originalDoc as FileData\n\n if (origDoc && 'focalX' in origDoc && 'focalY' in origDoc) {\n // Admin always resends the current focal point, so treat an unchanged value as no edit.\n if (incomingData?.focalX === origDoc.focalX && incomingData?.focalY === origDoc.focalY) {\n return undefined!\n }\n\n if (isDuplicating) {\n uploadEdits.focalPoint = {\n x: incomingData?.focalX || origDoc.focalX!,\n y: incomingData?.focalY || origDoc.focalY!,\n }\n return uploadEdits\n }\n }\n\n if (incomingData?.focalX && incomingData?.focalY) {\n uploadEdits.focalPoint = {\n x: incomingData.focalX,\n y: incomingData.focalY,\n }\n return uploadEdits\n }\n\n // If no focal point is set, default to center\n if (operation === 'create') {\n uploadEdits.focalPoint = {\n x: 50,\n y: 50,\n }\n }\n\n return uploadEdits\n}\n\n/** The stored focal point: the saved `_transforms` one, else `focalX`/`focalY`, else the center. */\nexport function getCurrentFocalPoint({\n current,\n previous,\n}: {\n current?: Document\n previous: TransformState\n}): FocalPoint {\n return (\n previous?.focalPoint ??\n (isNumber(current?.focalX) && isNumber(current?.focalY)\n ? { x: current.focalX, y: current.focalY }\n : centerFocalPoint)\n )\n}\n\n/**\n * The focal point written through the query or through `focalX`/`focalY`. Each of `focalX` and\n * `focalY` can be sent alone. The admin sends back the stored, rounded values on every save, so a\n * value equal to the stored one is not a write and the exact saved value is kept.\n */\nexport function getFocalPointWrite({\n current,\n currentFocalPoint,\n incoming,\n queryFocalPoint,\n}: {\n current?: Document\n currentFocalPoint: FocalPoint\n incoming: Document\n queryFocalPoint?: FocalPoint\n}): FocalPoint | undefined {\n if (queryFocalPoint) {\n // Query values arrive as strings.\n return { x: Number(queryFocalPoint.x), y: Number(queryFocalPoint.y) }\n }\n\n // Form data can send numbers as strings.\n const x =\n isNumber(incoming.focalX) && Number(incoming.focalX) !== current?.focalX\n ? Number(incoming.focalX)\n : undefined\n const y =\n isNumber(incoming.focalY) && Number(incoming.focalY) !== current?.focalY\n ? Number(incoming.focalY)\n : undefined\n\n if (x === undefined && y === undefined) {\n return undefined\n }\n\n return { x: x ?? currentFocalPoint.x, y: y ?? currentFocalPoint.y }\n}\n\n/**\n * Applies the legacy inputs to the next `_transforms` value, in this order:\n * 1. An admin editor crop (percent of the original) sets or removes `crop`.\n * 2. A focal point written through `focalX`/`focalY` or the query is saved when it changes. A\n * submitted `_transforms.focalPoint` wins over it.\n * 3. The first write on a document saved before `_transforms` existed keeps its focal point.\n * The center means the same as no focal point, so it is not copied.\n */\nexport function applyLegacyEdits({\n adminCrop,\n currentFocalPoint,\n focalPointWrite,\n isLegacyDocument,\n original,\n state,\n submitted,\n}: {\n adminCrop?: UploadEdits['crop']\n currentFocalPoint: FocalPoint\n focalPointWrite?: FocalPoint\n isLegacyDocument: boolean\n original?: Dimensions\n /** The next value from the general rules. */\n state: TransformState\n submitted?: TransformState\n}): TransformState {\n let next = state\n\n if (adminCrop && original) {\n const { crop: _crop, ...rest } = next ?? {}\n next = isFullCrop(adminCrop)\n ? rest\n : { ...rest, crop: cropToPixels({ crop: adminCrop, original }) }\n }\n\n const writtenFocalPoint = submitted?.focalPoint ?? focalPointWrite\n if (writtenFocalPoint && !isDeepStrictEqual(writtenFocalPoint, currentFocalPoint)) {\n next = { ...next, focalPoint: writtenFocalPoint }\n }\n\n if (\n next &&\n !next.focalPoint &&\n isLegacyDocument &&\n !isDeepStrictEqual(currentFocalPoint, centerFocalPoint)\n ) {\n next = { ...next, focalPoint: currentFocalPoint }\n }\n\n return next\n}\n\n/**\n * The focal point that `focalX`/`focalY` and the pipeline use. A state without a focal point uses\n * the center, unless it never had one. A new file starts from the center too: the stored focal\n * point belongs to the replaced file. A submitted `null` removes all edits, including a focal point\n * saved before `_transforms` existed.\n */\nexport function getNextFocalPoint({\n currentFocalPoint,\n hasNewFile,\n next,\n previous,\n submitted,\n}: {\n currentFocalPoint: FocalPoint\n hasNewFile: boolean\n next: TransformState\n previous: TransformState\n submitted?: TransformState\n}): {\n hasChange: boolean\n /** `focalX`, `focalY` and the pipeline use whole numbers; `_transforms` keeps the exact value. */\n rounded: FocalPoint\n} {\n const nextFocalPoint =\n next?.focalPoint ??\n (previous?.focalPoint || hasNewFile || submitted === null\n ? centerFocalPoint\n : currentFocalPoint)\n\n return {\n hasChange: !isDeepStrictEqual(nextFocalPoint, currentFocalPoint),\n rounded: { x: Math.round(nextFocalPoint.x), y: Math.round(nextFocalPoint.y) },\n }\n}\n\n/**\n * The edits for the upload pipeline. Without a query crop, the crop comes from the saved state:\n * a changed crop or focal point reprocesses the original, and an unchanged crop does not. A\n * removed crop is sent as a crop of the whole original: the rebuild decision and the crop reset\n * (`getCropResetAndFocalPointChange`) read it that way, and the upload bridge gets its size.\n */\nexport function toPipelineEdits({\n hasFocalPointChange,\n hasNewFile,\n next,\n nextFocalPoint,\n original,\n parsedEdits,\n previous,\n}: {\n hasFocalPointChange: boolean\n hasNewFile: boolean\n next: TransformState\n nextFocalPoint: FocalPoint\n original?: Dimensions\n parsedEdits: UploadEdits\n previous: TransformState\n}): UploadEdits {\n let edits = parsedEdits\n\n if (parsedEdits?.focalPoint || hasFocalPointChange) {\n edits = { ...edits, focalPoint: nextFocalPoint }\n }\n\n if (!original) {\n return edits\n }\n\n // A rebuilt file rebuilds its sizes, which must keep the saved focal point.\n const savedFocalPoint = isDeepStrictEqual(nextFocalPoint, centerFocalPoint)\n ? undefined\n : { focalPoint: nextFocalPoint }\n\n // A query crop is applied as sent: its `widthInPixels`/`heightInPixels` can also resize it.\n if (edits?.crop) {\n return { ...savedFocalPoint, ...edits }\n }\n\n const hasCropChange = !isDeepStrictEqual(previous?.crop, next?.crop)\n\n if (next?.crop && (hasNewFile || hasCropChange || hasFocalPointChange)) {\n return { ...savedFocalPoint, ...edits, ...toCropEdits({ crop: next.crop, original }) }\n }\n\n if (previous?.crop && !next?.crop) {\n return {\n ...savedFocalPoint,\n ...edits,\n crop: fullCrop,\n heightInPixels: original.height,\n widthInPixels: original.width,\n }\n }\n\n return edits\n}\n\n/**\n * The edits for a rebuild from the retained original. Another key can cause the rebuild, so the\n * saved crop and focal point are applied again, unless the edits already set them. Without the\n * focal point, the sizes would be built around the center.\n */\nexport function withSavedEdits({\n edits,\n original,\n transforms,\n}: {\n edits: UploadEdits\n original: { height?: null | number; width?: null | number }\n transforms: TransformState | undefined\n}): UploadEdits {\n const savedCrop = transforms?.crop\n const savedFocalPoint = transforms?.focalPoint\n const canApplySavedCrop = !edits?.crop && savedCrop && original.width && original.height\n\n return {\n ...edits,\n ...(canApplySavedCrop\n ? toCropEdits({\n crop: savedCrop,\n original: { height: original.height!, width: original.width! },\n })\n : {}),\n ...(!edits?.focalPoint && savedFocalPoint ? { focalPoint: savedFocalPoint } : {}),\n }\n}\n\n/**\n * A crop or resize in the edits, or a focal point that differs from the one in `fileData`. These\n * triggers rebuilt the stored file before `_transforms` existed.\n */\nexport function hasLegacyCropOrFocalPointEdit({\n fileData,\n uploadEdits,\n}: {\n fileData: Record<string, unknown> | undefined\n uploadEdits: undefined | UploadEdits\n}): boolean {\n if (!fileData || !uploadEdits) {\n return false\n }\n\n if (hasCropOrResizeEdit(uploadEdits)) {\n return true\n }\n\n // Since uploadEdits always has focalPoint, compare to the value in the data if it was changed\n if (uploadEdits.focalPoint) {\n const currentFocalX = 'focalX' in fileData && fileData.focalX\n const currentFocalY = 'focalY' in fileData && fileData.focalY\n\n return !(\n uploadEdits.focalPoint.x === currentFocalX && uploadEdits.focalPoint.y === currentFocalY\n )\n }\n\n return false\n}\n\n/**\n * Whether the edits reset the crop of a document that keeps its original, and whether they change\n * the focal point. A crop reset is a crop of the whole original at its own size. With no other\n * change it reuses the retained original, so the upload bridge does not get its crop size.\n */\nexport function getCropResetAndFocalPointChange({\n currentFileData,\n retainedOriginal,\n uploadEdits,\n}: {\n currentFileData?: FileData\n retainedOriginal?: OriginalFileData\n uploadEdits: UploadEdits\n}): {\n /**\n * The pixel size of the crop in the edits, which a request can send apart from the crop itself.\n * The upload bridge reads the crop from `_transforms`, so only this size is passed to it.\n */\n cropSize?: { height: number; width: number }\n hasFocalPointChange: boolean\n isResettingCrop: boolean\n} {\n const crop = uploadEdits?.crop\n const isResettingCrop = Boolean(\n retainedOriginal &&\n crop &&\n isFullCrop(crop) &&\n (uploadEdits.widthInPixels === undefined ||\n Number(uploadEdits.widthInPixels) === retainedOriginal.width) &&\n (uploadEdits.heightInPixels === undefined ||\n Number(uploadEdits.heightInPixels) === retainedOriginal.height),\n )\n const hasFocalPointChange = Boolean(\n uploadEdits?.focalPoint &&\n (Number(uploadEdits.focalPoint.x) !== (currentFileData?.focalX ?? 50) ||\n Number(uploadEdits.focalPoint.y) !== (currentFileData?.focalY ?? 50)),\n )\n\n return {\n cropSize: isResettingCrop ? undefined : getCropSize({ edits: uploadEdits }),\n hasFocalPointChange,\n isResettingCrop,\n }\n}\n\n/** A saved crop in pixels as the `uploadEdits` crop: percent, plus its output size in pixels. */\nfunction toCropEdits({\n crop,\n original,\n}: {\n crop: NonNullable<NonNullable<TransformState>['crop']>\n original: Dimensions\n}): Pick<UploadEdits, 'crop' | 'heightInPixels' | 'widthInPixels'> {\n return {\n crop: cropToPercent({ crop, original }),\n heightInPixels: crop.height,\n widthInPixels: crop.width,\n }\n}\n\n/** The crop size in the edits, when the edits have a crop and both pixel sizes. */\nfunction getCropSize({\n edits,\n}: {\n edits: undefined | UploadEdits\n}): { height: number; width: number } | undefined {\n if (!edits?.crop || edits.widthInPixels === undefined || edits.heightInPixels === undefined) {\n return undefined\n }\n\n return { height: Number(edits.heightInPixels), width: Number(edits.widthInPixels) }\n}\n"],"names":["isDeepStrictEqual","isNumber","hasCropOrResizeEdit","cropToPercent","cropToPixels","isFullCrop","centerFocalPoint","x","y","fullCrop","height","unit","width","parseLegacyUploadEdits","data","isDuplicating","operation","originalDoc","req","uploadEdits","query","focalPoint","incomingData","origDoc","focalX","focalY","undefined","getCurrentFocalPoint","current","previous","getFocalPointWrite","currentFocalPoint","incoming","queryFocalPoint","Number","applyLegacyEdits","adminCrop","focalPointWrite","isLegacyDocument","original","state","submitted","next","crop","_crop","rest","writtenFocalPoint","getNextFocalPoint","hasNewFile","nextFocalPoint","hasChange","rounded","Math","round","toPipelineEdits","hasFocalPointChange","parsedEdits","edits","savedFocalPoint","hasCropChange","toCropEdits","heightInPixels","widthInPixels","withSavedEdits","transforms","savedCrop","canApplySavedCrop","hasLegacyCropOrFocalPointEdit","fileData","currentFocalX","currentFocalY","getCropResetAndFocalPointChange","currentFileData","retainedOriginal","isResettingCrop","Boolean","cropSize","getCropSize"],"mappings":"AAAA;;;;;CAKC,GACD,SAASA,iBAAiB,QAAQ,YAAW;AAM7C,SAASC,QAAQ,QAAQ,iCAAgC;AACzD,SAASC,mBAAmB,QAAQ,+BAA8B;AAClE,SAASC,aAAa,EAAEC,YAAY,EAAEC,UAAU,QAAQ,oCAAmC;AAE3F,OAAO,MAAMC,mBAA+B;IAAEC,GAA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AAa;IAAE;AACpF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PayloadRequest } from '../../../types/index.js';
|
|
2
|
+
import type { UploadEdits } from '../../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Combines `_transforms`, the `uploadEdits` query and `focalX`/`focalY` into the `_transforms`
|
|
5
|
+
* value to save and the edits that the upload pipeline applies to the original. The general
|
|
6
|
+
* `_transforms` rules are in transformState/transformStateInput.ts, and the older inputs in
|
|
7
|
+
* legacyUploadEdits.ts.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveUploadEdits({ canWaitForFile, collectionSlug, data, file: fileArg, focalPointEnabled, isDuplicating, operation, originalDoc, req, }: {
|
|
10
|
+
/**
|
|
11
|
+
* True when the file is read later in the operation, as on a create from a URL. A saved crop
|
|
12
|
+
* that needs the file's size then returns `isWaitingForFile`, and the caller resolves again
|
|
13
|
+
* with the read `file` before any transformer runs.
|
|
14
|
+
*/
|
|
15
|
+
canWaitForFile?: boolean;
|
|
16
|
+
collectionSlug: string;
|
|
17
|
+
data: unknown;
|
|
18
|
+
/** The new file. Defaults to `req.file`. */
|
|
19
|
+
file?: PayloadRequest['file'];
|
|
20
|
+
focalPointEnabled: boolean;
|
|
21
|
+
isDuplicating?: boolean;
|
|
22
|
+
operation: 'create' | 'update';
|
|
23
|
+
originalDoc: unknown;
|
|
24
|
+
req: PayloadRequest;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
applyTransformState: <T>(fileData: T) => T;
|
|
27
|
+
isWaitingForFile?: boolean;
|
|
28
|
+
uploadEdits: UploadEdits;
|
|
29
|
+
}>;
|
|
30
|
+
//# sourceMappingURL=resolveUploadEdits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveUploadEdits.d.ts","sourceRoot":"","sources":["../../../../src/uploads/generateFileData/edits/resolveUploadEdits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAEvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAmBjD;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,cAAc,EACd,cAAc,EACd,IAAI,EACJ,IAAI,EAAE,OAAO,EACb,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,WAAW,EACX,GAAG,GACJ,EAAE;IACD;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,OAAO,CAAA;IACb,4CAA4C;IAC5C,IAAI,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;IAC7B,iBAAiB,EAAE,OAAO,CAAA;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC9B,WAAW,EAAE,OAAO,CAAA;IACpB,GAAG,EAAE,cAAc,CAAA;CACpB,GAAG,OAAO,CAAC;IACV,mBAAmB,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAA;IAC1C,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,WAAW,EAAE,WAAW,CAAA;CACzB,CAAC,CAqFD"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { isRequestTimeFile } from '../../isRequestTimeFile.js';
|
|
2
|
+
import { assertValidTransformState, getNextTransformState, getOriginalDimensions, readSubmittedTransformState, toSavedTransformState } from '../../transformState/transformStateInput.js';
|
|
3
|
+
import { applyLegacyEdits, getCurrentFocalPoint, getFocalPointWrite, getNextFocalPoint, parseLegacyUploadEdits, toPipelineEdits } from './legacyUploadEdits.js';
|
|
4
|
+
/**
|
|
5
|
+
* Combines `_transforms`, the `uploadEdits` query and `focalX`/`focalY` into the `_transforms`
|
|
6
|
+
* value to save and the edits that the upload pipeline applies to the original. The general
|
|
7
|
+
* `_transforms` rules are in transformState/transformStateInput.ts, and the older inputs in
|
|
8
|
+
* legacyUploadEdits.ts.
|
|
9
|
+
*/ export async function resolveUploadEdits({ canWaitForFile, collectionSlug, data, file: fileArg, focalPointEnabled, isDuplicating, operation, originalDoc, req }) {
|
|
10
|
+
const parsedEdits = parseLegacyUploadEdits({
|
|
11
|
+
data,
|
|
12
|
+
isDuplicating,
|
|
13
|
+
operation,
|
|
14
|
+
// Only a duplication source informs edit parsing. Updates now also pass `originalDoc` so the
|
|
15
|
+
// stored file can be reprocessed, and that must not change which edits are applied.
|
|
16
|
+
originalDoc: isDuplicating ? originalDoc : undefined,
|
|
17
|
+
req
|
|
18
|
+
});
|
|
19
|
+
if (isDuplicating) {
|
|
20
|
+
return {
|
|
21
|
+
applyTransformState: getDuplicateTransformState({
|
|
22
|
+
source: originalDoc
|
|
23
|
+
}),
|
|
24
|
+
uploadEdits: parsedEdits
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const incoming = data ?? {};
|
|
28
|
+
const current = operation === 'update' ? originalDoc : undefined;
|
|
29
|
+
const file = fileArg ?? req.file;
|
|
30
|
+
const hasNewFile = Boolean(file);
|
|
31
|
+
const queryEdits = req.query?.uploadEdits;
|
|
32
|
+
// Crop coordinates belong to the replaced file, so a new file starts without them.
|
|
33
|
+
const previous = hasNewFile ? null : current?._transforms ?? null;
|
|
34
|
+
const submitted = readSubmittedTransformState({
|
|
35
|
+
collectionSlug,
|
|
36
|
+
incoming,
|
|
37
|
+
req
|
|
38
|
+
});
|
|
39
|
+
const hasCrop = Boolean(submitted?.crop || queryEdits?.crop || previous?.crop);
|
|
40
|
+
const original = hasCrop ? await getOriginalDimensions({
|
|
41
|
+
current,
|
|
42
|
+
file
|
|
43
|
+
}) : undefined;
|
|
44
|
+
if ((submitted?.crop || queryEdits?.crop) && !original && canWaitForFile) {
|
|
45
|
+
return {
|
|
46
|
+
applyTransformState: (fileData)=>fileData,
|
|
47
|
+
isWaitingForFile: true,
|
|
48
|
+
uploadEdits: parsedEdits
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (submitted !== undefined) {
|
|
52
|
+
await assertValidTransformState({
|
|
53
|
+
collectionSlug,
|
|
54
|
+
original,
|
|
55
|
+
req,
|
|
56
|
+
submitted
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const currentFocalPoint = getCurrentFocalPoint({
|
|
60
|
+
current,
|
|
61
|
+
previous
|
|
62
|
+
});
|
|
63
|
+
const next = toSavedTransformState({
|
|
64
|
+
state: applyLegacyEdits({
|
|
65
|
+
adminCrop: queryEdits?.crop,
|
|
66
|
+
currentFocalPoint,
|
|
67
|
+
focalPointWrite: getFocalPointWrite({
|
|
68
|
+
current,
|
|
69
|
+
currentFocalPoint,
|
|
70
|
+
incoming,
|
|
71
|
+
queryFocalPoint: queryEdits?.focalPoint
|
|
72
|
+
}),
|
|
73
|
+
isLegacyDocument: !previous && !hasNewFile && operation === 'update',
|
|
74
|
+
original,
|
|
75
|
+
state: getNextTransformState({
|
|
76
|
+
previous,
|
|
77
|
+
submitted
|
|
78
|
+
}),
|
|
79
|
+
submitted
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
const nextFocalPoint = getNextFocalPoint({
|
|
83
|
+
currentFocalPoint,
|
|
84
|
+
hasNewFile,
|
|
85
|
+
next,
|
|
86
|
+
previous,
|
|
87
|
+
submitted
|
|
88
|
+
});
|
|
89
|
+
const uploadEdits = toPipelineEdits({
|
|
90
|
+
hasFocalPointChange: nextFocalPoint.hasChange,
|
|
91
|
+
hasNewFile,
|
|
92
|
+
next,
|
|
93
|
+
nextFocalPoint: nextFocalPoint.rounded,
|
|
94
|
+
original,
|
|
95
|
+
parsedEdits,
|
|
96
|
+
previous
|
|
97
|
+
});
|
|
98
|
+
const applyTransformState = (fileData)=>({
|
|
99
|
+
...fileData,
|
|
100
|
+
...focalPointEnabled && (next?.focalPoint || nextFocalPoint.hasChange) ? {
|
|
101
|
+
focalX: nextFocalPoint.rounded.x,
|
|
102
|
+
focalY: nextFocalPoint.rounded.y
|
|
103
|
+
} : {},
|
|
104
|
+
_transforms: next
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
applyTransformState,
|
|
108
|
+
uploadEdits
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A duplicate is made from the source's cropped main file, which becomes the copy's original.
|
|
113
|
+
* The crop is already part of those files, so the copy keeps every other key but not `crop`.
|
|
114
|
+
* generateFileData then also drops the other keys that a stage claims. A source with no stored
|
|
115
|
+
* main file is copied from its original, so its copy keeps every key.
|
|
116
|
+
*/ function getDuplicateTransformState({ source }) {
|
|
117
|
+
if (isRequestTimeFile({
|
|
118
|
+
entry: source
|
|
119
|
+
})) {
|
|
120
|
+
return (fileData)=>fileData;
|
|
121
|
+
}
|
|
122
|
+
return (fileData)=>{
|
|
123
|
+
const { crop: _crop, ...rest } = fileData._transforms ?? {};
|
|
124
|
+
return {
|
|
125
|
+
...fileData,
|
|
126
|
+
_transforms: Object.keys(rest).length ? rest : null
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=resolveUploadEdits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/uploads/generateFileData/edits/resolveUploadEdits.ts"],"sourcesContent":["import type { Document, PayloadRequest } from '../../../types/index.js'\nimport type { TransformState } from '../../transformState/transformStateInput.js'\nimport type { UploadEdits } from '../../types.js'\n\nimport { isRequestTimeFile } from '../../isRequestTimeFile.js'\nimport {\n assertValidTransformState,\n getNextTransformState,\n getOriginalDimensions,\n readSubmittedTransformState,\n toSavedTransformState,\n} from '../../transformState/transformStateInput.js'\nimport {\n applyLegacyEdits,\n getCurrentFocalPoint,\n getFocalPointWrite,\n getNextFocalPoint,\n parseLegacyUploadEdits,\n toPipelineEdits,\n} from './legacyUploadEdits.js'\n\n/**\n * Combines `_transforms`, the `uploadEdits` query and `focalX`/`focalY` into the `_transforms`\n * value to save and the edits that the upload pipeline applies to the original. The general\n * `_transforms` rules are in transformState/transformStateInput.ts, and the older inputs in\n * legacyUploadEdits.ts.\n */\nexport async function resolveUploadEdits({\n canWaitForFile,\n collectionSlug,\n data,\n file: fileArg,\n focalPointEnabled,\n isDuplicating,\n operation,\n originalDoc,\n req,\n}: {\n /**\n * True when the file is read later in the operation, as on a create from a URL. A saved crop\n * that needs the file's size then returns `isWaitingForFile`, and the caller resolves again\n * with the read `file` before any transformer runs.\n */\n canWaitForFile?: boolean\n collectionSlug: string\n data: unknown\n /** The new file. Defaults to `req.file`. */\n file?: PayloadRequest['file']\n focalPointEnabled: boolean\n isDuplicating?: boolean\n operation: 'create' | 'update'\n originalDoc: unknown\n req: PayloadRequest\n}): Promise<{\n applyTransformState: <T>(fileData: T) => T\n isWaitingForFile?: boolean\n uploadEdits: UploadEdits\n}> {\n const parsedEdits = parseLegacyUploadEdits({\n data,\n isDuplicating,\n operation,\n // Only a duplication source informs edit parsing. Updates now also pass `originalDoc` so the\n // stored file can be reprocessed, and that must not change which edits are applied.\n originalDoc: isDuplicating ? originalDoc : undefined,\n req,\n })\n\n if (isDuplicating) {\n return {\n applyTransformState: getDuplicateTransformState({ source: originalDoc as Document }),\n uploadEdits: parsedEdits,\n }\n }\n\n const incoming = (data ?? {}) as Document\n const current = (operation === 'update' ? originalDoc : undefined) as Document\n const file = fileArg ?? req.file\n const hasNewFile = Boolean(file)\n const queryEdits = req.query?.uploadEdits as undefined | UploadEdits\n // Crop coordinates belong to the replaced file, so a new file starts without them.\n const previous: TransformState = hasNewFile ? null : (current?._transforms ?? null)\n const submitted = readSubmittedTransformState({ collectionSlug, incoming, req })\n const hasCrop = Boolean(submitted?.crop || queryEdits?.crop || previous?.crop)\n const original = hasCrop ? await getOriginalDimensions({ current, file }) : undefined\n\n if ((submitted?.crop || queryEdits?.crop) && !original && canWaitForFile) {\n return {\n applyTransformState: (fileData) => fileData,\n isWaitingForFile: true,\n uploadEdits: parsedEdits,\n }\n }\n\n if (submitted !== undefined) {\n await assertValidTransformState({ collectionSlug, original, req, submitted })\n }\n\n const currentFocalPoint = getCurrentFocalPoint({ current, previous })\n const next = toSavedTransformState({\n state: applyLegacyEdits({\n adminCrop: queryEdits?.crop,\n currentFocalPoint,\n focalPointWrite: getFocalPointWrite({\n current,\n currentFocalPoint,\n incoming,\n queryFocalPoint: queryEdits?.focalPoint,\n }),\n isLegacyDocument: !previous && !hasNewFile && operation === 'update',\n original,\n state: getNextTransformState({ previous, submitted }),\n submitted,\n }),\n })\n const nextFocalPoint = getNextFocalPoint({\n currentFocalPoint,\n hasNewFile,\n next,\n previous,\n submitted,\n })\n\n const uploadEdits = toPipelineEdits({\n hasFocalPointChange: nextFocalPoint.hasChange,\n hasNewFile,\n next,\n nextFocalPoint: nextFocalPoint.rounded,\n original,\n parsedEdits,\n previous,\n })\n\n const applyTransformState = <T>(fileData: T): T => ({\n ...fileData,\n ...(focalPointEnabled && (next?.focalPoint || nextFocalPoint.hasChange)\n ? { focalX: nextFocalPoint.rounded.x, focalY: nextFocalPoint.rounded.y }\n : {}),\n _transforms: next,\n })\n\n return { applyTransformState, uploadEdits }\n}\n\n/**\n * A duplicate is made from the source's cropped main file, which becomes the copy's original.\n * The crop is already part of those files, so the copy keeps every other key but not `crop`.\n * generateFileData then also drops the other keys that a stage claims. A source with no stored\n * main file is copied from its original, so its copy keeps every key.\n */\nfunction getDuplicateTransformState({ source }: { source: Document }): <T>(fileData: T) => T {\n if (isRequestTimeFile({ entry: source })) {\n return (fileData) => fileData\n }\n\n return <T>(fileData: T): T => {\n const { crop: _crop, ...rest } = ((fileData as Document)._transforms ?? {}) as Document\n\n return { ...fileData, _transforms: Object.keys(rest).length ? rest : null }\n }\n}\n"],"names":["isRequestTimeFile","assertValidTransformState","getNextTransformState","getOriginalDimensions","readSubmittedTransformState","toSavedTransformState","applyLegacyEdits","getCurrentFocalPoint","getFocalPointWrite","getNextFocalPoint","parseLegacyUploadEdits","toPipelineEdits","resolveUploadEdits","canWaitForFile","collectionSlug","data","file","fileArg","focalPointEnabled","isDuplicating","operation","originalDoc","req","parsedEdits","undefined","applyTransformState","getDuplicateTransformState","source","uploadEdits","incoming","current","hasNewFile","Boolean","queryEdits","query","previous","_transforms","submitted","hasCrop","crop","original","fileData","isWaitingForFile","currentFocalPoint","next","state","adminCrop","focalPointWrite","queryFocalPoint","focalPoint","isLegacyDocument","nextFocalPoint","hasFocalPointChange","hasChange","rounded","focalX","x","focalY","y","entry","_crop","rest","Object","keys","length"],"mappings":"AAIA,SAASA,iBAAiB,QAAQ,6BAA4B;AAC9D,SACEC,yBAAyB,EACzBC,qBAAqB,EACrBC,qBAAqB,EACrBC,2BAA2B,EAC3BC,qBAAqB,QAChB,8CAA6C;AACpD,SACEC,gBAAgB,EAChBC,oBAAoB,EACpBC,kBAAkB,EAClBC,iBAAiB,EACjBC,sBAAsB,EACtBC,eAAe,QACV,yBAAwB;AAE/B;;;;;CAKC,GACD,OAAO,eAAeC,mBAAmB,EACvCC,cAAc,EACdC,cAAc,EACdC,IAAI,EACJC,MAAMC,OAAO,EACbC,iBAAiB,EACjBC,aAAa,EACbC,SAAS,EACTC,WAAW,EACXC,GAAG,EAiBJ;IAKC,MAAMC,cAAcb,uBAAuB;QACzCK;QACAI;QACAC;QACA,6FAA6F;QAC7F,oFAAoF;QACpFC,aAAaF,gBAAgBE,cAAcG;QAC3CF;IACF;IAEA,IAAIH,eAAe;QACjB,OAAO;YACLM,qBAAqBC,2BAA2B;gBAAEC,QAAQN;YAAwB;YAClFO,aAAaL;QACf;IACF;IAEA,MAAMM,WAAYd,QAAQ,CAAC;IAC3B,MAAMe,UAAWV,cAAc,WAAWC,cAAcG;IACxD,MAAMR,OAAOC,WAAWK,IAAIN,IAAI;IAChC,MAAMe,aAAaC,QAAQhB;IAC3B,MAAMiB,aAAaX,IAAIY,KAAK,EAAEN;IAC9B,mFAAmF;IACnF,MAAMO,WAA2BJ,aAAa,OAAQD,SAASM,eAAe;IAC9E,MAAMC,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NtB,aAAaQ;QACf,CAAA;IAEA,OAAO;QAAEnB;QAAqBG;IAAY;AAC5C;AAEA;;;;;CAKC,GACD,SAASF,2BAA2B,EAAEC,MAAM,EAAwB;IAClE,IAAI3B,kBAAkB;QAAE2D,OAAOhC;IAAO,IAAI;QACxC,OAAO,CAACc,WAAaA;IACvB;IAEA,OAAO,CAAIA;QACT,MAAM,EAAEF,MAAMqB,KAAK,EAAE,GAAGC,MAAM,GAAI,AAACpB,SAAsBL,WAAW,IAAI,CAAC;QAEzE,OAAO;YAAE,GAAGK,QAAQ;YAAEL,aAAa0B,OAAOC,IAAI,CAACF,MAAMG,MAAM,GAAGH,OAAO;QAAK;IAC5E;AACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Collection } from '../../collections/config/types.js';
|
|
2
|
+
import type { SanitizedConfig } from '../../config/types.js';
|
|
3
|
+
import type { PayloadRequest } from '../../types/index.js';
|
|
4
|
+
import type { ExternalUploadSource } from '../sanitizeUploadData.js';
|
|
5
|
+
import type { FileToSave } from '../types.js';
|
|
6
|
+
import { fetchFullClientUpload as downloadFullClientUpload } from '../getFileFromUploadInstructions.js';
|
|
7
|
+
type Args<T> = {
|
|
8
|
+
collection: Collection;
|
|
9
|
+
config: SanitizedConfig;
|
|
10
|
+
data: T;
|
|
11
|
+
draft?: boolean;
|
|
12
|
+
externalUploadSource?: ExternalUploadSource;
|
|
13
|
+
/**
|
|
14
|
+
* Downloads a client upload that arrived without its whole contents. Defaults to
|
|
15
|
+
* `fetchFullClientUpload`. A bulk update passes a shared download, so its documents download
|
|
16
|
+
* the file once.
|
|
17
|
+
*/
|
|
18
|
+
fetchFullClientUpload?: typeof downloadFullClientUpload;
|
|
19
|
+
isDuplicating?: boolean;
|
|
20
|
+
operation: 'create' | 'update';
|
|
21
|
+
originalDoc?: T;
|
|
22
|
+
overwriteExistingFiles?: boolean;
|
|
23
|
+
req: PayloadRequest;
|
|
24
|
+
throwOnMissingFile?: boolean;
|
|
25
|
+
};
|
|
26
|
+
type Result<T> = Promise<{
|
|
27
|
+
data: T;
|
|
28
|
+
files: FileToSave[];
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Builds the document's file metadata and the list of files to write to disk.
|
|
32
|
+
*
|
|
33
|
+
* ```
|
|
34
|
+
* resolve edits → select the source → decide whether processing is needed
|
|
35
|
+
* → read the source and plan the stages → run the transformers → build and assemble the result
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* A source is read only when the operation needs its bytes. A request-time file and an unchanged
|
|
39
|
+
* upload often need none. A large client upload may arrive as a temp file instead of an in-memory
|
|
40
|
+
* buffer (see getFileFromUploadInstructions.ts), and `file.data` can hold only a partial probe
|
|
41
|
+
* rather than the full file. To avoid loading such files into memory unnecessarily, no
|
|
42
|
+
* transformer runs unless the full bytes are available, a temp file is not read when local
|
|
43
|
+
* storage is disabled, and it is copied straight to its destination when local storage is enabled.
|
|
44
|
+
*/
|
|
45
|
+
export declare const generateFileData: <T>(args: Args<T>) => Result<T>;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/uploads/generateFileData/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,mCAAmC,CAAA;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AACpE,OAAO,KAAK,EAAY,UAAU,EAAE,MAAM,aAAa,CAAA;AAKvD,OAAO,EAAE,qBAAqB,IAAI,wBAAwB,EAAE,MAAM,qCAAqC,CAAA;AAgBvG,KAAK,IAAI,CAAC,CAAC,IAAI;IACb,UAAU,EAAE,UAAU,CAAA;IACtB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