Skip to content

Commit

Permalink
Fix Imgur links not previewing & extra extension being added
Browse files Browse the repository at this point in the history
  • Loading branch information
GamingGeek authored Feb 27, 2024
1 parent 3f740b4 commit ea516b9
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -82,7 +83,7 @@ private void handle(String value) {
return;
}

if (value.contains("imgur.com/")) {
if (value.contains("imgur.com/") && !value.contains("i.imgur")) {
final String[] split = value.split("/");
value = String.format("https://i.imgur.com/%s.png", split[split.length - 1]);
}
Expand Down Expand Up @@ -156,6 +157,10 @@ private void loadUrl(String url) {
connection.setUseCaches(true);
connection.setInstanceFollowRedirects(true);
connection.addRequestProperty("User-Agent", "Patcher Image Previewer");
if (url.contains("imgur")) {
// Prevents redirect to main website
connection.addRequestProperty("Referer", "https://imgur.com/");
}
connection.setReadTimeout(15000);
connection.setConnectTimeout(15000);
connection.setDoOutput(true);
Expand Down

0 comments on commit ea516b9

Please sign in to comment.