mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-26 04:23:14 -05:00
define maxAttemptsRatio instead of maxAttempts
This commit is contained in:
parent
a4df7a346d
commit
8df6039a7d
@ -26,7 +26,7 @@ object AttributesEnum extends Enumeration {
|
|||||||
val PLAYGROUND_ENABLED: Value = Value("playgroundEnabled")
|
val PLAYGROUND_ENABLED: Value = Value("playgroundEnabled")
|
||||||
val CORS_HEADER: Value = Value("corsHeader")
|
val CORS_HEADER: Value = Value("corsHeader")
|
||||||
val CONFIG: Value = Value("config")
|
val CONFIG: Value = Value("config")
|
||||||
val MAX_ATTEMPTS: Value = Value("maxAttempts")
|
val MAX_ATTEMPTS_RATIO: Value = Value("maxAttemptsRatio")
|
||||||
}
|
}
|
||||||
|
|
||||||
object ResultEnum extends Enumeration {
|
object ResultEnum extends Enumeration {
|
||||||
|
@ -51,7 +51,7 @@ class Config(configFilePath: String) {
|
|||||||
val threadDelay: Int = configFields.threadDelayInt.getOrElse(2)
|
val threadDelay: Int = configFields.threadDelayInt.getOrElse(2)
|
||||||
val playgroundEnabled: Boolean = configFields.playgroundEnabledBool.getOrElse(true)
|
val playgroundEnabled: Boolean = configFields.playgroundEnabledBool.getOrElse(true)
|
||||||
val corsHeader: String = configFields.corsHeader.getOrElse("")
|
val corsHeader: String = configFields.corsHeader.getOrElse("")
|
||||||
val maxAttempts: Int = configFields.maxAttemptsInt.getOrElse(10)
|
val maxAttempts: Int = Math.max(1, (configFields.maxAttemptsRatioFloat.getOrElse(0.01f) * bufferCount).toInt)
|
||||||
|
|
||||||
private val captchaConfigJson = (configJson \ "captchas")
|
private val captchaConfigJson = (configJson \ "captchas")
|
||||||
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
||||||
@ -74,7 +74,7 @@ class Config(configFilePath: String) {
|
|||||||
(AttributesEnum.THREAD_DELAY.toString -> 2) ~
|
(AttributesEnum.THREAD_DELAY.toString -> 2) ~
|
||||||
(AttributesEnum.PLAYGROUND_ENABLED.toString -> true) ~
|
(AttributesEnum.PLAYGROUND_ENABLED.toString -> true) ~
|
||||||
(AttributesEnum.CORS_HEADER.toString -> "") ~
|
(AttributesEnum.CORS_HEADER.toString -> "") ~
|
||||||
(AttributesEnum.MAX_ATTEMPTS.toString -> 10) ~
|
(AttributesEnum.MAX_ATTEMPTS_RATIO.toString -> 0.01f) ~
|
||||||
("captchas" -> List(
|
("captchas" -> List(
|
||||||
(
|
(
|
||||||
(AttributesEnum.NAME.toString -> "FilterChallenge") ~
|
(AttributesEnum.NAME.toString -> "FilterChallenge") ~
|
||||||
|
@ -28,17 +28,20 @@ case class ConfigField(
|
|||||||
threadDelay: Option[Integer],
|
threadDelay: Option[Integer],
|
||||||
playgroundEnabled: Option[java.lang.Boolean],
|
playgroundEnabled: Option[java.lang.Boolean],
|
||||||
corsHeader: Option[String],
|
corsHeader: Option[String],
|
||||||
maxAttempts: Option[Integer]
|
maxAttemptsRatio: Option[java.lang.Float]
|
||||||
) {
|
) {
|
||||||
lazy val portInt: Option[Int] = mapInt(port)
|
lazy val portInt: Option[Int] = mapInt(port)
|
||||||
lazy val bufferCountInt: Option[Int] = mapInt(bufferCount)
|
lazy val bufferCountInt: Option[Int] = mapInt(bufferCount)
|
||||||
lazy val seedInt: Option[Int] = mapInt(seed)
|
lazy val seedInt: Option[Int] = mapInt(seed)
|
||||||
lazy val captchaExpiryTimeLimitInt: Option[Int] = mapInt(captchaExpiryTimeLimit)
|
lazy val captchaExpiryTimeLimitInt: Option[Int] = mapInt(captchaExpiryTimeLimit)
|
||||||
lazy val threadDelayInt: Option[Int] = mapInt(threadDelay)
|
lazy val threadDelayInt: Option[Int] = mapInt(threadDelay)
|
||||||
lazy val maxAttemptsInt: Option[Int] = mapInt(maxAttempts)
|
lazy val maxAttemptsRatioFloat: Option[Float] = mapFloat(maxAttemptsRatio)
|
||||||
lazy val playgroundEnabledBool: Option[Boolean] = playgroundEnabled.map(_ || true)
|
lazy val playgroundEnabledBool: Option[Boolean] = playgroundEnabled.map(_ || true)
|
||||||
|
|
||||||
private def mapInt(x: Option[Integer]): Option[Int] = {
|
private def mapInt(x: Option[Integer]): Option[Int] = {
|
||||||
x.map(_ + 0)
|
x.map(_ + 0)
|
||||||
}
|
}
|
||||||
|
private def mapFloat(x: Option[java.lang.Float]): Option[Float] = {
|
||||||
|
x.map(_ + 0.0f)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user