From 03df207e638122446a9b24facfd0b893ddd9e0e8 Mon Sep 17 00:00:00 2001 From: brian-doherty <76168809+brian-doherty@users.noreply.github.com> Date: Tue, 13 Sep 2022 08:46:33 -0500 Subject: [PATCH] feat(subsonic): support dsub edgecase for queries by decade * Found a podcast that returns 403 without a UserAgent string so I added one. URL is https://feeds.buzzsprout.com/132359.rss * Fixed lint issues including needed error checking. * DSub swaps fromYear and toYear so swap them back in that case. TBD -- fix the same logic in ServeGetRandomSongs --- server/ctrlsubsonic/handlers_by_folder.go | 10 ++++++---- server/ctrlsubsonic/handlers_by_tags.go | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/server/ctrlsubsonic/handlers_by_folder.go b/server/ctrlsubsonic/handlers_by_folder.go index c8e4040d..cd522f50 100644 --- a/server/ctrlsubsonic/handlers_by_folder.go +++ b/server/ctrlsubsonic/handlers_by_folder.go @@ -115,10 +115,12 @@ func (c *Controller) ServeGetAlbumList(r *http.Request) *spec.Response { case "alphabeticalByName": q = q.Order("right_path") case "byYear": - q = q.Where( - "tag_year BETWEEN ? AND ?", - params.GetOrInt("fromYear", 1800), - params.GetOrInt("toYear", 2200)) + fromYear := params.GetOrInt("fromYear", 1800) + toYear := params.GetOrInt("toYear", 2200) + if fromYear > toYear { + toYear, fromYear = fromYear, toYear + } + q = q.Where("tag_year BETWEEN ? AND ?", fromYear, toYear) q = q.Order("tag_year") case "byGenre": genre, _ := params.Get("genre") diff --git a/server/ctrlsubsonic/handlers_by_tags.go b/server/ctrlsubsonic/handlers_by_tags.go index 7be3e4b6..1d312037 100644 --- a/server/ctrlsubsonic/handlers_by_tags.go +++ b/server/ctrlsubsonic/handlers_by_tags.go @@ -125,10 +125,12 @@ func (c *Controller) ServeGetAlbumListTwo(r *http.Request) *spec.Response { case "alphabeticalByName": q = q.Order("tag_title") case "byYear": - q = q.Where( - "tag_year BETWEEN ? AND ?", - params.GetOrInt("fromYear", 1800), - params.GetOrInt("toYear", 2200)) + fromYear := params.GetOrInt("fromYear", 1800) + toYear := params.GetOrInt("toYear", 2200) + if fromYear > toYear { + toYear, fromYear = fromYear, toYear + } + q = q.Where("tag_year BETWEEN ? AND ?", fromYear, toYear) q = q.Order("tag_year") case "byGenre": genre, _ := params.Get("genre")