From f18f87c7367a24624f6fbfcc697f058fbeb879b5 Mon Sep 17 00:00:00 2001 From: FireMasterK <20838718+FireMasterK@users.noreply.github.com> Date: Fri, 13 Nov 2020 03:10:50 +0530 Subject: [PATCH] Add support for an external proxy. --- config.properties | 3 +++ src/main/java/me/kavin/piped/consts/Constants.java | 3 +++ src/main/java/me/kavin/piped/utils/ResponseHelper.java | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/config.properties b/config.properties index 766df34..100e187 100644 --- a/config.properties +++ b/config.properties @@ -2,3 +2,6 @@ # The port to Listen on. PORT: 8080 +# Proxy +PROXY_PART: https://pipedproxy.kavin.rocks + diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index 7cd724b..7981bcf 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -19,6 +19,8 @@ public class Constants { public static final int PORT; + public static final String PROXY_PART; + public static final StreamingService YOUTUBE_SERVICE; public static final HttpClient h2client = HttpClient.newBuilder().followRedirects(Redirect.NORMAL) @@ -34,6 +36,7 @@ public class Constants { prop.load(new FileReader("config.properties")); PORT = Integer.parseInt(prop.getProperty("PORT")); + PROXY_PART = prop.getProperty("PROXY_PART"); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index dfef8ad..7dd0b42 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -173,7 +173,8 @@ public class ResponseHelper { if (!hasQuery && path.startsWith("/vi/")) path = path.replace("/vi/", "/vi_webp/").replace(".jpg", ".webp"); - return path + (hasQuery ? "?" + query + "&host=" : "?host=") + URLUtils.silentEncode(host); + return Constants.PROXY_PART + path + (hasQuery ? "?" + query + "&host=" : "?host=") + + URLUtils.silentEncode(host); } }