Skip to content

Commit b573ba9

Browse files
authored
[improvement] Uploader: support more image types (youzan#4140)
1 parent 67fc817 commit b573ba9

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/uploader/test/utils.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ test('isImageFile', () => {
66
expect(isImageFile({ url: 'https://a.png' })).toBeTruthy();
77
expect(isImageFile({ url: 'https://a.svg' })).toBeTruthy();
88
expect(isImageFile({ url: 'https://a.gif' })).toBeTruthy();
9+
expect(isImageFile({ url: 'https://a.webp' })).toBeTruthy();
10+
expect(isImageFile({ url: 'https://a.jfif' })).toBeTruthy();
11+
expect(isImageFile({ url: 'https://a.bmp' })).toBeTruthy();
12+
expect(isImageFile({ url: 'https://a.dpg' })).toBeTruthy();
913
expect(isImageFile({ file: { type: 'image/jpg' } })).toBeTruthy();
1014
expect(isImageFile({ file: { type: 'application/pdf' } })).toBeFalsy();
1115
expect(isImageFile({ content: 'data:image/xxx' })).toBeTruthy();

src/uploader/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export type FileListItem = {
3333
isImage?: boolean;
3434
};
3535

36-
const IMAGE_EXT = ['jpeg', 'jpg', 'gif', 'png', 'svg'];
36+
const IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
3737

3838
export function isImageUrl(url: string): boolean {
39-
return IMAGE_EXT.some(ext => url.indexOf(`.${ext}`) !== -1);
39+
return IMAGE_REGEXP.test(url);
4040
}
4141

4242
export function isImageFile(item: FileListItem): boolean {

0 commit comments

Comments
 (0)