diff --git a/src/main/scala/lc/core/captchaFields.scala b/src/main/scala/lc/core/captchaFields.scala index 42d977e..192ffa9 100644 --- a/src/main/scala/lc/core/captchaFields.scala +++ b/src/main/scala/lc/core/captchaFields.scala @@ -26,7 +26,7 @@ object AttributesEnum extends Enumeration { val PLAYGROUND_ENABLED: Value = Value("playgroundEnabled") val CORS_HEADER: Value = Value("corsHeader") val CONFIG: Value = Value("config") - val MAX_ATTEMPTS: Value = Value("maxAttempts") + val MAX_ATTEMPTS_RATIO: Value = Value("maxAttemptsRatio") } object ResultEnum extends Enumeration { diff --git a/src/main/scala/lc/core/config.scala b/src/main/scala/lc/core/config.scala index 970a5ec..d2349fa 100644 --- a/src/main/scala/lc/core/config.scala +++ b/src/main/scala/lc/core/config.scala @@ -51,7 +51,7 @@ class Config(configFilePath: String) { 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) + val maxAttempts: Int = Math.max(1, (configFields.maxAttemptsRatioFloat.getOrElse(0.01f) * bufferCount).toInt) private val captchaConfigJson = (configJson \ "captchas") val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) => @@ -74,7 +74,7 @@ class Config(configFilePath: String) { (AttributesEnum.THREAD_DELAY.toString -> 2) ~ (AttributesEnum.PLAYGROUND_ENABLED.toString -> true) ~ (AttributesEnum.CORS_HEADER.toString -> "") ~ - (AttributesEnum.MAX_ATTEMPTS.toString -> 10) ~ + (AttributesEnum.MAX_ATTEMPTS_RATIO.toString -> 0.01f) ~ ("captchas" -> List( ( (AttributesEnum.NAME.toString -> "FilterChallenge") ~ diff --git a/src/main/scala/lc/core/models.scala b/src/main/scala/lc/core/models.scala index 3a9ed3c..9dfb16c 100644 --- a/src/main/scala/lc/core/models.scala +++ b/src/main/scala/lc/core/models.scala @@ -28,17 +28,20 @@ case class ConfigField( threadDelay: Option[Integer], playgroundEnabled: Option[java.lang.Boolean], corsHeader: Option[String], - maxAttempts: Option[Integer] + maxAttemptsRatio: Option[java.lang.Float] ) { lazy val portInt: Option[Int] = mapInt(port) lazy val bufferCountInt: Option[Int] = mapInt(bufferCount) 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 maxAttemptsRatioFloat: Option[Float] = mapFloat(maxAttemptsRatio) lazy val playgroundEnabledBool: Option[Boolean] = playgroundEnabled.map(_ || true) private def mapInt(x: Option[Integer]): Option[Int] = { x.map(_ + 0) } + private def mapFloat(x: Option[java.lang.Float]): Option[Float] = { + x.map(_ + 0.0f) + } }