2019-11-29 01:11:05 +01:00
|
|
|
defmodule PhilomenaWeb.Search.ReverseController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
2019-12-04 01:50:23 +01:00
|
|
|
alias PhilomenaWeb.ImageReverse
|
2020-08-16 07:35:42 +02:00
|
|
|
alias Philomena.SpoilerExecutor
|
2019-11-29 01:11:05 +01:00
|
|
|
|
2020-08-08 02:23:36 +02:00
|
|
|
plug PhilomenaWeb.ScraperCachePlug
|
2020-01-11 19:50:53 +01:00
|
|
|
plug PhilomenaWeb.ScraperPlug, params_key: "image", params_name: "image"
|
2019-11-29 01:11:05 +01:00
|
|
|
|
2020-01-11 19:50:53 +01:00
|
|
|
def index(conn, params) do
|
|
|
|
create(conn, params)
|
2019-11-29 01:11:05 +01:00
|
|
|
end
|
|
|
|
|
2020-01-11 19:50:53 +01:00
|
|
|
def create(conn, %{"image" => image_params}) when is_map(image_params) do
|
2019-12-04 01:50:23 +01:00
|
|
|
images = ImageReverse.images(image_params)
|
2020-08-16 07:35:42 +02:00
|
|
|
spoilers = SpoilerExecutor.execute_spoiler(conn.assigns.compiled_spoiler, images)
|
2019-11-29 01:11:05 +01:00
|
|
|
|
2020-08-16 07:35:42 +02:00
|
|
|
render(conn, "index.html", title: "Reverse Search", images: images, spoilers: spoilers)
|
2020-01-11 19:50:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, _params) do
|
|
|
|
render(conn, "index.html", title: "Reverse Search", images: nil)
|
|
|
|
end
|
2019-12-16 20:24:38 +01:00
|
|
|
end
|