payload 3.0.0-beta.34 → 3.0.0-beta.35
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/sendVerificationEmail.js +1 -1
- package/dist/auth/sendVerificationEmail.js.map +1 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +1 -0
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +1 -0
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +1 -0
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/exports/utilities.d.ts +1 -1
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +1 -1
- package/dist/exports/utilities.js.map +1 -1
- package/dist/types/index.d.ts +0 -12
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/uploads/canResizeImage.d.ts +1 -1
- package/dist/uploads/canResizeImage.d.ts.map +1 -1
- package/dist/uploads/canResizeImage.js +1 -1
- package/dist/uploads/canResizeImage.js.map +1 -1
- package/dist/uploads/cropImage.d.ts +1 -1
- package/dist/uploads/cropImage.d.ts.map +1 -1
- package/dist/uploads/cropImage.js +1 -1
- package/dist/uploads/cropImage.js.map +1 -1
- package/dist/uploads/generateFileData.d.ts +3 -1
- package/dist/uploads/generateFileData.d.ts.map +1 -1
- package/dist/uploads/generateFileData.js +50 -12
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getBaseFields.d.ts.map +1 -1
- package/dist/uploads/getBaseFields.js +15 -0
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/getSafeFilename.d.ts +2 -2
- package/dist/uploads/getSafeFilename.d.ts.map +1 -1
- package/dist/uploads/getSafeFilename.js +1 -2
- package/dist/uploads/getSafeFilename.js.map +1 -1
- package/dist/uploads/imageResizer.d.ts +7 -9
- package/dist/uploads/imageResizer.d.ts.map +1 -1
- package/dist/uploads/imageResizer.js +42 -24
- package/dist/uploads/imageResizer.js.map +1 -1
- package/dist/uploads/isImage.d.ts +1 -1
- package/dist/uploads/isImage.d.ts.map +1 -1
- package/dist/uploads/isImage.js +1 -1
- package/dist/uploads/isImage.js.map +1 -1
- package/dist/uploads/types.d.ts +14 -0
- package/dist/uploads/types.d.ts.map +1 -1
- package/dist/uploads/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/uploads/imageResizer.ts"],"sourcesContent":["import type { OutputInfo } from 'sharp'\n\nimport fileType from 'file-type'\nconst { fromBuffer } = fileType\n\nimport fs from 'fs'\nimport sanitize from 'sanitize-filename'\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SharpDependency } from '../config/types.js'\nimport type { PayloadRequestWithData, UploadEdits } from '../types/index.js'\nimport type { FileSize, FileSizes, FileToSave, ImageSize, ProbedImageSize } from './types.js'\n\nimport { isNumber } from '../utilities/isNumber.js'\nimport fileExists from './fileExists.js'\n\ntype ResizeArgs = {\n config: SanitizedCollectionConfig\n dimensions: ProbedImageSize\n file: PayloadRequestWithData['file']\n mimeType: string\n req: PayloadRequestWithData & {\n query?: {\n uploadEdits?: UploadEdits\n }\n }\n savedFilename: string\n sharp: SharpDependency\n staticPath: string\n}\n\n/** Result from resizing and transforming the requested image sizes */\ntype ImageSizesResult = {\n sizeData: FileSizes\n sizesToSave: FileToSave[]\n}\n\ntype SanitizedImageData = {\n ext: string\n name: string\n}\n\n/**\n * Sanitize the image name and extract the extension from the source image\n *\n * @param sourceImage - the source image\n * @returns the sanitized name and extension\n */\nconst getSanitizedImageData = (sourceImage: string): SanitizedImageData => {\n const extension = sourceImage.split('.').pop()\n const name = sanitize(sourceImage.substring(0, sourceImage.lastIndexOf('.')) || sourceImage)\n return { name, ext: extension }\n}\n\n/**\n * Create a new image name based on the output image name, the dimensions and\n * the extension.\n *\n * Ignore the fact that duplicate names could happen if the there is one\n * size with `width AND height` and one with only `height OR width`. Because\n * space is expensive, we will reuse the same image for both sizes.\n *\n * @param outputImageName - the sanitized image name\n * @param bufferInfo - the buffer info\n * @param extension - the extension to use\n * @returns the new image name that is not taken\n */\nconst createImageName = (\n outputImageName: string,\n { height, width }: OutputInfo,\n extension: string,\n) => `${outputImageName}-${width}x${height}.${extension}`\n\n/**\n * Create the result object for the image resize operation based on the\n * provided parameters. If the name is not provided, an empty result object\n * is returned.\n *\n * @param name - the name of the image\n * @param filename - the filename of the image\n * @param width - the width of the image\n * @param height - the height of the image\n * @param filesize - the filesize of the image\n * @param mimeType - the mime type of the image\n * @param sizesToSave - the sizes to save\n * @returns the result object\n */\nconst createResult = (\n name: string,\n filename: FileSize['filename'] = null,\n width: FileSize['width'] = null,\n height: FileSize['height'] = null,\n filesize: FileSize['filesize'] = null,\n mimeType: FileSize['mimeType'] = null,\n sizesToSave: FileToSave[] = [],\n): ImageSizesResult => ({\n sizeData: {\n [name]: {\n filename,\n filesize,\n height,\n mimeType,\n width,\n },\n },\n sizesToSave,\n})\n\n/**\n * Check if the image needs to be resized according to the requested dimensions\n * and the original image size. If the resize options withoutEnlargement or withoutReduction are provided,\n * the image will be resized regardless of the requested dimensions, given that the\n * width or height to be resized is provided.\n *\n * @param resizeConfig - object containing the requested dimensions and resize options\n * @param original - the original image size\n * @returns true if resizing is not needed, false otherwise\n */\nconst preventResize = (\n { height: desiredHeight, width: desiredWidth, withoutEnlargement, withoutReduction }: ImageSize,\n original: ProbedImageSize,\n): boolean => {\n // default is to allow reduction\n if (withoutReduction !== undefined) {\n return false // needs resize\n }\n\n // default is to prevent enlargement\n if (withoutEnlargement !== undefined) {\n return false // needs resize\n }\n\n const isWidthOrHeightNotDefined = !desiredHeight || !desiredWidth\n if (isWidthOrHeightNotDefined) {\n // If width and height are not defined, it means there is a format conversion\n // and the image needs to be \"resized\" (transformed).\n return false // needs resize\n }\n\n const hasInsufficientWidth = desiredWidth > original.width\n const hasInsufficientHeight = desiredHeight > original.height\n if (hasInsufficientWidth && hasInsufficientHeight) {\n // doesn't need resize - prevent enlargement. This should only happen if both width and height are insufficient.\n // if only one dimension is insufficient and the other is sufficient, resizing needs to happen, as the image\n // should be resized to the sufficient dimension.\n return true // do not create a new size\n }\n\n return false // needs resize\n}\n\n/**\n * Check if the image should be passed directly to sharp without payload adjusting properties.\n *\n * @param resizeConfig - object containing the requested dimensions and resize options\n * @param original - the original image size\n * @returns true if the image should passed directly to sharp\n */\nconst applyPayloadAdjustments = (\n { fit, height, width, withoutEnlargement, withoutReduction }: ImageSize,\n original: ProbedImageSize,\n) => {\n if (fit === 'contain' || fit === 'inside') return false\n if (!isNumber(height) && !isNumber(width)) return false\n\n const targetAspectRatio = width / height\n const originalAspectRatio = original.width / original.height\n if (originalAspectRatio === targetAspectRatio) return false\n\n const skipEnlargement = withoutEnlargement && (original.height < height || original.width < width)\n const skipReduction = withoutReduction && (original.height > height || original.width > width)\n if (skipEnlargement || skipReduction) return false\n\n return true\n}\n\n/**\n * Sanitize the resize config. If the resize config has the `withoutReduction`\n * property set to true, the `fit` and `position` properties will be set to `contain`\n * and `top left` respectively.\n *\n * @param resizeConfig - the resize config\n * @returns a sanitized resize config\n */\nconst sanitizeResizeConfig = (resizeConfig: ImageSize): ImageSize => {\n if (resizeConfig.withoutReduction) {\n return {\n ...resizeConfig,\n // Why fit `contain` should also be set to https://github.com/lovell/sharp/issues/3595\n fit: resizeConfig?.fit || 'contain',\n position: resizeConfig?.position || 'left top',\n }\n }\n return resizeConfig\n}\n\n/**\n * For the provided image sizes, handle the resizing and the transforms\n * (format, trim, etc.) of each requested image size and return the result object.\n * This only handles the image sizes. The transforms of the original image\n * are handled in {@link ./generateFileData.ts}.\n *\n * The image will be resized according to the provided\n * resize config. If no image sizes are requested, the resolved data will be empty.\n * For every image that dos not need to be resized, an result object with `null`\n * parameters will be returned.\n *\n * @param resizeConfig - the resize config\n * @returns the result of the resize operation(s)\n */\nexport default async function resizeAndTransformImageSizes({\n config,\n dimensions,\n file,\n mimeType,\n req,\n savedFilename,\n sharp,\n staticPath,\n}: ResizeArgs): Promise<ImageSizesResult> {\n const { imageSizes } = config.upload\n // Noting to resize here so return as early as possible\n if (!imageSizes) return { sizeData: {}, sizesToSave: [] }\n\n const sharpBase = sharp(file.tempFilePath || file.data).rotate() // pass rotate() to auto-rotate based on EXIF data. https://github.com/payloadcms/payload/pull/3081\n\n const results: ImageSizesResult[] = await Promise.all(\n imageSizes.map(async (imageResizeConfig): Promise<ImageSizesResult> => {\n imageResizeConfig = sanitizeResizeConfig(imageResizeConfig)\n\n // This checks if a resize should happen. If not, the resized image will be\n // skipped COMPLETELY and thus will not be included in the resulting images.\n // All further format/trim options will thus be skipped as well.\n if (preventResize(imageResizeConfig, dimensions)) {\n return createResult(imageResizeConfig.name)\n }\n\n const imageToResize = sharpBase.clone()\n let resized = imageToResize\n\n if (\n req.query?.uploadEdits?.focalPoint &&\n applyPayloadAdjustments(imageResizeConfig, dimensions)\n ) {\n const { height: resizeHeight, width: resizeWidth } = imageResizeConfig\n const resizeAspectRatio = resizeWidth / resizeHeight\n const originalAspectRatio = dimensions.width / dimensions.height\n const prioritizeHeight = resizeAspectRatio < originalAspectRatio\n\n // Scale the image up or down to fit the resize dimensions\n const scaledImage = imageToResize.resize({\n height: prioritizeHeight ? resizeHeight : null,\n width: prioritizeHeight ? null : resizeWidth,\n })\n const { info: scaledImageInfo } = await scaledImage.toBuffer({ resolveWithObject: true })\n\n // Focal point adjustments\n const focalPoint = {\n x: isNumber(req.query.uploadEdits.focalPoint?.x)\n ? req.query.uploadEdits.focalPoint.x\n : 50,\n y: isNumber(req.query.uploadEdits.focalPoint?.y)\n ? req.query.uploadEdits.focalPoint.y\n : 50,\n }\n\n const safeResizeWidth = resizeWidth ?? scaledImageInfo.width\n const maxOffsetX = scaledImageInfo.width - safeResizeWidth\n const leftFocalEdge = Math.round(\n scaledImageInfo.width * (focalPoint.x / 100) - safeResizeWidth / 2,\n )\n const safeOffsetX = Math.min(Math.max(0, leftFocalEdge), maxOffsetX)\n\n const safeResizeHeight = resizeHeight ?? scaledImageInfo.height\n const maxOffsetY = scaledImageInfo.height - safeResizeHeight\n const topFocalEdge = Math.round(\n scaledImageInfo.height * (focalPoint.y / 100) - safeResizeHeight / 2,\n )\n const safeOffsetY = Math.min(Math.max(0, topFocalEdge), maxOffsetY)\n\n // extract the focal area from the scaled image\n resized = scaledImage.extract({\n height: safeResizeHeight,\n left: safeOffsetX,\n top: safeOffsetY,\n width: safeResizeWidth,\n })\n } else {\n resized = imageToResize.resize(imageResizeConfig)\n }\n\n if (imageResizeConfig.formatOptions) {\n resized = resized.toFormat(\n imageResizeConfig.formatOptions.format,\n imageResizeConfig.formatOptions.options,\n )\n }\n\n if (imageResizeConfig.trimOptions) {\n resized = resized.trim(imageResizeConfig.trimOptions)\n }\n\n const { data: bufferData, info: bufferInfo } = await resized.toBuffer({\n resolveWithObject: true,\n })\n\n const sanitizedImage = getSanitizedImageData(savedFilename)\n\n req.payloadUploadSizes[imageResizeConfig.name] = bufferData\n\n const mimeInfo = await fromBuffer(bufferData)\n\n const imageNameWithDimensions = createImageName(\n sanitizedImage.name,\n bufferInfo,\n mimeInfo?.ext || sanitizedImage.ext,\n )\n\n const imagePath = `${staticPath}/${imageNameWithDimensions}`\n\n if (await fileExists(imagePath)) {\n try {\n fs.unlinkSync(imagePath)\n } catch {\n // Ignore unlink errors\n }\n }\n\n const { height, size, width } = bufferInfo\n return createResult(\n imageResizeConfig.name,\n imageNameWithDimensions,\n width,\n height,\n size,\n mimeInfo?.mime || mimeType,\n [{ buffer: bufferData, path: imagePath }],\n )\n }),\n )\n\n return results.reduce(\n (acc, result) => {\n Object.assign(acc.sizeData, result.sizeData)\n acc.sizesToSave.push(...result.sizesToSave)\n return acc\n },\n { sizeData: {}, sizesToSave: [] },\n )\n}\n"],"names":["fileType","fromBuffer","fs","sanitize","isNumber","fileExists","getSanitizedImageData","sourceImage","extension","split","pop","name","substring","lastIndexOf","ext","createImageName","outputImageName","height","width","createResult","filename","filesize","mimeType","sizesToSave","sizeData","preventResize","desiredHeight","desiredWidth","withoutEnlargement","withoutReduction","original","undefined","isWidthOrHeightNotDefined","hasInsufficientWidth","hasInsufficientHeight","applyPayloadAdjustments","fit","targetAspectRatio","originalAspectRatio","skipEnlargement","skipReduction","sanitizeResizeConfig","resizeConfig","position","resizeAndTransformImageSizes","config","dimensions","file","req","savedFilename","sharp","staticPath","imageSizes","upload","sharpBase","tempFilePath","data","rotate","results","Promise","all","map","imageResizeConfig","imageToResize","clone","resized","query","uploadEdits","focalPoint","resizeHeight","resizeWidth","resizeAspectRatio","prioritizeHeight","scaledImage","resize","info","scaledImageInfo","toBuffer","resolveWithObject","x","y","safeResizeWidth","maxOffsetX","leftFocalEdge","Math","round","safeOffsetX","min","max","safeResizeHeight","maxOffsetY","topFocalEdge","safeOffsetY","extract","left","top","formatOptions","toFormat","format","options","trimOptions","trim","bufferData","bufferInfo","sanitizedImage","payloadUploadSizes","mimeInfo","imageNameWithDimensions","imagePath","unlinkSync","size","mime","buffer","path","reduce","acc","result","Object","assign","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,cAAc,YAAW;AAChC,MAAM,EAAEC,UAAU,EAAE,GAAGD;AAEvB,OAAOE,QAAQ,KAAI;AACnB,OAAOC,cAAc,oBAAmB;AAOxC,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,OAAOC,gBAAgB,kBAAiB;AA4B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0BAA0B5F,gBAC9ByF,eAAe7F,IAAI,EACnB4F,YACAG,UAAU5F,OAAO0F,eAAe1F,GAAG;QAGrC,MAAM8F,YAAY,CAAC,EAAEzD,WAAW,CAAC,EAAEwD,wBAAwB,CAAC;QAE5D,IAAI,MAAMtG,WAAWuG,YAAY;YAC/B,IAAI;gBACF1G,GAAG2G,UAAU,CAACD;YAChB,EAAE,OAAM;YACN,uBAAuB;YACzB;QACF;QAEA,MAAM,EAAE3F,MAAM,EAAE6F,IAAI,EAAE5F,KAAK,EAAE,GAAGqF;QAChC,OAAOpF,aACL2C,kBAAkBnD,IAAI,EACtBgG,yBACAzF,OACAD,QACA6F,MACAJ,UAAUK,QAAQzF,UAClB;YAAC;gBAAE0F,QAAQV;gBAAYW,MAAML;YAAU;SAAE;IAE7C;IAGF,OAAOlD,QAAQwD,MAAM,CACnB,CAACC,KAAKC;QACJC,OAAOC,MAAM,CAACH,IAAI3F,QAAQ,EAAE4F,OAAO5F,QAAQ;QAC3C2F,IAAI5F,WAAW,CAACgG,IAAI,IAAIH,OAAO7F,WAAW;QAC1C,OAAO4F;IACT,GACA;QAAE3F,UAAU,CAAC;QAAGD,aAAa,EAAE;IAAC;AAEpC"}
|
|
1
|
+
{"version":3,"sources":["../../src/uploads/imageResizer.ts"],"sourcesContent":["import type { OutputInfo } from 'sharp'\n\nimport fileType from 'file-type'\nconst { fromBuffer } = fileType\n\nimport fs from 'fs'\nimport sanitize from 'sanitize-filename'\n\nimport type { SanitizedCollectionConfig } from '../collections/config/types.js'\nimport type { SharpDependency } from '../config/types.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\nimport type {\n FileSize,\n FileSizes,\n FileToSave,\n ImageSize,\n ProbedImageSize,\n UploadEdits,\n} from './types.js'\n\nimport { isNumber } from '../utilities/isNumber.js'\nimport fileExists from './fileExists.js'\n\ntype ResizeArgs = {\n config: SanitizedCollectionConfig\n dimensions: ProbedImageSize\n file: PayloadRequestWithData['file']\n mimeType: string\n req: PayloadRequestWithData\n savedFilename: string\n sharp?: SharpDependency\n staticPath: string\n uploadEdits?: UploadEdits\n}\n\n/** Result from resizing and transforming the requested image sizes */\ntype ImageSizesResult = {\n focalPoint?: UploadEdits['focalPoint']\n sizeData: FileSizes\n sizesToSave: FileToSave[]\n}\n\ntype SanitizedImageData = {\n ext: string\n name: string\n}\n\n/**\n * Sanitize the image name and extract the extension from the source image\n *\n * @param sourceImage - the source image\n * @returns the sanitized name and extension\n */\nconst getSanitizedImageData = (sourceImage: string): SanitizedImageData => {\n const extension = sourceImage.split('.').pop()\n const name = sanitize(sourceImage.substring(0, sourceImage.lastIndexOf('.')) || sourceImage)\n return { name, ext: extension }\n}\n\n/**\n * Create a new image name based on the output image name, the dimensions and\n * the extension.\n *\n * Ignore the fact that duplicate names could happen if the there is one\n * size with `width AND height` and one with only `height OR width`. Because\n * space is expensive, we will reuse the same image for both sizes.\n *\n * @param outputImageName - the sanitized image name\n * @param bufferInfo - the buffer info\n * @param extension - the extension to use\n * @returns the new image name that is not taken\n */\nconst createImageName = (\n outputImageName: string,\n { height, width }: OutputInfo,\n extension: string,\n) => `${outputImageName}-${width}x${height}.${extension}`\n\ntype CreateResultArgs = {\n filename?: FileSize['filename']\n filesize?: FileSize['filesize']\n height?: FileSize['height']\n mimeType?: FileSize['mimeType']\n name: string\n sizesToSave?: FileToSave[]\n width?: FileSize['width']\n}\n\n/**\n * Create the result object for the image resize operation based on the\n * provided parameters. If the name is not provided, an empty result object\n * is returned.\n *\n * @param name - the name of the image\n * @param filename - the filename of the image\n * @param width - the width of the image\n * @param height - the height of the image\n * @param filesize - the filesize of the image\n * @param mimeType - the mime type of the image\n * @param sizesToSave - the sizes to save\n * @returns the result object\n */\nconst createResult = ({\n name,\n filename = null,\n filesize = null,\n height = null,\n mimeType = null,\n sizesToSave = [],\n width = null,\n}: CreateResultArgs): ImageSizesResult => {\n return {\n sizeData: {\n [name]: {\n filename,\n filesize,\n height,\n mimeType,\n width,\n },\n },\n sizesToSave,\n }\n}\n\n/**\n * Check if the image needs to be resized according to the requested dimensions\n * and the original image size. If the resize options withoutEnlargement or withoutReduction are provided,\n * the image will be resized regardless of the requested dimensions, given that the\n * width or height to be resized is provided.\n *\n * @param resizeConfig - object containing the requested dimensions and resize options\n * @param original - the original image size\n * @returns true if resizing is not needed, false otherwise\n */\nconst preventResize = (\n { height: desiredHeight, width: desiredWidth, withoutEnlargement, withoutReduction }: ImageSize,\n original: ProbedImageSize,\n): boolean => {\n // default is to allow reduction\n if (withoutReduction !== undefined) {\n return false // needs resize\n }\n\n // default is to prevent enlargement\n if (withoutEnlargement !== undefined) {\n return false // needs resize\n }\n\n const isWidthOrHeightNotDefined = !desiredHeight || !desiredWidth\n if (isWidthOrHeightNotDefined) {\n // If width and height are not defined, it means there is a format conversion\n // and the image needs to be \"resized\" (transformed).\n return false // needs resize\n }\n\n const hasInsufficientWidth = desiredWidth > original.width\n const hasInsufficientHeight = desiredHeight > original.height\n if (hasInsufficientWidth && hasInsufficientHeight) {\n // doesn't need resize - prevent enlargement. This should only happen if both width and height are insufficient.\n // if only one dimension is insufficient and the other is sufficient, resizing needs to happen, as the image\n // should be resized to the sufficient dimension.\n return true // do not create a new size\n }\n\n return false // needs resize\n}\n\n/**\n * Check if the image should be passed directly to sharp without payload adjusting properties.\n *\n * @param resizeConfig - object containing the requested dimensions and resize options\n * @param original - the original image size\n * @returns true if the image should passed directly to sharp\n */\nconst applyPayloadAdjustments = (\n { fit, height, width, withoutEnlargement, withoutReduction }: ImageSize,\n original: ProbedImageSize,\n) => {\n if (fit === 'contain' || fit === 'inside') return false\n if (!isNumber(height) && !isNumber(width)) return false\n\n const targetAspectRatio = width / height\n const originalAspectRatio = original.width / original.height\n if (originalAspectRatio === targetAspectRatio) return false\n\n const skipEnlargement = withoutEnlargement && (original.height < height || original.width < width)\n const skipReduction = withoutReduction && (original.height > height || original.width > width)\n if (skipEnlargement || skipReduction) return false\n\n return true\n}\n\n/**\n * Sanitize the resize config. If the resize config has the `withoutReduction`\n * property set to true, the `fit` and `position` properties will be set to `contain`\n * and `top left` respectively.\n *\n * @param resizeConfig - the resize config\n * @returns a sanitized resize config\n */\nconst sanitizeResizeConfig = (resizeConfig: ImageSize): ImageSize => {\n if (resizeConfig.withoutReduction) {\n return {\n ...resizeConfig,\n // Why fit `contain` should also be set to https://github.com/lovell/sharp/issues/3595\n fit: resizeConfig?.fit || 'contain',\n position: resizeConfig?.position || 'left top',\n }\n }\n return resizeConfig\n}\n\n/**\n * For the provided image sizes, handle the resizing and the transforms\n * (format, trim, etc.) of each requested image size and return the result object.\n * This only handles the image sizes. The transforms of the original image\n * are handled in {@link ./generateFileData.ts}.\n *\n * The image will be resized according to the provided\n * resize config. If no image sizes are requested, the resolved data will be empty.\n * For every image that dos not need to be resized, an result object with `null`\n * parameters will be returned.\n *\n * @param resizeConfig - the resize config\n * @returns the result of the resize operation(s)\n */\nexport async function resizeAndTransformImageSizes({\n config,\n dimensions,\n file,\n mimeType,\n req,\n savedFilename,\n sharp,\n staticPath,\n uploadEdits,\n}: ResizeArgs): Promise<ImageSizesResult> {\n const { focalPoint: focalPointEnabled = true, imageSizes } = config.upload\n\n // Focal point adjustments\n const incomingFocalPoint = uploadEdits.focalPoint\n ? {\n x: isNumber(uploadEdits.focalPoint.x) ? Math.round(uploadEdits.focalPoint.x) : 50,\n y: isNumber(uploadEdits.focalPoint.y) ? Math.round(uploadEdits.focalPoint.y) : 50,\n }\n : undefined\n\n const defaultResult: ImageSizesResult = {\n ...(focalPointEnabled && incomingFocalPoint && { focalPoint: incomingFocalPoint }),\n sizeData: {},\n sizesToSave: [],\n }\n\n if (!imageSizes || !sharp) {\n return defaultResult\n }\n\n const sharpBase = sharp(file.tempFilePath || file.data).rotate() // pass rotate() to auto-rotate based on EXIF data. https://github.com/payloadcms/payload/pull/3081\n\n const results: ImageSizesResult[] = await Promise.all(\n imageSizes.map(async (imageResizeConfig): Promise<ImageSizesResult> => {\n imageResizeConfig = sanitizeResizeConfig(imageResizeConfig)\n\n // This checks if a resize should happen. If not, the resized image will be\n // skipped COMPLETELY and thus will not be included in the resulting images.\n // All further format/trim options will thus be skipped as well.\n if (preventResize(imageResizeConfig, dimensions)) {\n return createResult({ name: imageResizeConfig.name })\n }\n\n const imageToResize = sharpBase.clone()\n let resized = imageToResize\n\n if (incomingFocalPoint && applyPayloadAdjustments(imageResizeConfig, dimensions)) {\n const { height: resizeHeight, width: resizeWidth } = imageResizeConfig\n const resizeAspectRatio = resizeWidth / resizeHeight\n const originalAspectRatio = dimensions.width / dimensions.height\n const prioritizeHeight = resizeAspectRatio < originalAspectRatio\n\n // Scale the image up or down to fit the resize dimensions\n const scaledImage = imageToResize.resize({\n height: prioritizeHeight ? resizeHeight : null,\n width: prioritizeHeight ? null : resizeWidth,\n })\n const { info: scaledImageInfo } = await scaledImage.toBuffer({ resolveWithObject: true })\n\n const safeResizeWidth = resizeWidth ?? scaledImageInfo.width\n const maxOffsetX = scaledImageInfo.width - safeResizeWidth\n const leftFocalEdge = Math.round(\n scaledImageInfo.width * (incomingFocalPoint.x / 100) - safeResizeWidth / 2,\n )\n const safeOffsetX = Math.min(Math.max(0, leftFocalEdge), maxOffsetX)\n\n const safeResizeHeight = resizeHeight ?? scaledImageInfo.height\n const maxOffsetY = scaledImageInfo.height - safeResizeHeight\n const topFocalEdge = Math.round(\n scaledImageInfo.height * (incomingFocalPoint.y / 100) - safeResizeHeight / 2,\n )\n const safeOffsetY = Math.min(Math.max(0, topFocalEdge), maxOffsetY)\n\n // extract the focal area from the scaled image\n resized = scaledImage.extract({\n height: safeResizeHeight,\n left: safeOffsetX,\n top: safeOffsetY,\n width: safeResizeWidth,\n })\n } else {\n resized = imageToResize.resize(imageResizeConfig)\n }\n\n if (imageResizeConfig.formatOptions) {\n resized = resized.toFormat(\n imageResizeConfig.formatOptions.format,\n imageResizeConfig.formatOptions.options,\n )\n }\n\n if (imageResizeConfig.trimOptions) {\n resized = resized.trim(imageResizeConfig.trimOptions)\n }\n\n const { data: bufferData, info: bufferInfo } = await resized.toBuffer({\n resolveWithObject: true,\n })\n\n const sanitizedImage = getSanitizedImageData(savedFilename)\n\n if (req.payloadUploadSizes) {\n req.payloadUploadSizes[imageResizeConfig.name] = bufferData\n }\n\n const mimeInfo = await fromBuffer(bufferData)\n\n const imageNameWithDimensions = createImageName(\n sanitizedImage.name,\n bufferInfo,\n mimeInfo?.ext || sanitizedImage.ext,\n )\n\n const imagePath = `${staticPath}/${imageNameWithDimensions}`\n\n if (await fileExists(imagePath)) {\n try {\n fs.unlinkSync(imagePath)\n } catch {\n // Ignore unlink errors\n }\n }\n\n const { height, size, width } = bufferInfo\n return createResult({\n name: imageResizeConfig.name,\n filename: imageNameWithDimensions,\n filesize: size,\n height,\n mimeType: mimeInfo?.mime || mimeType,\n sizesToSave: [{ buffer: bufferData, path: imagePath }],\n width,\n })\n }),\n )\n\n return results.reduce(\n (acc, result) => {\n Object.assign(acc.sizeData, result.sizeData)\n acc.sizesToSave.push(...result.sizesToSave)\n return acc\n },\n { ...defaultResult },\n )\n}\n"],"names":["fileType","fromBuffer","fs","sanitize","isNumber","fileExists","getSanitizedImageData","sourceImage","extension","split","pop","name","substring","lastIndexOf","ext","createImageName","outputImageName","height","width","createResult","filename","filesize","mimeType","sizesToSave","sizeData","preventResize","desiredHeight","desiredWidth","withoutEnlargement","withoutReduction","original","undefined","isWidthOrHeightNotDefined","hasInsufficientWidth","hasInsufficientHeight","applyPayloadAdjustments","fit","targetAspectRatio","originalAspectRatio","skipEnlargement","skipReduction","sanitizeResizeConfig","resizeConfig","position","resizeAndTransformImageSizes","config","dimensions","file","req","savedFilename","sharp","staticPath","uploadEdits","focalPoint","focalPointEnabled","imageSizes","upload","incomingFocalPoint","x","Math","round","y","defaultResult","sharpBase","tempFilePath","data","rotate","results","Promise","all","map","imageResizeConfig","imageToResize","clone","resized","resizeHeight","resizeWidth","resizeAspectRatio","prioritizeHeight","scaledImage","resize","info","scaledImageInfo","toBuffer","resolveWithObject","safeResizeWidth","maxOffsetX","leftFocalEdge","safeOffsetX","min","max","safeResizeHeight","maxOffsetY","topFocalEdge","safeOffsetY","extract","left","top","formatOptions","toFormat","format","options","trimOptions","trim","bufferData","bufferInfo","sanitizedImage","payloadUploadSizes","mimeInfo","imageNameWithDimensions","imagePath","unlinkSync","size","mime","buffer","path","reduce","acc","result","Object","assign","push"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,cAAc,YAAW;AAChC,MAAM,EAAEC,UAAU,EAAE,GAAGD;AAEvB,OAAOE,QAAQ,KAAI;AACnB,OAAOC,cAAc,oBAAmB;AAcxC,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,OAAOC,gBAAgB,kBAAiB;AA0BxC;;;;;CAKC,GACD,MAAMC,wBAAwB,CAACC;IAC7B,MAAMC,YAAYD,YAAYE,KAAK,CAAC,KAAKC,GAAG;IAC5C,MAAMC,OAAOR,SAASI,YAAYK,SAAS,CAAC,GAAGL,YAAYM,WAAW,CAAC,SAASN;IAChF,OAAO;QAAEI;QAAMG,KAAKN;IAAU;AAChC;AAEA;;;;;;;;;;;;CAYC,GACD,MAAMO,kBAAkB,CACtBC,iBACA,EAAEC,MAAM,EAAEC,KAAK,EAAc,EAC7BV,YACG,CAAC,EAAEQ,gBAAgB,CAAC,EAAEE,MAAM,CAAC,EAAED,OAAO,CAAC,EAAET,UAAU,CAAC;AAYzD;;;;;;;;;;;;;CAaC,GACD,MAAMW,eAAe,CAAC,EACpBR,IAAI,EACJS,WAAW,IAAI,EACfC,WAAW,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,EAAE,GAAGuF;QAChC,OAAOtF,aAAa;YAClBR,MAAM4D,kBAAkB5D,IAAI;YAC5BS,UAAUyF;YACVxF,UAAU2F;YACV/F;YACAK,UAAUsF,UAAUK,QAAQ3F;YAC5BC,aAAa;gBAAC;oBAAE2F,QAAQV;oBAAYW,MAAML;gBAAU;aAAE;YACtD5F;QACF;IACF;IAGF,OAAOiD,QAAQiD,MAAM,CACnB,CAACC,KAAKC;QACJC,OAAOC,MAAM,CAACH,IAAI7F,QAAQ,EAAE8F,OAAO9F,QAAQ;QAC3C6F,IAAI9F,WAAW,CAACkG,IAAI,IAAIH,OAAO/F,WAAW;QAC1C,OAAO8F;IACT,GACA;QAAE,GAAGvD,aAAa;IAAC;AAEvB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare function isImage(mimeType: string): boolean;
|
|
2
2
|
//# sourceMappingURL=isImage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isImage.d.ts","sourceRoot":"","sources":["../../src/uploads/isImage.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"isImage.d.ts","sourceRoot":"","sources":["../../src/uploads/isImage.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAMjD"}
|
package/dist/uploads/isImage.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/uploads/isImage.ts"],"sourcesContent":["export
|
|
1
|
+
{"version":3,"sources":["../../src/uploads/isImage.ts"],"sourcesContent":["export function isImage(mimeType: string): boolean {\n return (\n ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml', 'image/webp', 'image/avif'].indexOf(\n mimeType,\n ) > -1\n )\n}\n"],"names":["isImage","mimeType","indexOf"],"rangeMappings":";;;;;;;;;","mappings":"AAAA,OAAO,SAASA,QAAQC,QAAgB;IACtC,OACE;QAAC;QAAc;QAAa;QAAa;QAAiB;QAAc;KAAa,CAACC,OAAO,CAC3FD,YACE,CAAC;AAET"}
|
package/dist/uploads/types.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export type FileSizes = {
|
|
|
15
15
|
export type FileData = {
|
|
16
16
|
filename: string;
|
|
17
17
|
filesize: number;
|
|
18
|
+
focalX?: number;
|
|
19
|
+
focalY?: number;
|
|
18
20
|
height: number;
|
|
19
21
|
mimeType: string;
|
|
20
22
|
sizes: FileSizes;
|
|
@@ -110,4 +112,16 @@ export type FileToSave = {
|
|
|
110
112
|
buffer: Buffer;
|
|
111
113
|
path: string;
|
|
112
114
|
};
|
|
115
|
+
export type UploadEdits = {
|
|
116
|
+
crop?: {
|
|
117
|
+
height?: number;
|
|
118
|
+
width?: number;
|
|
119
|
+
x?: number;
|
|
120
|
+
y?: number;
|
|
121
|
+
};
|
|
122
|
+
focalPoint?: {
|
|
123
|
+
x?: number;
|
|
124
|
+
y?: number;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
113
127
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/uploads/types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAA;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAA;IACvB,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAA;IACvB,MAAM,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,QAAQ,EAAE,IAAI,GAAG,MAAM,CAAA;IACvB,KAAK,EAAE,IAAI,GAAG,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,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 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/uploads/types.ts"],"sourcesContent":["import type { ResizeOptions, Sharp } from 'sharp'\n\nimport type { TypeWithID } from '../collections/config/types.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\n\nexport type FileSize = {\n filename: null | string\n filesize: null | number\n height: null | number\n mimeType: null | string\n width: null | number\n}\n\nexport type FileSizes = {\n [size: string]: FileSize\n}\n\nexport type FileData = {\n filename: string\n filesize: number\n height: number\n mimeType: string\n sizes: FileSizes\n tempFilePath?: string\n url?: string\n width: number\n}\n\nexport type ProbedImageSize = {\n height: number\n width: number\n}\n\n/**\n * Params sent to the sharp toFormat() function\n * @link https://sharp.pixelplumbing.com/api-output#toformat\n */\nexport type ImageUploadFormatOptions = {\n format: Parameters<Sharp['toFormat']>[0]\n options?: Parameters<Sharp['toFormat']>[1]\n}\n\n/**\n * Params sent to the sharp trim() function\n * @link https://sharp.pixelplumbing.com/api-resize#trim\n */\nexport type ImageUploadTrimOptions = Parameters<Sharp['trim']>[0]\n\nexport type ImageSize = Omit<ResizeOptions, 'withoutEnlargement'> & {\n /**\n * @deprecated prefer position\n */\n crop?: string // comes from sharp package\n formatOptions?: ImageUploadFormatOptions\n name: string\n trimOptions?: ImageUploadTrimOptions\n /**\n * When an uploaded image is smaller than the defined image size, we have 3 options:\n *\n * `undefined | false | true`\n *\n * 1. `undefined` [default]: uploading images with smaller width AND height than the image size will return null\n * 2. `false`: always enlarge images to the image size\n * 3. `true`: if the image is smaller than the image size, return the original image\n */\n withoutEnlargement?: ResizeOptions['withoutEnlargement']\n}\n\nexport type GetAdminThumbnail = (args: { doc: Record<string, unknown> }) => false | null | string\n\nexport type UploadConfig = {\n /**\n * The adapter to use for uploads.\n */\n adapter?: string\n /**\n * Represents an admin thumbnail, which can be either a React component or a string.\n * - If a string, it should be one of the image size names.\n * - If a React component, register a function that generates the thumbnail URL using the `useAdminThumbnail` hook.\n **/\n adminThumbnail?: GetAdminThumbnail | string\n crop?: boolean\n disableLocalStorage?: boolean\n /**\n * Accepts existing headers and can filter/modify them.\n *\n * Useful for adding custom headers to fetch from external providers.\n */\n externalFileHeaderFilter?: (headers: Record<string, string>) => Record<string, string>\n filesRequiredOnCreate?: boolean\n focalPoint?: boolean\n /** Options for original upload file only. For sizes, set each formatOptions individually. */\n formatOptions?: ImageUploadFormatOptions\n handlers?: ((\n req: PayloadRequestWithData,\n args: { doc: TypeWithID; params: { collection: string; filename: string } },\n ) => Promise<Response> | Response)[]\n imageSizes?: ImageSize[]\n mimeTypes?: string[]\n resizeOptions?: ResizeOptions\n staticDir?: string\n trimOptions?: ImageUploadTrimOptions\n}\n\nexport type SanitizedUploadConfig = UploadConfig & {\n staticDir: UploadConfig['staticDir']\n}\n\nexport type File = {\n data: Buffer\n mimetype: string\n name: string\n size: number\n}\n\nexport type FileToSave = {\n buffer: Buffer\n path: string\n}\n"],"names":[],"rangeMappings":"","mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/uploads/types.ts"],"sourcesContent":["import type { ResizeOptions, Sharp } from 'sharp'\n\nimport type { TypeWithID } from '../collections/config/types.js'\nimport type { PayloadRequestWithData } from '../types/index.js'\n\nexport type FileSize = {\n filename: null | string\n filesize: null | number\n height: null | number\n mimeType: null | string\n width: null | number\n}\n\nexport type FileSizes = {\n [size: string]: FileSize\n}\n\nexport type FileData = {\n filename: string\n filesize: number\n focalX?: number\n focalY?: number\n height: number\n mimeType: string\n sizes: FileSizes\n tempFilePath?: string\n url?: string\n width: number\n}\n\nexport type ProbedImageSize = {\n height: number\n width: number\n}\n\n/**\n * Params sent to the sharp toFormat() function\n * @link https://sharp.pixelplumbing.com/api-output#toformat\n */\nexport type ImageUploadFormatOptions = {\n format: Parameters<Sharp['toFormat']>[0]\n options?: Parameters<Sharp['toFormat']>[1]\n}\n\n/**\n * Params sent to the sharp trim() function\n * @link https://sharp.pixelplumbing.com/api-resize#trim\n */\nexport type ImageUploadTrimOptions = Parameters<Sharp['trim']>[0]\n\nexport type ImageSize = Omit<ResizeOptions, 'withoutEnlargement'> & {\n /**\n * @deprecated prefer position\n */\n crop?: string // comes from sharp package\n formatOptions?: ImageUploadFormatOptions\n name: string\n trimOptions?: ImageUploadTrimOptions\n /**\n * When an uploaded image is smaller than the defined image size, we have 3 options:\n *\n * `undefined | false | true`\n *\n * 1. `undefined` [default]: uploading images with smaller width AND height than the image size will return null\n * 2. `false`: always enlarge images to the image size\n * 3. `true`: if the image is smaller than the image size, return the original image\n */\n withoutEnlargement?: ResizeOptions['withoutEnlargement']\n}\n\nexport type GetAdminThumbnail = (args: { doc: Record<string, unknown> }) => false | null | string\n\nexport type UploadConfig = {\n /**\n * The adapter to use for uploads.\n */\n adapter?: string\n /**\n * Represents an admin thumbnail, which can be either a React component or a string.\n * - If a string, it should be one of the image size names.\n * - If a React component, register a function that generates the thumbnail URL using the `useAdminThumbnail` hook.\n **/\n adminThumbnail?: GetAdminThumbnail | string\n crop?: boolean\n disableLocalStorage?: boolean\n /**\n * Accepts existing headers and can filter/modify them.\n *\n * Useful for adding custom headers to fetch from external providers.\n */\n externalFileHeaderFilter?: (headers: Record<string, string>) => Record<string, string>\n filesRequiredOnCreate?: boolean\n focalPoint?: boolean\n /** Options for original upload file only. For sizes, set each formatOptions individually. */\n formatOptions?: ImageUploadFormatOptions\n handlers?: ((\n req: PayloadRequestWithData,\n args: { doc: TypeWithID; params: { collection: string; filename: string } },\n ) => Promise<Response> | Response)[]\n imageSizes?: ImageSize[]\n mimeTypes?: string[]\n resizeOptions?: ResizeOptions\n staticDir?: string\n trimOptions?: ImageUploadTrimOptions\n}\n\nexport type SanitizedUploadConfig = UploadConfig & {\n staticDir: UploadConfig['staticDir']\n}\n\nexport type File = {\n data: Buffer\n mimetype: string\n name: string\n size: number\n}\n\nexport type FileToSave = {\n buffer: Buffer\n path: string\n}\n\nexport type UploadEdits = {\n crop?: {\n height?: number\n width?: number\n x?: number\n y?: number\n }\n focalPoint?: {\n x?: number\n y?: number\n }\n}\n"],"names":[],"rangeMappings":"","mappings":"AA0HA,WAWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.35",
|
|
4
4
|
"description": "Node, React, Headless CMS and Application Framework built on Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"admin panel",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"scmp": "2.1.0",
|
|
97
97
|
"ts-essentials": "7.0.3",
|
|
98
98
|
"uuid": "^9.0.1",
|
|
99
|
-
"@payloadcms/translations": "3.0.0-beta.
|
|
99
|
+
"@payloadcms/translations": "3.0.0-beta.35"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@monaco-editor/react": "4.5.1",
|