fix: unable to save animated file types with undefined image sizes (#6733)

## Description

Fixes #6727 

- [x] I have read and understand the
[CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md)
document in this repository.

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)

## Checklist:

- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] Existing test suite passes locally with my changes
This commit is contained in:
Patrik
2024-06-13 09:41:24 -04:00
committed by GitHub
parent b7e852993b
commit e40570bd0d
9 changed files with 188 additions and 20 deletions

BIN
test/uploads/animated.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

View File

@@ -8,6 +8,7 @@ import { Uploads1 } from './collections/Upload1'
import Uploads2 from './collections/Upload2'
import AdminThumbnailCol from './collections/admin-thumbnail'
import {
animatedTypeMedia,
audioSlug,
cropOnlySlug,
enlargeSlug,
@@ -317,6 +318,43 @@ export default buildConfigWithDefaults({
],
},
},
{
slug: animatedTypeMedia,
fields: [],
upload: {
staticDir: './media',
staticURL: '/media',
resizeOptions: {
position: 'center',
width: 200,
height: 200,
},
imageSizes: [
{
name: 'squareSmall',
width: 480,
height: 480,
position: 'centre',
withoutEnlargement: false,
},
{
name: 'undefinedHeight',
width: 300,
height: undefined,
},
{
name: 'undefinedWidth',
width: undefined,
height: 300,
},
{
name: 'undefinedAll',
width: undefined,
height: undefined,
},
],
},
},
{
slug: enlargeSlug,
fields: [],
@@ -543,6 +581,43 @@ export default buildConfigWithDefaults({
},
})
// Create animated type images
const animatedImageFilePath = path.resolve(__dirname, './animated.webp')
const animatedImageFile = await getFileByPath(animatedImageFilePath)
await payload.create({
collection: animatedTypeMedia,
data: {},
file: animatedImageFile,
})
await payload.create({
collection: versionSlug,
data: {
_status: 'published',
title: 'upload',
},
file: animatedImageFile,
})
const nonAnimatedImageFilePath = path.resolve(__dirname, './non-animated.webp')
const nonAnimatedImageFile = await getFileByPath(nonAnimatedImageFilePath)
await payload.create({
collection: animatedTypeMedia,
data: {},
file: nonAnimatedImageFile,
})
await payload.create({
collection: versionSlug,
data: {
_status: 'published',
title: 'upload',
},
file: nonAnimatedImageFile,
})
// Create audio
const audioFilePath = path.resolve(__dirname, './audio.mp3')
const audioFile = await getFileByPath(audioFilePath)

View File

@@ -12,12 +12,20 @@ import { AdminUrlUtil } from '../helpers/adminUrlUtil'
import { initPayloadE2E } from '../helpers/configHelpers'
import { RESTClient } from '../helpers/rest'
import { adminThumbnailSrc } from './collections/admin-thumbnail'
import { adminThumbnailSlug, audioSlug, globalWithMedia, mediaSlug, relationSlug } from './shared'
import {
adminThumbnailSlug,
animatedTypeMedia,
audioSlug,
globalWithMedia,
mediaSlug,
relationSlug,
} from './shared'
const { beforeAll, describe } = test
let client: RESTClient
let mediaURL: AdminUrlUtil
let animatedTypeMediaURL: AdminUrlUtil
let audioURL: AdminUrlUtil
let relationURL: AdminUrlUtil
let adminThumbnailURL: AdminUrlUtil
@@ -34,6 +42,7 @@ describe('uploads', () => {
await client.login()
mediaURL = new AdminUrlUtil(serverURL, mediaSlug)
animatedTypeMediaURL = new AdminUrlUtil(serverURL, animatedTypeMedia)
audioURL = new AdminUrlUtil(serverURL, audioSlug)
relationURL = new AdminUrlUtil(serverURL, relationSlug)
adminThumbnailURL = new AdminUrlUtil(serverURL, adminThumbnailSlug)
@@ -96,6 +105,26 @@ describe('uploads', () => {
await saveDocAndAssert(page)
})
test('should create animated file upload', async () => {
await page.goto(animatedTypeMediaURL.create)
await page.setInputFiles('input[type="file"]', path.resolve(__dirname, './animated.webp'))
const animatedFilename = page.locator('.file-field__filename')
await expect(animatedFilename).toHaveValue('animated.webp')
await saveDocAndAssert(page)
await page.goto(animatedTypeMediaURL.create)
await page.setInputFiles('input[type="file"]', path.resolve(__dirname, './non-animated.webp'))
const nonAnimatedFileName = page.locator('.file-field__filename')
await expect(nonAnimatedFileName).toHaveValue('non-animated.webp')
await saveDocAndAssert(page)
})
test('should show resized images', async () => {
await page.goto(mediaURL.edit(pngDoc.id))
@@ -186,7 +215,7 @@ describe('uploads', () => {
// choose from existing
await page.locator('.list-drawer__toggler').click()
await expect(page.locator('.cell-title')).toContainText('draft')
await expect(page.locator('.row-3 .cell-title')).toContainText('draft')
})
test('should restrict mimetype based on filterOptions', async () => {

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@@ -172,6 +172,53 @@ export interface Media {
}
}
}
export interface AnimatedTypeMedia {
id: string
updatedAt: string
createdAt: string
url?: string
filename?: string
mimeType?: string
filesize?: number
width?: number
height?: number
focalX?: number
focalY?: number
sizes?: {
squareSmall?: {
url?: string
width?: number
height?: number
mimeType?: string
filesize?: number
filename?: string
}
undefinedHeight?: {
url?: string
width?: number
height?: number
mimeType?: string
filesize?: number
filename?: string
}
undefinedWidth?: {
url?: string
width?: number
height?: number
mimeType?: string
filesize?: number
filename?: string
}
undefinedAll?: {
url?: string
width?: number
height?: number
mimeType?: string
filesize?: number
filename?: string
}
}
}
export interface Audio {
id: string
audio?: string | Media

View File

@@ -8,3 +8,4 @@ export const reduceSlug = 'reduce'
export const relationSlug = 'relation'
export const versionSlug = 'versions'
export const globalWithMedia = 'global-with-media'
export const animatedTypeMedia = 'animated-type-media'