From 9ca28e05ecddc46208c26fba03527538541dc0e4 Mon Sep 17 00:00:00 2001 From: Nic Jackson Date: Fri, 12 Apr 2024 09:59:56 +0100 Subject: [PATCH] Use Curl as user-agent due to imgur issue --- gradle.properties | 2 +- .../projector/downloader/FileDownloader.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 96495f2..482425a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.14.22 # Mod Properties - mod_version = 1.4.0 + mod_version = 1.4.1 maven_group = com.github.hashicraft archives_base_name = projector diff --git a/src/main/java/com/github/hashicraft/projector/downloader/FileDownloader.java b/src/main/java/com/github/hashicraft/projector/downloader/FileDownloader.java index 679095d..236563f 100644 --- a/src/main/java/com/github/hashicraft/projector/downloader/FileDownloader.java +++ b/src/main/java/com/github/hashicraft/projector/downloader/FileDownloader.java @@ -11,6 +11,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.time.Duration; @@ -199,6 +200,7 @@ private void downloadFile(String location, int cacheSeconds) { // Are we dealing with a local file or URL? try { final URL url = new URL(location); + if (url.getProtocol().equals("http") || url.getProtocol().equals("https")) { isURL = true; } @@ -208,7 +210,13 @@ private void downloadFile(String location, int cacheSeconds) { // downloads to 10 concurrent threads Future future = downloadService.submit(() -> { try { - BufferedInputStream in = new BufferedInputStream(url.openStream()); + + final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestProperty("user-agent", + " curl/7.81.0"); + conn.setRequestProperty("accept", "*/*"); + + BufferedInputStream in = new BufferedInputStream(conn.getInputStream()); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmpFile)); byte dataBuffer[] = new byte[1024];