Fix int types in OpenSubsonic responses.

Refer to https://support.symfonium.app/t/symfonium-sync-crashes-when-tpos-is-not-an-int/4204
This commit is contained in:
Deluan 2024-05-01 13:57:11 -04:00
parent 7ab7b5df5e
commit 2c06a4234e
4 changed files with 39 additions and 14 deletions

View file

@ -7,7 +7,6 @@ import (
"mime"
"net/http"
"sort"
"strconv"
"strings"
"github.com/navidrome/navidrome/consts"
@ -15,6 +14,7 @@ import (
"github.com/navidrome/navidrome/model/request"
"github.com/navidrome/navidrome/server/public"
"github.com/navidrome/navidrome/server/subsonic/responses"
"github.com/navidrome/navidrome/utils/number"
)
func newResponse() *responses.Subsonic {
@ -254,12 +254,12 @@ func toItemDate(date string) responses.ItemDate {
}
parts := strings.Split(date, "-")
if len(parts) > 2 {
itemDate.Day, _ = strconv.Atoi(parts[2])
itemDate.Day = number.ParseInt[int32](parts[2])
}
if len(parts) > 1 {
itemDate.Month, _ = strconv.Atoi(parts[1])
itemDate.Month = number.ParseInt[int32](parts[1])
}
itemDate.Year, _ = strconv.Atoi(parts[0])
itemDate.Year = number.ParseInt[int32](parts[0])
return itemDate
}
@ -278,7 +278,7 @@ func buildDiscSubtitles(_ context.Context, a model.Album) responses.DiscTitles {
}
discTitles := responses.DiscTitles{}
for num, title := range a.Discs {
discTitles = append(discTitles, responses.DiscTitle{Disc: num, Title: title})
discTitles = append(discTitles, responses.DiscTitle{Disc: int32(num), Title: title})
}
sort.Slice(discTitles, func(i, j int) bool {
return discTitles[i].Disc < discTitles[j].Disc