From 52370036e303c9df915990981fa097468deef510 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 18 Sep 2022 15:15:58 +0200 Subject: [PATCH 1/2] add config for the frontend --- config.properties | 15 +++++++++------ src/main/java/me/kavin/piped/ServerLauncher.java | 6 ++++++ .../java/me/kavin/piped/consts/Constants.java | 6 ++++++ .../java/me/kavin/piped/utils/ResponseHelper.java | 4 ++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/config.properties b/config.properties index d746de6..99d580f 100644 --- a/config.properties +++ b/config.properties @@ -25,15 +25,18 @@ DISABLE_TIMERS:false RYD_PROXY_URL:https://ryd-proxy.kavin.rocks # Disable the usage of RYD DISABLE_RYD:false -# Disable API server (node just runs timers if enabled) -DISABLE_SERVER:false -# Disable the inclusion of LBRY streams -DISABLE_LBRY:false -# How long should unauthenticated subscriptions last for -SUBSCRIPTIONS_EXPIRY:30 +# Disable API server (node just runs timers if enabled) +DISABLE_SERVER:false +# Disable the inclusion of LBRY streams +DISABLE_LBRY:false +# How long should unauthenticated subscriptions last for +SUBSCRIPTIONS_EXPIRY:30 # Hibernate properties hibernate.connection.url:jdbc:postgresql://postgres:5432/piped hibernate.connection.driver_class:org.postgresql.Driver hibernate.dialect:org.hibernate.dialect.PostgreSQLDialect hibernate.connection.username:piped hibernate.connection.password:changeme +# Frontend configuration +frontend.statusPageUrl:https://kavin.rocks +frontend.donationUrl:https://kavin.rocks \ No newline at end of file diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index c2200cf..d9a4b5c 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -52,6 +52,12 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { } catch (Exception e) { return getErrorResponse(e, request.getPath()); } + })).map(GET, "/config", AsyncServlet.ofBlocking(executor, request -> { + try { + return getJsonResponse(ResponseHelper.configResponse(), "no-store"); + } catch (Exception e) { + return getErrorResponse(e, request.getPath()); + } })) .map(GET, "/version", AsyncServlet.ofBlocking(executor, request -> getRawResponse(Constants.VERSION.getBytes(UTF_8), "text/plain", "no-store"))) .map(HttpMethod.OPTIONS, "/*", request -> HttpResponse.ofCode(200)) diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index 056d20f..58282ea 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -1,6 +1,8 @@ package me.kavin.piped.consts; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.kavin.piped.utils.PageMixin; import okhttp3.OkHttpClient; @@ -67,6 +69,8 @@ public class Constants { public static final Object2ObjectOpenHashMap hibernateProperties = new Object2ObjectOpenHashMap<>(); + public static final ObjectNode frontendProperties = mapper.createObjectNode(); + static { Properties prop = new Properties(); try { @@ -101,6 +105,8 @@ public class Constants { String key = String.valueOf(_key), value = String.valueOf(_value); if (key.startsWith("hibernate")) hibernateProperties.put(key, value); + else if (key.startsWith("frontend")) + frontendProperties.put(key.replace("frontend.", ""), value); }); // transform hibernate properties for legacy configurations diff --git a/src/main/java/me/kavin/piped/utils/ResponseHelper.java b/src/main/java/me/kavin/piped/utils/ResponseHelper.java index 5d5e12a..8b278d9 100644 --- a/src/main/java/me/kavin/piped/utils/ResponseHelper.java +++ b/src/main/java/me/kavin/piped/utils/ResponseHelper.java @@ -67,6 +67,10 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper public class ResponseHelper { + public static byte[] configResponse() throws Exception { + return mapper.writeValueAsBytes(Constants.frontendProperties); + } + public static byte[] streamsResponse(String videoId) throws Exception { final var futureStream = Multithreading.supplyAsync(() -> { From 51185f255895f881493c5e922b8a0389d6552c25 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Sun, 25 Sep 2022 22:33:29 +0100 Subject: [PATCH 2/2] Some small changes. --- config.properties | 4 ++-- src/main/java/me/kavin/piped/ServerLauncher.java | 2 +- src/main/java/me/kavin/piped/consts/Constants.java | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/config.properties b/config.properties index 99d580f..63e5a27 100644 --- a/config.properties +++ b/config.properties @@ -38,5 +38,5 @@ hibernate.dialect:org.hibernate.dialect.PostgreSQLDialect hibernate.connection.username:piped hibernate.connection.password:changeme # Frontend configuration -frontend.statusPageUrl:https://kavin.rocks -frontend.donationUrl:https://kavin.rocks \ No newline at end of file +#frontend.statusPageUrl:https://kavin.rocks +#frontend.donationUrl:https://kavin.rocks diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index d9a4b5c..29e2adf 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -54,7 +54,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { } })).map(GET, "/config", AsyncServlet.ofBlocking(executor, request -> { try { - return getJsonResponse(ResponseHelper.configResponse(), "no-store"); + return getJsonResponse(ResponseHelper.configResponse(), "public, max-age=86400"); } catch (Exception e) { return getErrorResponse(e, request.getPath()); } diff --git a/src/main/java/me/kavin/piped/consts/Constants.java b/src/main/java/me/kavin/piped/consts/Constants.java index 58282ea..bdf93dd 100644 --- a/src/main/java/me/kavin/piped/consts/Constants.java +++ b/src/main/java/me/kavin/piped/consts/Constants.java @@ -2,7 +2,6 @@ package me.kavin.piped.consts; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; - import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.kavin.piped.utils.PageMixin; import okhttp3.OkHttpClient; @@ -105,8 +104,8 @@ public class Constants { String key = String.valueOf(_key), value = String.valueOf(_value); if (key.startsWith("hibernate")) hibernateProperties.put(key, value); - else if (key.startsWith("frontend")) - frontendProperties.put(key.replace("frontend.", ""), value); + else if (key.startsWith("frontend.")) + frontendProperties.put(StringUtils.substringAfter(key, "frontend."), value); }); // transform hibernate properties for legacy configurations