mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-02-14 03:58:06 -05:00
Merge pull request #122 from rr83019/opt-config-param
Make config parameters optional
This commit is contained in:
commit
715758ad48
@ -11,6 +11,7 @@ import java.io.{FileNotFoundException, File, PrintWriter}
|
||||
import java.{util => ju}
|
||||
import lc.misc.HelperFunctions
|
||||
|
||||
|
||||
class Config(configFilePath: String) {
|
||||
|
||||
import Config.formats
|
||||
@ -41,16 +42,17 @@ class Config(configFilePath: String) {
|
||||
}
|
||||
|
||||
private val configJson = parse(configString)
|
||||
private val configFields: ConfigField = configJson.extract[ConfigField]
|
||||
|
||||
val port: Int = (configJson \ AttributesEnum.PORT.toString).extract[Int]
|
||||
val address: String = (configJson \ AttributesEnum.ADDRESS.toString).extract[String]
|
||||
val throttle: Int = (configJson \ AttributesEnum.THROTTLE.toString).extract[Int]
|
||||
val seed: Int = (configJson \ AttributesEnum.RANDOM_SEED.toString).extract[Int]
|
||||
val captchaExpiryTimeLimit: Int = (configJson \ AttributesEnum.CAPTCHA_EXPIRY_TIME_LIMIT.toString).extract[Int]
|
||||
val threadDelay: Int = (configJson \ AttributesEnum.THREAD_DELAY.toString).extract[Int]
|
||||
val playgroundEnabled: Boolean = (configJson \ AttributesEnum.PLAYGROUND_ENABLED.toString).extract[Boolean]
|
||||
val corsHeader: String = (configJson \ AttributesEnum.CORS_HEADER.toString).extract[String]
|
||||
val maxAttempts: Int = (configJson \ AttributesEnum.MAX_ATTEMPTS.toString).extract[Int]
|
||||
val port: Int = configFields.portInt.getOrElse(8888)
|
||||
val address: String = configFields.address.getOrElse("0.0.0.0")
|
||||
val throttle: Int = configFields.throttleInt.getOrElse(1000)
|
||||
val seed: Int = configFields.seedInt.getOrElse(375264328)
|
||||
val captchaExpiryTimeLimit: Int = configFields.captchaExpiryTimeLimitInt.getOrElse(5)
|
||||
val threadDelay: Int = configFields.threadDelayInt.getOrElse(2)
|
||||
val playgroundEnabled: Boolean = configFields.playgroundEnabledBool.getOrElse(true)
|
||||
val corsHeader: String = configFields.corsHeader.getOrElse("")
|
||||
val maxAttempts: Int = configFields.maxAttemptsInt.getOrElse(10)
|
||||
|
||||
private val captchaConfigJson = (configJson \ "captchas")
|
||||
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
||||
|
@ -18,3 +18,26 @@ case class CaptchaConfig(
|
||||
allowedInputType: List[String],
|
||||
config: String
|
||||
)
|
||||
case class ConfigField(
|
||||
port: Option[Integer],
|
||||
address: Option[String],
|
||||
throttle: Option[Integer],
|
||||
seed: Option[Integer],
|
||||
captchaExpiryTimeLimit: Option[Integer],
|
||||
threadDelay: Option[Integer],
|
||||
playgroundEnabled: Option[java.lang.Boolean],
|
||||
corsHeader: Option[String],
|
||||
maxAttempts: Option[Integer]
|
||||
){
|
||||
lazy val portInt: Option[Int] = mapInt(port)
|
||||
lazy val throttleInt: Option[Int] = mapInt(throttle)
|
||||
lazy val seedInt: Option[Int] = mapInt(seed)
|
||||
lazy val captchaExpiryTimeLimitInt: Option[Int] = mapInt(captchaExpiryTimeLimit)
|
||||
lazy val threadDelayInt: Option[Int] = mapInt(threadDelay)
|
||||
lazy val maxAttemptsInt: Option[Int] = mapInt(maxAttempts)
|
||||
lazy val playgroundEnabledBool: Option[Boolean] = playgroundEnabled.map(_ || true)
|
||||
|
||||
private def mapInt(x: Option[Integer]): Option[Int] = {
|
||||
x.map(_ + 0)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user