Skip to content

Commit d1794e3

Browse files
committed
chore: Hack of jpg file type
1 parent 50fd853 commit d1794e3

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/attr-accept.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import type { RcFile } from './interface';
22

3-
function endsWith(str: string, suffix: string) {
4-
return str.indexOf(suffix, str.length - suffix.length) !== -1;
5-
}
6-
73
export default (file: RcFile, acceptedFiles: string | string[]) => {
84
if (file && acceptedFiles) {
95
const acceptedFilesArray = Array.isArray(acceptedFiles)
@@ -20,7 +16,15 @@ export default (file: RcFile, acceptedFiles: string | string[]) => {
2016
return true;
2117
}
2218
if (validType.charAt(0) === '.') {
23-
return endsWith(fileName.toLowerCase(), validType.toLowerCase());
19+
const lowerFileName = fileName.toLowerCase();
20+
const lowerType = validType.toLowerCase();
21+
22+
let affixList = [lowerType];
23+
if (lowerType === '.jpg' || lowerType === '.jpeg') {
24+
affixList = ['.jpg', 'jpeg'];
25+
}
26+
27+
return affixList.some(affix => lowerFileName.endsWith(affix));
2428
}
2529
if (/\/\*$/.test(validType)) {
2630
// This is something like a image/* mime type

tests/uploader.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ describe('uploader', () => {
462462
);
463463

464464
test(
465-
'support .ext',
465+
'support .png',
466466
'.png',
467467
[
468468
{
@@ -475,6 +475,23 @@ describe('uploader', () => {
475475
1,
476476
);
477477

478+
test(
479+
'support .jpg and .jpeg',
480+
'.jpg',
481+
[
482+
{
483+
name: 'unaccepted.webp',
484+
},
485+
{
486+
name: 'accepted.jpg',
487+
},
488+
{
489+
name: 'accepted.jpeg',
490+
},
491+
],
492+
2,
493+
);
494+
478495
test(
479496
'support .ext,ext',
480497
'.png,.txt',

0 commit comments

Comments
 (0)