add config for the frontend

This commit is contained in:
Bnyro 2022-09-18 15:15:58 +02:00
parent 83dc2e5833
commit 52370036e3
4 changed files with 25 additions and 6 deletions

View file

@ -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

View file

@ -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))

View file

@ -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<String, String> 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

View file

@ -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(() -> {