diff --git a/.scalafmt.conf b/.scalafmt.conf index 3d74380..f77a401 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,3 +1,3 @@ -version="3.4.3" +version="3.5.0" maxColumn = 120 runner.dialect = scala3 diff --git a/src/main/scala/lc/Main.scala b/src/main/scala/lc/Main.scala index 5bdd849..3d2ac9c 100644 --- a/src/main/scala/lc/Main.scala +++ b/src/main/scala/lc/Main.scala @@ -26,13 +26,12 @@ object LCFramework { corsHeader = config.corsHeader ) - Runtime.getRuntime.addShutdownHook( new Thread { - override def run(): Unit = { - println("Shutting down gracefully...") - backgroundTask.shutdown() - } + Runtime.getRuntime.addShutdownHook(new Thread { + override def run(): Unit = { + println("Shutting down gracefully...") + backgroundTask.shutdown() } - ) + }) server.start() } diff --git a/src/main/scala/lc/background/taskThread.scala b/src/main/scala/lc/background/taskThread.scala index 431c93e..7398e41 100644 --- a/src/main/scala/lc/background/taskThread.scala +++ b/src/main/scala/lc/background/taskThread.scala @@ -26,7 +26,7 @@ class BackgroundTask(config: Config, captchaManager: CaptchaManager) { val countExisting = captchaManager.getCount(param).getOrElse(0) val countRequired = requiredCountPerCombination - countExisting if (countRequired > 0) { - val countCreate = Math.min(1.0 + requiredCountPerCombination/10.0, countRequired).toInt + val countCreate = Math.min(1.0 + requiredCountPerCombination / 10.0, countRequired).toInt println(s"Creating $countCreate of $countRequired captchas for $param") for (i <- 0 until countCreate) { @@ -42,10 +42,10 @@ class BackgroundTask(config: Config, captchaManager: CaptchaManager) { } private def allParameterCombinations(): List[Parameters] = { - (config.captchaConfig).flatMap {captcha => - (captcha.allowedLevels).flatMap {level => - (captcha.allowedMedia).flatMap {media => - (captcha.allowedInputType).map {inputType => + (config.captchaConfig).flatMap { captcha => + (captcha.allowedLevels).flatMap { level => + (captcha.allowedMedia).flatMap { media => + (captcha.allowedInputType).map { inputType => Parameters(level, media, inputType, Some(Size(0, 0))) } } diff --git a/src/main/scala/lc/core/captchaManager.scala b/src/main/scala/lc/core/captchaManager.scala index 96620bf..4943485 100644 --- a/src/main/scala/lc/core/captchaManager.scala +++ b/src/main/scala/lc/core/captchaManager.scala @@ -37,10 +37,10 @@ class CaptchaManager(config: Config, captchaProviders: CaptchaProviders) { captchaProviders.getProvider(param).flatMap { provider => val providerId = provider.getId() val challenge = provider.returnChallenge() - val blob = new ByteArrayInputStream(challenge.content) + val blob = new ByteArrayInputStream(challenge.content) val token = insertCaptcha(provider, challenge, providerId, param, blob) - // println("Added new challenge: " + token.toString) - token.map(_.toInt) + // println("Added new challenge: " + token.toString) + token.map(_.toInt) } } diff --git a/src/main/scala/lc/database/DB.scala b/src/main/scala/lc/database/DB.scala index ee6532f..78111a4 100644 --- a/src/main/scala/lc/database/DB.scala +++ b/src/main/scala/lc/database/DB.scala @@ -3,7 +3,8 @@ package lc.database import java.sql.{Connection, DriverManager, Statement} class DBConn() { - val con: Connection = DriverManager.getConnection("jdbc:h2:./data/H2/captcha2;MAX_COMPACT_TIME=8000;DB_CLOSE_ON_EXIT=FALSE", "sa", "") + val con: Connection = + DriverManager.getConnection("jdbc:h2:./data/H2/captcha2;MAX_COMPACT_TIME=8000;DB_CLOSE_ON_EXIT=FALSE", "sa", "") def getStatement(): Statement = { con.createStatement() diff --git a/src/main/scala/lc/server/Server.scala b/src/main/scala/lc/server/Server.scala index da8f3cf..197a9cc 100644 --- a/src/main/scala/lc/server/Server.scala +++ b/src/main/scala/lc/server/Server.scala @@ -13,7 +13,13 @@ import java.net.InetSocketAddress import java.util import scala.jdk.CollectionConverters._ -class Server(address: String, port: Int, captchaManager: CaptchaManager, playgroundEnabled: Boolean, corsHeader: String) { +class Server( + address: String, + port: Int, + captchaManager: CaptchaManager, + playgroundEnabled: Boolean, + corsHeader: String +) { var headerMap: util.Map[String, util.List[String]] = _ if (corsHeader.nonEmpty) { headerMap = Map("Access-Control-Allow-Origin" -> List(corsHeader).asJava).asJava