mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-20 06:37:59 +01:00
include intensity data in image api response
This commit is contained in:
parent
330e4ffb26
commit
dd5d553c0d
4 changed files with 10 additions and 6 deletions
|
@ -4,7 +4,7 @@ defmodule PhilomenaWeb.Api.Json.ImageController do
|
|||
alias PhilomenaWeb.ImageJson
|
||||
alias Philomena.Images.Image
|
||||
|
||||
plug :load_and_authorize_resource, model: Image, only: [:show], preload: [:tags, :user]
|
||||
plug :load_and_authorize_resource, model: Image, only: [:show], preload: [:tags, :user, :intensity]
|
||||
|
||||
def show(conn, _params) do
|
||||
json(conn, %{image: ImageJson.as_json(conn, conn.assigns.image)})
|
||||
|
|
|
@ -9,7 +9,7 @@ defmodule PhilomenaWeb.Api.Json.Search.ImageController do
|
|||
import Ecto.Query
|
||||
|
||||
def index(conn, params) do
|
||||
queryable = Image |> preload([:tags, :user])
|
||||
queryable = Image |> preload([:tags, :user, :intensity])
|
||||
user = conn.assigns.current_user
|
||||
sort = ImageSorter.parse_sort(params)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ defmodule PhilomenaWeb.ImageJson do
|
|||
uploader: if(!!image.user and !image.anonymous, do: image.user.name),
|
||||
uploader_id: if(!!image.user and !image.anonymous, do: image.user.id),
|
||||
wilson_score: Philomena.Images.ElasticsearchIndex.wilson_score(image),
|
||||
intensities: intensities(image),
|
||||
score: image.score,
|
||||
upvotes: image.upvotes_count,
|
||||
downvotes: image.downvotes_count,
|
||||
|
@ -35,4 +36,7 @@ defmodule PhilomenaWeb.ImageJson do
|
|||
processed: image.processed
|
||||
}
|
||||
end
|
||||
|
||||
defp intensities(%{intensity: %{nw: nw, ne: ne, sw: sw, se: se}}), do: %{nw: nw, ne: ne, sw: sw, se: se}
|
||||
defp intensities(_), do: nil
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ defmodule PhilomenaWeb.ImageReverse do
|
|||
dist = normalize_dist(image_params)
|
||||
|
||||
DuplicateReports.duplicates_of(intensities, aspect, dist, dist)
|
||||
|> preload([:tags, :user])
|
||||
|> preload([:tags, :user, :intensity])
|
||||
|> Repo.all()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue