You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.4 KiB
51 lines
1.4 KiB
import warning from "rc-util/es/warning";
|
|
export default (function (file, acceptedFiles) {
|
|
if (file && acceptedFiles) {
|
|
var acceptedFilesArray = Array.isArray(acceptedFiles) ? acceptedFiles : acceptedFiles.split(',');
|
|
var fileName = file.name || '';
|
|
var mimeType = file.type || '';
|
|
var baseMimeType = mimeType.replace(/\/.*$/, '');
|
|
return acceptedFilesArray.some(function (type) {
|
|
var validType = type.trim(); // This is something like */*,* allow all files
|
|
|
|
if (/^\*(\/\*)?$/.test(type)) {
|
|
return true;
|
|
} // like .jpg, .png
|
|
|
|
|
|
if (validType.charAt(0) === '.') {
|
|
var lowerFileName = fileName.toLowerCase();
|
|
var lowerType = validType.toLowerCase();
|
|
var affixList = [lowerType];
|
|
|
|
if (lowerType === '.jpg' || lowerType === '.jpeg') {
|
|
affixList = ['.jpg', '.jpeg'];
|
|
}
|
|
|
|
return affixList.some(function (affix) {
|
|
return lowerFileName.endsWith(affix);
|
|
});
|
|
} // This is something like a image/* mime type
|
|
|
|
|
|
if (/\/\*$/.test(validType)) {
|
|
return baseMimeType === validType.replace(/\/.*$/, '');
|
|
} // Full match
|
|
|
|
|
|
if (mimeType === validType) {
|
|
return true;
|
|
} // Invalidate type should skip
|
|
|
|
|
|
if (/^\w+$/.test(validType)) {
|
|
warning(false, "Upload takes an invalidate 'accept' type '".concat(validType, "'.Skip for check."));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
}
|
|
|
|
return true;
|
|
}); |