Check extensions first in thumbnailSupported().

This commit is contained in:
esaunders 2018-08-15 17:45:23 -04:00
parent 90ef414a17
commit 5570aa7003

View File

@ -205,6 +205,18 @@ public class ImageUtils {
}
AbstractFile file = (AbstractFile) content;
/**
* Before taking on the potentially costly task of calculating the MIME
* type that can happen in isMediaThumbnailSupported() below, let's
* first see if the file extension is in the set of supported media file
* extensions.
*/
List<String> supportedExtensions = new ArrayList<>(SUPPORTED_IMAGE_EXTENSIONS);
supportedExtensions.addAll(VideoUtils.getSupportedVideoExtensions());
if (isSupportedMediaExtension(file, supportedExtensions)) {
return true;
}
return VideoUtils.isVideoThumbnailSupported(file)
|| isImageThumbnailSupported(file);
}
@ -258,9 +270,7 @@ public class ImageUtils {
return false;
}
String extension = file.getNameExtension();
if (StringUtils.isNotBlank(extension) && supportedExtension.contains(extension)) {
if (isSupportedMediaExtension(file, supportedExtension)) {
return true;
} else {
try {
@ -276,6 +286,21 @@ public class ImageUtils {
}
}
/**
* Does the given file have an extension in the given list of supported
* extensions.
*
* @param file
* @param supportedExtensions
*
* @return
*/
static boolean isSupportedMediaExtension(final AbstractFile file, final List<String> supportedExtensions) {
String extension = file.getNameExtension();
return (StringUtils.isNotBlank(extension) && supportedExtensions.contains(extension));
}
/**
* //TODO: AUT-2057 this FileTypeDetector needs to be recreated when the
* user adds new user defined file types.