mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-11-29 21:33:26 -05:00
create equal number of captchas for each parameter combination in background task
Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
@@ -18,22 +18,33 @@ class BackgroundTask(config: Config, captchaManager: CaptchaManager) {
|
||||
val challengeGCPstmt = Statements.tlStmts.get.challengeGCPstmt
|
||||
challengeGCPstmt.executeUpdate()
|
||||
|
||||
val imageNumResult = Statements.tlStmts.get.getCountChallengeTable.executeQuery()
|
||||
val imageNum = if (imageNumResult.next()) {
|
||||
imageNumResult.getInt("total")
|
||||
} else {
|
||||
0
|
||||
}
|
||||
for (param <- allParameterCombinations()) {
|
||||
val imageNum = captchaManager.getCount(param).getOrElse(0)
|
||||
val countCreate = (config.throttle * 1.1).toInt - imageNum
|
||||
if (countCreate > 0) {
|
||||
println(s"Creating $countCreate captchas for $param")
|
||||
|
||||
val throttle = (config.throttle * 1.1).toInt - imageNum
|
||||
|
||||
for (i <- 0 until throttle) {
|
||||
captchaManager.generateChallenge(getRandomParam())
|
||||
for (i <- 0 until countCreate) {
|
||||
captchaManager.generateChallenge(param)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch { case exception: Exception => println(exception) }
|
||||
}
|
||||
}
|
||||
|
||||
private def allParameterCombinations(): List[Parameters] = {
|
||||
(config.captchaConfig).flatMap {captcha =>
|
||||
(captcha.allowedLevels).flatMap {level =>
|
||||
(captcha.allowedMedia).flatMap {media =>
|
||||
(captcha.allowedInputType).map {inputType =>
|
||||
Parameters(level, media, inputType, Some(Size(0, 0)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def getRandomParam(): Parameters = {
|
||||
val captcha = pickRandom(config.captchaConfig)
|
||||
val level = pickRandom(captcha.allowedLevels)
|
||||
|
||||
Reference in New Issue
Block a user