diff --git a/Makefile b/Makefile index dfd66efc..fa0268f7 100644 --- a/Makefile +++ b/Makefile @@ -27,13 +27,16 @@ watch: check_go_env test: check_go_env go test ./... -v -# @(cd ./ui && npm test -- --watchAll=false) .PHONY: test testall: check_go_env test @(cd ./ui && npm test -- --watchAll=false) .PHONY: testall +update-snapshots: check_go_env + UPDATE_SNAPSHOTS=true ginkgo ./server/subsonic/... +.PHONY: update-snapshots + setup: @which go-bindata || (echo "Installing BinData" && GO111MODULE=off go get -u github.com/go-bindata/go-bindata/...) go mod download diff --git a/model/mediafolder.go b/model/mediafolder.go index 39a17836..3a3b28ab 100644 --- a/model/mediafolder.go +++ b/model/mediafolder.go @@ -1,6 +1,7 @@ package model type MediaFolder struct { + // TODO Change to int ID string Name string Path string diff --git a/server/subsonic/browsing.go b/server/subsonic/browsing.go index 6e4ec138..a1110d82 100644 --- a/server/subsonic/browsing.go +++ b/server/subsonic/browsing.go @@ -2,8 +2,8 @@ package subsonic import ( "context" - "fmt" "net/http" + "strconv" "time" "github.com/deluan/navidrome/conf" @@ -26,7 +26,9 @@ func (c *BrowsingController) GetMusicFolders(w http.ResponseWriter, r *http.Requ mediaFolderList, _ := c.browser.MediaFolders(r.Context()) folders := make([]responses.MusicFolder, len(mediaFolderList)) for i, f := range mediaFolderList { - folders[i].Id = f.ID + // TODO Change model.MediaFolder.ID to int + id, _ := strconv.ParseInt(f.ID, 10, 32) + folders[i].Id = int32(id) folders[i].Name = f.Name } response := NewResponse() @@ -43,7 +45,7 @@ func (c *BrowsingController) getArtistIndex(r *http.Request, musicFolderId strin res := &responses.Indexes{ IgnoredArticles: conf.Server.IgnoredArticles, - LastModified: fmt.Sprint(utils.ToMillis(lastModified)), + LastModified: utils.ToMillis(lastModified), } res.Index = make([]responses.Index, len(indexes)) @@ -230,7 +232,7 @@ func (c *BrowsingController) buildAlbum(ctx context.Context, d *engine.Directory dir.CoverArt = d.CoverArt dir.SongCount = d.SongCount dir.Duration = d.Duration - dir.PlayCount = d.PlayCount + dir.PlayCount = int64(d.PlayCount) dir.Year = d.Year dir.Genre = d.Genre if !d.Created.IsZero() { diff --git a/server/subsonic/helpers.go b/server/subsonic/helpers.go index 9639b1be..4b0489a0 100644 --- a/server/subsonic/helpers.go +++ b/server/subsonic/helpers.go @@ -126,7 +126,7 @@ func ToChild(ctx context.Context, entry engine.Entry) responses.Child { child.Starred = &entry.Starred } child.Path = entry.Path - child.PlayCount = entry.PlayCount + child.PlayCount = int64(entry.PlayCount) child.DiscNumber = entry.DiscNumber if !entry.Created.IsZero() { child.Created = &entry.Created diff --git a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match .JSON b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match .JSON index 93b3a275..800283f4 100644 --- a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match .JSON +++ b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes with data should match .JSON @@ -1 +1 @@ -{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa","starred":"2016-03-02T20:30:00Z"}]}],"lastModified":"1","ignoredArticles":"A"}} +{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","indexes":{"index":[{"name":"A","artist":[{"id":"111","name":"aaa","starred":"2016-03-02T20:30:00Z"}]}],"lastModified":1,"ignoredArticles":"A"}} diff --git a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match .JSON b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match .JSON index cb318f45..5e9ffa25 100644 --- a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match .JSON +++ b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses Indexes without data should match .JSON @@ -1 +1 @@ -{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","indexes":{"lastModified":"1","ignoredArticles":"A"}} +{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","indexes":{"lastModified":1,"ignoredArticles":"A"}} diff --git a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match .JSON b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match .JSON index 0b659d36..634549ea 100644 --- a/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match .JSON +++ b/server/subsonic/responses/.snapshots/responses-snapshotMatcher-Match-Responses MusicFolders with data should match .JSON @@ -1 +1 @@ -{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","musicFolders":{"musicFolder":[{"id":"111","name":"aaa"},{"id":"222","name":"bbb"}]}} +{"status":"ok","version":"1.8.0","type":"navidrome","serverVersion":"v0.0.0","musicFolders":{"musicFolder":[{"id":111,"name":"aaa"},{"id":222,"name":"bbb"}]}} diff --git a/server/subsonic/responses/responses.go b/server/subsonic/responses/responses.go index c7fcec65..c7118966 100644 --- a/server/subsonic/responses/responses.go +++ b/server/subsonic/responses/responses.go @@ -54,7 +54,7 @@ type License struct { } type MusicFolder struct { - Id string `xml:"id,attr" json:"id"` + Id int32 `xml:"id,attr" json:"id"` Name string `xml:"name,attr" json:"name"` } @@ -80,7 +80,7 @@ type Index struct { type Indexes struct { Index []Index `xml:"index" json:"index,omitempty"` - LastModified string `xml:"lastModified,attr" json:"lastModified"` + LastModified int64 `xml:"lastModified,attr" json:"lastModified"` IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"` } @@ -105,7 +105,7 @@ type Child struct { Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"` BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"` Path string `xml:"path,attr,omitempty" json:"path,omitempty"` - PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"` + PlayCount int64 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"` DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"` Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"` AlbumId string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"` @@ -167,7 +167,7 @@ type AlbumID3 struct { CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"` SongCount int `xml:"songCount,attr,omitempty" json:"songCount,omitempty"` Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"` - PlayCount int32 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"` + PlayCount int64 `xml:"playCount,attr,omitempty" json:"playcount,omitempty"` Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"` Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"` Year int `xml:"year,attr,omitempty" json:"year,omitempty"` diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.go index cb523921..d55d3901 100644 --- a/server/subsonic/responses/responses_test.go +++ b/server/subsonic/responses/responses_test.go @@ -60,8 +60,8 @@ var _ = Describe("Responses", func() { Context("with data", func() { BeforeEach(func() { folders := make([]MusicFolder, 2) - folders[0] = MusicFolder{Id: "111", Name: "aaa"} - folders[1] = MusicFolder{Id: "222", Name: "bbb"} + folders[0] = MusicFolder{Id: 111, Name: "aaa"} + folders[1] = MusicFolder{Id: 222, Name: "bbb"} response.MusicFolders.Folders = folders }) @@ -76,7 +76,7 @@ var _ = Describe("Responses", func() { Describe("Indexes", func() { BeforeEach(func() { - response.Indexes = &Indexes{LastModified: "1", IgnoredArticles: "A"} + response.Indexes = &Indexes{LastModified: 1, IgnoredArticles: "A"} }) Context("without data", func() {