mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-01-27 13:03:12 -05:00
Reformat:Scalafmt
Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
parent
98c304ccd4
commit
e38c3b680a
@ -11,16 +11,22 @@ import scala.io.Source
|
|||||||
import org.limium.picoserve.Server.StringResponse
|
import org.limium.picoserve.Server.StringResponse
|
||||||
|
|
||||||
class Server(port: Int) {
|
class Server(port: Int) {
|
||||||
val server: picoserve.Server = picoserve.Server.builder()
|
val server: picoserve.Server = picoserve.Server
|
||||||
|
.builder()
|
||||||
.port(port)
|
.port(port)
|
||||||
.backlog(32)
|
.backlog(32)
|
||||||
.POST("/v1/captcha", (request) => {
|
.POST(
|
||||||
|
"/v1/captcha",
|
||||||
|
(request) => {
|
||||||
val json = parse(request.getBodyString())
|
val json = parse(request.getBodyString())
|
||||||
val param = json.extract[Parameters]
|
val param = json.extract[Parameters]
|
||||||
val id = Captcha.getChallenge(param)
|
val id = Captcha.getChallenge(param)
|
||||||
getResponse(id)
|
getResponse(id)
|
||||||
})
|
}
|
||||||
.GET("/v1/media", (request) => {
|
)
|
||||||
|
.GET(
|
||||||
|
"/v1/media",
|
||||||
|
(request) => {
|
||||||
val params = request.getQueryParams()
|
val params = request.getQueryParams()
|
||||||
val result = if (params.containsKey("id")) {
|
val result = if (params.containsKey("id")) {
|
||||||
val paramId = params.get("id").get(0)
|
val paramId = params.get("id").get(0)
|
||||||
@ -30,18 +36,25 @@ class Server(port: Int) {
|
|||||||
Left(Error(ErrorMessageEnum.INVALID_PARAM.toString + "=> id"))
|
Left(Error(ErrorMessageEnum.INVALID_PARAM.toString + "=> id"))
|
||||||
}
|
}
|
||||||
getResponse(result)
|
getResponse(result)
|
||||||
})
|
}
|
||||||
.POST("/v1/answer", (request) => {
|
)
|
||||||
|
.POST(
|
||||||
|
"/v1/answer",
|
||||||
|
(request) => {
|
||||||
val json = parse(request.getBodyString())
|
val json = parse(request.getBodyString())
|
||||||
val answer = json.extract[Answer]
|
val answer = json.extract[Answer]
|
||||||
val result = Captcha.checkAnswer(answer)
|
val result = Captcha.checkAnswer(answer)
|
||||||
getResponse(result)
|
getResponse(result)
|
||||||
})
|
}
|
||||||
.GET("/demo/index.html", (_) => {
|
)
|
||||||
|
.GET(
|
||||||
|
"/demo/index.html",
|
||||||
|
(_) => {
|
||||||
val resStream = getClass().getResourceAsStream("/index.html")
|
val resStream = getClass().getResourceAsStream("/index.html")
|
||||||
val str = Source.fromInputStream(resStream).mkString
|
val str = Source.fromInputStream(resStream).mkString
|
||||||
new StringResponse(200, str)
|
new StringResponse(200, str)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
private def getResponse(response: Either[Error, ByteConvert]): ByteResponse = {
|
private def getResponse(response: Either[Error, ByteConvert]): ByteResponse = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user