Merge pull request #108 from scala-steward/update/scalafmt-core-3.0.8

Update scalafmt-core to 3.0.8
This commit is contained in:
hrj 2021-12-16 07:17:22 +05:30 committed by GitHub
commit 6cb10f409b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 36 deletions

View File

@ -1,3 +1,3 @@
version="3.0.5" version="3.0.8"
maxColumn = 120 maxColumn = 120
runner.dialect = scala213source3 runner.dialect = scala213source3

View File

@ -6,7 +6,7 @@ import lc.background.BackgroundTask
object LCFramework { object LCFramework {
def main(args: scala.Array[String]): Unit = { def main(args: scala.Array[String]): Unit = {
val configFilePath = if (args.length > 0){ val configFilePath = if (args.length > 0) {
args(0) args(0)
} else { } else {
"data/config.json" "data/config.json"
@ -16,14 +16,20 @@ object LCFramework {
val captcha = new Captcha(config = config, captchaProviders = captchaProviders) val captcha = new Captcha(config = config, captchaProviders = captchaProviders)
val backgroundTask = new BackgroundTask(config = config, captcha = captcha) val backgroundTask = new BackgroundTask(config = config, captcha = captcha)
backgroundTask.beginThread(delay = config.threadDelay) backgroundTask.beginThread(delay = config.threadDelay)
val server = new Server(address = config.address, port = config.port, captcha = captcha, playgroundEnabled = config.playgroundEnabled, corsHeader = config.corsHeader) val server = new Server(
address = config.address,
port = config.port,
captcha = captcha,
playgroundEnabled = config.playgroundEnabled,
corsHeader = config.corsHeader
)
server.start() server.start()
} }
} }
object MakeSamples { object MakeSamples {
def main(args: scala.Array[String]): Unit = { def main(args: scala.Array[String]): Unit = {
val configFilePath = if (args.length > 0){ val configFilePath = if (args.length > 0) {
args(0) args(0)
} else { } else {
"data/config.json" "data/config.json"
@ -31,14 +37,13 @@ object MakeSamples {
val config = new Config(configFilePath) val config = new Config(configFilePath)
val captchaProviders = new CaptchaProviders(config = config) val captchaProviders = new CaptchaProviders(config = config)
val samples = captchaProviders.generateChallengeSamples() val samples = captchaProviders.generateChallengeSamples()
samples.foreach { samples.foreach { case (key, sample) =>
case (key, sample) => val extensionMap = Map("image/png" -> "png", "image/gif" -> "gif")
val extensionMap = Map("image/png" -> "png", "image/gif" -> "gif") println(key + ": " + sample)
println(key + ": " + sample)
val outStream = new java.io.FileOutputStream("samples/" + key + "." + extensionMap(sample.contentType)) val outStream = new java.io.FileOutputStream("samples/" + key + "." + extensionMap(sample.contentType))
outStream.write(sample.content) outStream.write(sample.content)
outStream.close outStream.close
} }
} }
} }

View File

@ -13,7 +13,9 @@ import lc.captchas.interfaces.Challenge
import lc.captchas.interfaces.ChallengeProvider import lc.captchas.interfaces.ChallengeProvider
import lc.misc.PngImageWriter import lc.misc.PngImageWriter
/** This captcha is only for debugging purposes. It creates very simple captchas that are deliberately easy to solve with OCR engines */ /** This captcha is only for debugging purposes. It creates very simple captchas that are deliberately easy to solve
* with OCR engines
*/
class DebugCaptcha extends ChallengeProvider { class DebugCaptcha extends ChallengeProvider {
def getId(): String = { def getId(): String = {
@ -26,9 +28,12 @@ class DebugCaptcha extends ChallengeProvider {
def supportedParameters(): Map[String, List[String]] = { def supportedParameters(): Map[String, List[String]] = {
Map.of( Map.of(
"supportedLevels", List.of("debug"), "supportedLevels",
"supportedMedia", List.of("image/png"), List.of("debug"),
"supportedInputType", List.of("text") "supportedMedia",
List.of("image/png"),
"supportedInputType",
List.of("text")
) )
} }

View File

@ -20,9 +20,12 @@ class FilterChallenge extends ChallengeProvider {
def supportedParameters(): JavaMap[String, JavaList[String]] = { def supportedParameters(): JavaMap[String, JavaList[String]] = {
JavaMap.of( JavaMap.of(
"supportedLevels",JavaList.of("medium", "hard"), "supportedLevels",
"supportedMedia", JavaList.of("image/png"), JavaList.of("medium", "hard"),
"supportedInputType", JavaList.of("text") "supportedMedia",
JavaList.of("image/png"),
"supportedInputType",
JavaList.of("text")
) )
} }

View File

@ -31,9 +31,12 @@ class LabelCaptcha extends ChallengeProvider {
def supportedParameters(): JavaMap[String, JavaList[String]] = { def supportedParameters(): JavaMap[String, JavaList[String]] = {
JavaMap.of( JavaMap.of(
"supportedLevels", JavaList.of("hard"), "supportedLevels",
"supportedMedia", JavaList.of("image/png"), JavaList.of("hard"),
"supportedInputType", JavaList.of("text") "supportedMedia",
JavaList.of("image/png"),
"supportedInputType",
JavaList.of("text")
) )
} }

View File

@ -38,9 +38,12 @@ class RainDropsCP extends ChallengeProvider {
def supportedParameters(): JavaMap[String, JavaList[String]] = { def supportedParameters(): JavaMap[String, JavaList[String]] = {
JavaMap.of( JavaMap.of(
"supportedLevels", JavaList.of("medium", "easy"), "supportedLevels",
"supportedMedia", JavaList.of("image/gif"), JavaList.of("medium", "easy"),
"supportedInputType", JavaList.of("text") "supportedMedia",
JavaList.of("image/gif"),
"supportedInputType",
JavaList.of("text")
) )
} }

View File

@ -9,18 +9,17 @@ import lc.misc.HelperFunctions
class CaptchaProviders(config: Config) { class CaptchaProviders(config: Config) {
private val providers = Map( private val providers = Map(
"FilterChallenge" -> new FilterChallenge, "FilterChallenge" -> new FilterChallenge,
//"FontFunCaptcha" -> new FontFunCaptcha, // "FontFunCaptcha" -> new FontFunCaptcha,
"PoppingCharactersCaptcha" -> new PoppingCharactersCaptcha, "PoppingCharactersCaptcha" -> new PoppingCharactersCaptcha,
"ShadowTextCaptcha" -> new ShadowTextCaptcha, "ShadowTextCaptcha" -> new ShadowTextCaptcha,
"RainDropsCaptcha" -> new RainDropsCP, "RainDropsCaptcha" -> new RainDropsCP,
"DebugCaptcha" -> new DebugCaptcha "DebugCaptcha" -> new DebugCaptcha
//"LabelCaptcha" -> new LabelCaptcha // "LabelCaptcha" -> new LabelCaptcha
) )
def generateChallengeSamples(): Map[String, Challenge] = { def generateChallengeSamples(): Map[String, Challenge] = {
providers.map { providers.map { case (key, provider) =>
case (key, provider) => (key, provider.returnChallenge())
(key, provider.returnChallenge())
} }
} }

View File

@ -21,7 +21,7 @@ class Config(configFilePath: String) {
} catch { } catch {
case _: FileNotFoundException => { case _: FileNotFoundException => {
val configFileContent = getDefaultConfig() val configFileContent = getDefaultConfig()
val file = if(new File(configFilePath).isDirectory){ val file = if (new File(configFilePath).isDirectory) {
new File(configFilePath.concat("/config.json")) new File(configFilePath.concat("/config.json"))
} else { } else {
new File(configFilePath) new File(configFilePath)
@ -49,8 +49,8 @@ class Config(configFilePath: String) {
val corsHeader: String = (configJson \ AttributesEnum.CORS_HEADER.toString).extract[String] val corsHeader: String = (configJson \ AttributesEnum.CORS_HEADER.toString).extract[String]
private val captchaConfigJson = (configJson \ "captchas") private val captchaConfigJson = (configJson \ "captchas")
val captchaConfigTransform: JValue = captchaConfigJson transformField { val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
case JField("config", JObject(config)) => ("config", JString(config.toString)) ("config", JString(config.toString))
} }
val captchaConfig: List[CaptchaConfig] = captchaConfigTransform.extract[List[CaptchaConfig]] val captchaConfig: List[CaptchaConfig] = captchaConfigTransform.extract[List[CaptchaConfig]]
val allowedLevels: Set[String] = captchaConfig.flatMap(_.allowedLevels).toSet val allowedLevels: Set[String] = captchaConfig.flatMap(_.allowedLevels).toSet
@ -105,6 +105,6 @@ class Config(configFilePath: String) {
} }
object Config{ object Config {
implicit val formats: DefaultFormats.type = DefaultFormats implicit val formats: DefaultFormats.type = DefaultFormats
} }

View File

@ -14,7 +14,7 @@ import scala.jdk.CollectionConverters._
class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Boolean, corsHeader: String) { class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Boolean, corsHeader: String) {
var headerMap: util.Map[String, util.List[String]] = _ var headerMap: util.Map[String, util.List[String]] = _
if( corsHeader.nonEmpty ) { if (corsHeader.nonEmpty) {
headerMap = Map("Access-Control-Allow-Origin" -> List(corsHeader).asJava).asJava headerMap = Map("Access-Control-Allow-Origin" -> List(corsHeader).asJava).asJava
} }
val serverBuilder: ServerBuilder = picoserve.Server val serverBuilder: ServerBuilder = picoserve.Server
@ -53,7 +53,7 @@ class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Bo
getResponse(result, headerMap) getResponse(result, headerMap)
} }
) )
if( playgroundEnabled ) { if (playgroundEnabled) {
serverBuilder.GET( serverBuilder.GET(
"/demo/index.html", "/demo/index.html",
(_) => { (_) => {
@ -66,7 +66,10 @@ class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Bo
val server: picoserve.Server = serverBuilder.build() val server: picoserve.Server = serverBuilder.build()
private def getResponse(response: Either[Error, ByteConvert], responseHeaders: util.Map[String, util.List[String]]): ByteResponse = { private def getResponse(
response: Either[Error, ByteConvert],
responseHeaders: util.Map[String, util.List[String]]
): ByteResponse = {
response match { response match {
case Right(value) => { case Right(value) => {
new ByteResponse(200, value.toBytes(), responseHeaders) new ByteResponse(200, value.toBytes(), responseHeaders)