temporarily disable image with extension like '.ico' to make it the same iOS (just accept jpg, png and gif)

This commit is contained in:
Ryan ZHAO 2020-11-23 12:00:18 +11:00
parent 2a3c2fdb28
commit 14a5ff0546
2 changed files with 15 additions and 0 deletions

View File

@ -147,6 +147,11 @@ public class LinkPreviewRepository implements InjectableType {
imageUrl = Optional.absent();
}
if (imageUrl.isPresent() && !LinkPreviewUtil.isVaildMimeType(imageUrl.get())) {
Log.i(TAG, "Image URL was invalid mime type. Skipping.");
imageUrl = Optional.absent();
}
callback.onComplete(new Metadata(title, imageUrl));
}
});

View File

@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.Util;
import org.whispersystems.libsignal.util.guava.Optional;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@ -96,6 +97,15 @@ public final class LinkPreviewUtil {
}
}
public static boolean isVaildMimeType(@NonNull String url) {
String[] vaildMimeType = {"jpg", "png", "gif", "jpeg"};
if (url.contains(".")) {
String extenstion = url.substring(url.lastIndexOf(".") + 1).toLowerCase();
return Arrays.asList(vaildMimeType).contains(extenstion);
}
return true;
}
public static @NonNull OpenGraph parseOpenGraphFields(@Nullable String html) {
return parseOpenGraphFields(html, text -> Html.fromHtml(text).toString());
}