From d9340371e59abef23b19593d2ff1c6c563d57703 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Tue, 24 Dec 2019 20:17:27 -0500 Subject: [PATCH] expand list of allowed sort fields --- lib/philomena/image_sorter.ex | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/philomena/image_sorter.ex b/lib/philomena/image_sorter.ex index f52adcae..2951611e 100644 --- a/lib/philomena/image_sorter.ex +++ b/lib/philomena/image_sorter.ex @@ -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 \ No newline at end of file +end