mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
expand list of allowed sort fields
This commit is contained in:
parent
1990e384da
commit
d9340371e5
1 changed files with 20 additions and 4 deletions
|
@ -1,4 +1,22 @@
|
||||||
defmodule Philomena.ImageSorter do
|
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
|
def parse_sort(params) do
|
||||||
sd = parse_sd(params)
|
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(%{"sd" => sd}) when sd in ~W(asc desc), do: sd
|
||||||
defp parse_sd(_params), do: "desc"
|
defp parse_sd(_params), do: "desc"
|
||||||
|
|
||||||
defp parse_sf(%{"sf" => sf}, sd) when
|
defp parse_sf(%{"sf" => sf}, sd) when sf in @allowed_fields do
|
||||||
sf in ~W(created_at updated_at first_seen_at width height score comment_count tag_count wilson_score _score)
|
|
||||||
do
|
|
||||||
%{queries: [], sorts: [%{sf => sd}]}
|
%{queries: [], sorts: [%{sf => sd}]}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue