From cddb143cf7b300eed4f99623875c761cce87ae78 Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Thu, 7 Mar 2019 13:02:41 +0530 Subject: [PATCH 1/2] Added contentType:varchar field in db --- src/main/scala/lc/Main.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/scala/lc/Main.scala b/src/main/scala/lc/Main.scala index faafcbb..4755a52 100644 --- a/src/main/scala/lc/Main.scala +++ b/src/main/scala/lc/Main.scala @@ -18,8 +18,8 @@ import scala.Array class Captcha { val con: Connection = DriverManager.getConnection("jdbc:h2:./captcha", "sa", "") val stmt: Statement = con.createStatement() - stmt.execute("CREATE TABLE IF NOT EXISTS challenge(token varchar, id varchar, secret varchar, provider varchar, image blob)") - val insertPstmt: PreparedStatement = con.prepareStatement("INSERT INTO challenge(token, id, secret, provider, image) VALUES (?, ?, ?, ?, ?)") + stmt.execute("CREATE TABLE IF NOT EXISTS challenge(token varchar, id varchar, secret varchar, provider varchar, contentType varchar, image blob)") + val insertPstmt: PreparedStatement = con.prepareStatement("INSERT INTO challenge(token, id, secret, provider, contentType, image) VALUES (?, ?, ?, ?, ?, ?)") val selectPstmt: PreparedStatement = con.prepareStatement("SELECT secret, provider FROM challenge WHERE token = ?") val imagePstmt: PreparedStatement = con.prepareStatement("SELECT image FROM challenge WHERE token = ?") @@ -48,7 +48,8 @@ class Captcha { insertPstmt.setString(2, provider.getId) insertPstmt.setString(3, challenge.secret) insertPstmt.setString(4, providerMap) - insertPstmt.setBlob(5, blob) + insertPstmt.setString(5, challenge.contentType) + insertPstmt.setBlob(6, blob) insertPstmt.executeUpdate() id } @@ -65,7 +66,8 @@ class Captcha { insertPstmt.setString(2, provider.getId) insertPstmt.setString(3, challenge.secret) insertPstmt.setString(4, providerMap) - insertPstmt.setBlob(5, blob) + insertPstmt.setString(5, challenge.contentType) + insertPstmt.setBlob(6, blob) insertPstmt.executeUpdate() } } From c43ffd6dd31658fefc2749990f17b6d4a153386d Mon Sep 17 00:00:00 2001 From: Rahul Rudragoudar Date: Tue, 12 Mar 2019 18:17:34 +0530 Subject: [PATCH 2/2] Added GET request support for media end point --- src/main/scala/lc/FilterChallenge.scala | 2 +- src/main/scala/lc/Main.scala | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/scala/lc/FilterChallenge.scala b/src/main/scala/lc/FilterChallenge.scala index 6f8e5f0..690ceab 100644 --- a/src/main/scala/lc/FilterChallenge.scala +++ b/src/main/scala/lc/FilterChallenge.scala @@ -7,7 +7,7 @@ import java.awt.Font import java.awt.Color class FilterChallenge extends ChallengeProvider { - def getId = "filter" + def getId = "FilterChallenge" def returnChallenge(): Challenge = { val filterTypes = List(new FilterType1, new FilterType2) val r = new scala.util.Random diff --git a/src/main/scala/lc/Main.scala b/src/main/scala/lc/Main.scala index 4755a52..92a2897 100644 --- a/src/main/scala/lc/Main.scala +++ b/src/main/scala/lc/Main.scala @@ -126,14 +126,20 @@ class Server(port: Int){ },"POST") host.addContext("/v1/media",(req, resp) => { - val body = req.getJson() - val json = parse(body) - val id = json.extract[Id] + var id = Id(null) + if ("GET" == req.getMethod()){ + val params = req.getParams() + id = Id(params.get("id")) + } else { + val body = req.getJson() + val json = parse(body) + id = json.extract[Id] + } val image = captcha.getCaptcha(id) resp.getHeaders().add("Content-Type","image/png") resp.send(200, image) 0 - },"POST") + },"POST", "GET") host.addContext("/v1/answer",(req, resp) => { val body = req.getJson()