mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-12 22:43:20 -05:00
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:
commit
6cb10f409b
@ -1,3 +1,3 @@
|
||||
version="3.0.5"
|
||||
version="3.0.8"
|
||||
maxColumn = 120
|
||||
runner.dialect = scala213source3
|
||||
|
@ -6,7 +6,7 @@ import lc.background.BackgroundTask
|
||||
|
||||
object LCFramework {
|
||||
def main(args: scala.Array[String]): Unit = {
|
||||
val configFilePath = if (args.length > 0){
|
||||
val configFilePath = if (args.length > 0) {
|
||||
args(0)
|
||||
} else {
|
||||
"data/config.json"
|
||||
@ -16,14 +16,20 @@ object LCFramework {
|
||||
val captcha = new Captcha(config = config, captchaProviders = captchaProviders)
|
||||
val backgroundTask = new BackgroundTask(config = config, captcha = captcha)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
object MakeSamples {
|
||||
def main(args: scala.Array[String]): Unit = {
|
||||
val configFilePath = if (args.length > 0){
|
||||
val configFilePath = if (args.length > 0) {
|
||||
args(0)
|
||||
} else {
|
||||
"data/config.json"
|
||||
@ -31,14 +37,13 @@ object MakeSamples {
|
||||
val config = new Config(configFilePath)
|
||||
val captchaProviders = new CaptchaProviders(config = config)
|
||||
val samples = captchaProviders.generateChallengeSamples()
|
||||
samples.foreach {
|
||||
case (key, sample) =>
|
||||
val extensionMap = Map("image/png" -> "png", "image/gif" -> "gif")
|
||||
println(key + ": " + sample)
|
||||
samples.foreach { case (key, sample) =>
|
||||
val extensionMap = Map("image/png" -> "png", "image/gif" -> "gif")
|
||||
println(key + ": " + sample)
|
||||
|
||||
val outStream = new java.io.FileOutputStream("samples/" + key + "." + extensionMap(sample.contentType))
|
||||
outStream.write(sample.content)
|
||||
outStream.close
|
||||
val outStream = new java.io.FileOutputStream("samples/" + key + "." + extensionMap(sample.contentType))
|
||||
outStream.write(sample.content)
|
||||
outStream.close
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,9 @@ import lc.captchas.interfaces.Challenge
|
||||
import lc.captchas.interfaces.ChallengeProvider
|
||||
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 {
|
||||
|
||||
def getId(): String = {
|
||||
@ -26,9 +28,12 @@ class DebugCaptcha extends ChallengeProvider {
|
||||
|
||||
def supportedParameters(): Map[String, List[String]] = {
|
||||
Map.of(
|
||||
"supportedLevels", List.of("debug"),
|
||||
"supportedMedia", List.of("image/png"),
|
||||
"supportedInputType", List.of("text")
|
||||
"supportedLevels",
|
||||
List.of("debug"),
|
||||
"supportedMedia",
|
||||
List.of("image/png"),
|
||||
"supportedInputType",
|
||||
List.of("text")
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,12 @@ class FilterChallenge extends ChallengeProvider {
|
||||
|
||||
def supportedParameters(): JavaMap[String, JavaList[String]] = {
|
||||
JavaMap.of(
|
||||
"supportedLevels",JavaList.of("medium", "hard"),
|
||||
"supportedMedia", JavaList.of("image/png"),
|
||||
"supportedInputType", JavaList.of("text")
|
||||
"supportedLevels",
|
||||
JavaList.of("medium", "hard"),
|
||||
"supportedMedia",
|
||||
JavaList.of("image/png"),
|
||||
"supportedInputType",
|
||||
JavaList.of("text")
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,12 @@ class LabelCaptcha extends ChallengeProvider {
|
||||
|
||||
def supportedParameters(): JavaMap[String, JavaList[String]] = {
|
||||
JavaMap.of(
|
||||
"supportedLevels", JavaList.of("hard"),
|
||||
"supportedMedia", JavaList.of("image/png"),
|
||||
"supportedInputType", JavaList.of("text")
|
||||
"supportedLevels",
|
||||
JavaList.of("hard"),
|
||||
"supportedMedia",
|
||||
JavaList.of("image/png"),
|
||||
"supportedInputType",
|
||||
JavaList.of("text")
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,12 @@ class RainDropsCP extends ChallengeProvider {
|
||||
|
||||
def supportedParameters(): JavaMap[String, JavaList[String]] = {
|
||||
JavaMap.of(
|
||||
"supportedLevels", JavaList.of("medium", "easy"),
|
||||
"supportedMedia", JavaList.of("image/gif"),
|
||||
"supportedInputType", JavaList.of("text")
|
||||
"supportedLevels",
|
||||
JavaList.of("medium", "easy"),
|
||||
"supportedMedia",
|
||||
JavaList.of("image/gif"),
|
||||
"supportedInputType",
|
||||
JavaList.of("text")
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -9,18 +9,17 @@ import lc.misc.HelperFunctions
|
||||
class CaptchaProviders(config: Config) {
|
||||
private val providers = Map(
|
||||
"FilterChallenge" -> new FilterChallenge,
|
||||
//"FontFunCaptcha" -> new FontFunCaptcha,
|
||||
// "FontFunCaptcha" -> new FontFunCaptcha,
|
||||
"PoppingCharactersCaptcha" -> new PoppingCharactersCaptcha,
|
||||
"ShadowTextCaptcha" -> new ShadowTextCaptcha,
|
||||
"RainDropsCaptcha" -> new RainDropsCP,
|
||||
"DebugCaptcha" -> new DebugCaptcha
|
||||
//"LabelCaptcha" -> new LabelCaptcha
|
||||
// "LabelCaptcha" -> new LabelCaptcha
|
||||
)
|
||||
|
||||
def generateChallengeSamples(): Map[String, Challenge] = {
|
||||
providers.map {
|
||||
case (key, provider) =>
|
||||
(key, provider.returnChallenge())
|
||||
providers.map { case (key, provider) =>
|
||||
(key, provider.returnChallenge())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ class Config(configFilePath: String) {
|
||||
} catch {
|
||||
case _: FileNotFoundException => {
|
||||
val configFileContent = getDefaultConfig()
|
||||
val file = if(new File(configFilePath).isDirectory){
|
||||
val file = if (new File(configFilePath).isDirectory) {
|
||||
new File(configFilePath.concat("/config.json"))
|
||||
} else {
|
||||
new File(configFilePath)
|
||||
@ -49,8 +49,8 @@ class Config(configFilePath: String) {
|
||||
val corsHeader: String = (configJson \ AttributesEnum.CORS_HEADER.toString).extract[String]
|
||||
|
||||
private val captchaConfigJson = (configJson \ "captchas")
|
||||
val captchaConfigTransform: JValue = captchaConfigJson transformField {
|
||||
case JField("config", JObject(config)) => ("config", JString(config.toString))
|
||||
val captchaConfigTransform: JValue = captchaConfigJson transformField { case JField("config", JObject(config)) =>
|
||||
("config", JString(config.toString))
|
||||
}
|
||||
val captchaConfig: List[CaptchaConfig] = captchaConfigTransform.extract[List[CaptchaConfig]]
|
||||
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
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import scala.jdk.CollectionConverters._
|
||||
|
||||
class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Boolean, corsHeader: 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
|
||||
}
|
||||
val serverBuilder: ServerBuilder = picoserve.Server
|
||||
@ -53,7 +53,7 @@ class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Bo
|
||||
getResponse(result, headerMap)
|
||||
}
|
||||
)
|
||||
if( playgroundEnabled ) {
|
||||
if (playgroundEnabled) {
|
||||
serverBuilder.GET(
|
||||
"/demo/index.html",
|
||||
(_) => {
|
||||
@ -66,7 +66,10 @@ class Server(address: String, port: Int, captcha: Captcha, playgroundEnabled: Bo
|
||||
|
||||
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 {
|
||||
case Right(value) => {
|
||||
new ByteResponse(200, value.toBytes(), responseHeaders)
|
||||
|
Loading…
Reference in New Issue
Block a user