Read properties from environment if available.

Closes https://github.com/TeamPiped/Piped/issues/638
This commit is contained in:
FireMaskterK 2021-11-23 00:21:18 +00:00
parent 6ec517e0ef
commit 749cf48f4b
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -55,16 +55,17 @@ public class Constants {
YOUTUBE_SERVICE = NewPipe.getService(0); YOUTUBE_SERVICE = NewPipe.getService(0);
prop.load(new FileReader("config.properties")); prop.load(new FileReader("config.properties"));
PORT = Integer.parseInt(prop.getProperty("PORT", "8080")); PORT = Integer.parseInt(getProperty(prop, "PORT", "8080"));
HTTP_WORKERS = prop.getProperty("HTTP_WORKERS", String.valueOf(Runtime.getRuntime().availableProcessors())); HTTP_WORKERS = getProperty(prop, "HTTP_WORKERS",
PROXY_PART = prop.getProperty("PROXY_PART"); String.valueOf(Runtime.getRuntime().availableProcessors()));
CAPTCHA_BASE_URL = prop.getProperty("CAPTCHA_BASE_URL"); PROXY_PART = getProperty(prop, "PROXY_PART");
CAPTCHA_API_KEY = prop.getProperty("CAPTCHA_API_KEY"); CAPTCHA_BASE_URL = getProperty(prop, "CAPTCHA_BASE_URL");
PUBLIC_URL = prop.getProperty("API_URL"); CAPTCHA_API_KEY = getProperty(prop, "CAPTCHA_API_KEY");
HTTP_PROXY = prop.getProperty("HTTP_PROXY"); PUBLIC_URL = getProperty(prop, "API_URL");
FRONTEND_URL = prop.getProperty("FRONTEND_URL", "https://pipedapi.kavin.rocks"); HTTP_PROXY = getProperty(prop, "HTTP_PROXY");
COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(prop.getProperty("COMPROMISED_PASSWORD_CHECK", "true")); FRONTEND_URL = getProperty(prop, "FRONTEND_URL", "https://pipedapi.kavin.rocks");
DISABLE_REGISTRATION = Boolean.parseBoolean(prop.getProperty("DISABLE_REGISTRATION", "false")); COMPROMISED_PASSWORD_CHECK = Boolean.parseBoolean(getProperty(prop, "COMPROMISED_PASSWORD_CHECK", "true"));
DISABLE_REGISTRATION = Boolean.parseBoolean(getProperty(prop, "DISABLE_REGISTRATION", "false"));
prop.forEach((_key, _value) -> { prop.forEach((_key, _value) -> {
String key = String.valueOf(_key), value = String.valueOf(_value); String key = String.valueOf(_key), value = String.valueOf(_value);
if (key.startsWith("hibernate")) if (key.startsWith("hibernate"))
@ -85,4 +86,18 @@ public class Constants {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private static final String getProperty(final Properties prop, String key) {
return getProperty(prop, key, null);
}
private static final String getProperty(final Properties prop, String key, String def) {
final String envVal = System.getenv(key);
if (envVal != null)
return envVal;
return prop.getProperty(key, def);
}
} }