fix link preview

This commit is contained in:
Ryan ZHAO 2021-02-02 11:29:51 +11:00
parent c8149209a1
commit cca38e270b
2 changed files with 9 additions and 5 deletions

View File

@ -145,7 +145,7 @@ public class LinkPreviewRepository implements InjectableType {
imageUrl = Optional.absent();
}
if (imageUrl.isPresent() && !LinkPreviewUtil.isVaildMimeType(imageUrl.get())) {
if (imageUrl.isPresent() && !LinkPreviewUtil.isValidMimeType(imageUrl.get())) {
Log.i(TAG, "Image URL was invalid mime type. Skipping.");
imageUrl = Optional.absent();
}

View File

@ -98,11 +98,15 @@ public final class LinkPreviewUtil {
}
}
public static boolean isVaildMimeType(@NonNull String url) {
String[] vaildMimeType = {"jpg", "png", "gif", "jpeg"};
public static boolean isValidMimeType(@NonNull String url) {
String[] validMimeType = {".jpg", ".png", ".gif", ".jpeg"};
if (url.contains(".")) {
String extenstion = url.substring(url.lastIndexOf(".") + 1).toLowerCase();
return Arrays.asList(vaildMimeType).contains(extenstion);
for (String mimeType : validMimeType) {
if (url.contains(mimeType)) {
return true;
}
}
return false;
}
return true;
}