From b573ba9f6a6e9ec4da23c8bdb5d083f0a346ea29 Mon Sep 17 00:00:00 2001 From: neverland Date: Sun, 18 Aug 2019 11:16:44 +0800 Subject: [PATCH] [improvement] Uploader: support more image types (#4140) --- src/uploader/test/utils.spec.js | 4 ++++ src/uploader/utils.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/uploader/test/utils.spec.js b/src/uploader/test/utils.spec.js index ba3e239e5..58435c82b 100644 --- a/src/uploader/test/utils.spec.js +++ b/src/uploader/test/utils.spec.js @@ -6,6 +6,10 @@ test('isImageFile', () => { expect(isImageFile({ url: 'https://a.png' })).toBeTruthy(); expect(isImageFile({ url: 'https://a.svg' })).toBeTruthy(); expect(isImageFile({ url: 'https://a.gif' })).toBeTruthy(); + expect(isImageFile({ url: 'https://a.webp' })).toBeTruthy(); + expect(isImageFile({ url: 'https://a.jfif' })).toBeTruthy(); + expect(isImageFile({ url: 'https://a.bmp' })).toBeTruthy(); + expect(isImageFile({ url: 'https://a.dpg' })).toBeTruthy(); expect(isImageFile({ file: { type: 'image/jpg' } })).toBeTruthy(); expect(isImageFile({ file: { type: 'application/pdf' } })).toBeFalsy(); expect(isImageFile({ content: 'data:image/xxx' })).toBeTruthy(); diff --git a/src/uploader/utils.ts b/src/uploader/utils.ts index 067598be5..d9cc007c3 100644 --- a/src/uploader/utils.ts +++ b/src/uploader/utils.ts @@ -33,10 +33,10 @@ export type FileListItem = { isImage?: boolean; }; -const IMAGE_EXT = ['jpeg', 'jpg', 'gif', 'png', 'svg']; +const IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i; export function isImageUrl(url: string): boolean { - return IMAGE_EXT.some(ext => url.indexOf(`.${ext}`) !== -1); + return IMAGE_REGEXP.test(url); } export function isImageFile(item: FileListItem): boolean {