expand list of allowed sort fields

This commit is contained in:
byte[] 2019-12-24 20:17:27 -05:00
parent 1990e384da
commit d9340371e5

View file

@ -1,4 +1,22 @@
defmodule Philomena.ImageSorter do
@allowed_fields ~W(
created_at
updated_at
first_seen_at
aspect_ratio
faves
id
downvotes
upvotes
width
height
score
comment_count
tag_count
wilson_score
_score
)
def parse_sort(params) do
sd = parse_sd(params)
@ -8,9 +26,7 @@ defmodule Philomena.ImageSorter do
defp parse_sd(%{"sd" => sd}) when sd in ~W(asc desc), do: sd
defp parse_sd(_params), do: "desc"
defp parse_sf(%{"sf" => sf}, sd) when
sf in ~W(created_at updated_at first_seen_at width height score comment_count tag_count wilson_score _score)
do
defp parse_sf(%{"sf" => sf}, sd) when sf in @allowed_fields do
%{queries: [], sorts: [%{sf => sd}]}
end
@ -67,4 +83,4 @@ defmodule Philomena.ImageSorter do
sorts: [%{"_score" => sd}]
}
end
end
end