2019-11-29 01:11:05 +01:00
|
|
|
defmodule PhilomenaWeb.Search.ReverseController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
2024-07-19 15:29:02 +02:00
|
|
|
alias Philomena.DuplicateReports.SearchQuery
|
|
|
|
alias Philomena.DuplicateReports
|
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
|
|
|
|
|
2021-10-24 22:18:50 +02:00
|
|
|
def create(conn, %{"image" => image_params})
|
|
|
|
when is_map(image_params) and image_params != %{} do
|
2024-07-19 15:29:02 +02:00
|
|
|
case DuplicateReports.execute_search_query(image_params) do
|
|
|
|
{:ok, images} ->
|
|
|
|
changeset = DuplicateReports.change_search_query(%SearchQuery{})
|
2024-08-26 05:50:33 +02:00
|
|
|
|
|
|
|
render(conn, "index.html",
|
|
|
|
title: "Reverse Search",
|
|
|
|
layout_class: "layout--wide",
|
|
|
|
images: images,
|
|
|
|
changeset: changeset
|
|
|
|
)
|
2019-11-29 01:11:05 +01:00
|
|
|
|
2024-07-19 15:29:02 +02:00
|
|
|
{:error, changeset} ->
|
2024-08-26 05:50:33 +02:00
|
|
|
render(conn, "index.html",
|
|
|
|
title: "Reverse Search",
|
|
|
|
layout_class: "layout--wide",
|
|
|
|
images: nil,
|
|
|
|
changeset: changeset
|
|
|
|
)
|
2024-07-19 15:29:02 +02:00
|
|
|
end
|
2020-01-11 19:50:53 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, _params) do
|
2024-07-19 15:29:02 +02:00
|
|
|
changeset = DuplicateReports.change_search_query(%SearchQuery{})
|
2024-08-26 05:50:33 +02:00
|
|
|
|
|
|
|
render(conn, "index.html",
|
|
|
|
title: "Reverse Search",
|
|
|
|
layout_class: "layout--wide",
|
|
|
|
images: nil,
|
|
|
|
changeset: changeset
|
|
|
|
)
|
2020-01-11 19:50:53 +01:00
|
|
|
end
|
2019-12-16 20:24:38 +01:00
|
|
|
end
|