From 8c2e4da39646d0ce2ec75b2ff09999e52f8fcabb Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 31 Oct 2021 20:26:30 -0400 Subject: [PATCH] Fix `dateLoved` in criteria. Now log invalid field names in criteria --- model/criteria/criteria.go | 6 ++++++ model/criteria/fields.go | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/model/criteria/criteria.go b/model/criteria/criteria.go index 394c5590a..e9e64aa16 100644 --- a/model/criteria/criteria.go +++ b/model/criteria/criteria.go @@ -6,6 +6,8 @@ import ( "errors" "strings" + "github.com/navidrome/navidrome/log" + "github.com/Masterminds/squirrel" ) @@ -21,6 +23,10 @@ type Criteria struct { func (c Criteria) OrderBy() string { f := fieldMap[strings.ToLower(c.Sort)] + if f == "" { + log.Error("Invalid field in 'sort' field", "field", c.Sort) + f = c.Sort + } if c.Order != "" { f = f + " " + c.Order } diff --git a/model/criteria/fields.go b/model/criteria/fields.go index 949a2f09c..3722a9fae 100644 --- a/model/criteria/fields.go +++ b/model/criteria/fields.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" "time" + + "github.com/navidrome/navidrome/log" ) var fieldMap = map[string]string{ @@ -37,7 +39,7 @@ var fieldMap = map[string]string{ "channels": "media_file.channels", "genre": "genre.name", "loved": "annotation.starred", - "dateLoved": "annotation.starred_at", + "dateloved": "annotation.starred_at", "lastplayed": "annotation.play_date", "playcount": "annotation.play_count", "rating": "annotation.rating", @@ -48,6 +50,8 @@ func mapFields(expr map[string]interface{}) map[string]interface{} { for f, v := range expr { if dbf, found := fieldMap[strings.ToLower(f)]; found { m[dbf] = v + } else { + log.Error("Invalid field in criteria", "field", f) } } return m