Skip to content

Commit

Permalink
fix: Imgur links not being previewed and extra extension sometimes be…
Browse files Browse the repository at this point in the history
…ing added (#169)

* Fix Imgur links not previewing & extra extension being added

* Remove unused import

Added this when debugging the issue and i forgor to remove 💀
  • Loading branch information
GamingGeek authored Feb 27, 2024
1 parent 3f740b4 commit 0945eeb
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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 +156,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 0945eeb

Please sign in to comment.