Files
payloadcms/test/uploads/getMimeType.ts
Patrik e148243260 fix(payload, ui): unable to save animated file types with undefined image sizes (#6757)
## Description

V2 PR [here](https://github.com/payloadcms/payload/pull/6733)

Additionally fixes issue with image thumbnails not updating properly
until page refresh.

Image thumbnails properly update on document save now.

- [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
2024-06-13 09:43:44 -04:00

36 lines
585 B
TypeScript

import path from 'path'
export const getMimeType = (
filePath: string,
): {
filename: string
type: string
} => {
const ext = path.extname(filePath).slice(1)
let type: string
switch (ext) {
case 'png':
type = 'image/png'
break
case 'jpg':
type = 'image/jpeg'
break
case 'jpeg':
type = 'image/jpeg'
break
case 'svg':
type = 'image/svg+xml'
break
case 'webp':
type = 'image/webp'
break
default:
type = 'image/png'
}
return {
filename: path.basename(filePath),
type,
}
}