Merge pull request #374 from Bnyro/config

add config for the frontend
This commit is contained in:
Kavin 2022-10-02 14:53:51 +01:00 committed by GitHub
commit 202df96442
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 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(), "public, max-age=86400");
} 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,7 @@
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 +68,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 +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(StringUtils.substringAfter(key, "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(() -> {