From 0945eebf7e72d1759d754e92e7cd183577b00386 Mon Sep 17 00:00:00 2001 From: Jake Ward Date: Tue, 27 Feb 2024 13:53:50 +0000 Subject: [PATCH] fix: Imgur links not being previewed and extra extension sometimes being added (#169) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix Imgur links not previewing & extra extension being added * Remove unused import Added this when debugging the issue and i forgor to remove 💀 --- .../sk1er/patcher/screen/render/overlay/ImagePreview.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/club/sk1er/patcher/screen/render/overlay/ImagePreview.java b/src/main/java/club/sk1er/patcher/screen/render/overlay/ImagePreview.java index 7063778e2..e048b351c 100644 --- a/src/main/java/club/sk1er/patcher/screen/render/overlay/ImagePreview.java +++ b/src/main/java/club/sk1er/patcher/screen/render/overlay/ImagePreview.java @@ -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]); } @@ -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);