Fix `getMusicFolders` and `getIndexes` API compliance. Fix #286

This commit is contained in:
Deluan 2020-05-09 21:00:38 -04:00
parent 09267d2ffd
commit 1ed6d130b1
9 changed files with 22 additions and 16 deletions

View File

@ -27,13 +27,16 @@ watch: check_go_env
test: check_go_env test: check_go_env
go test ./... -v go test ./... -v
# @(cd ./ui && npm test -- --watchAll=false)
.PHONY: test .PHONY: test
testall: check_go_env test testall: check_go_env test
@(cd ./ui && npm test -- --watchAll=false) @(cd ./ui && npm test -- --watchAll=false)
.PHONY: testall .PHONY: testall
update-snapshots: check_go_env
UPDATE_SNAPSHOTS=true ginkgo ./server/subsonic/...
.PHONY: update-snapshots
setup: setup:
@which go-bindata || (echo "Installing BinData" && GO111MODULE=off go get -u github.com/go-bindata/go-bindata/...) @which go-bindata || (echo "Installing BinData" && GO111MODULE=off go get -u github.com/go-bindata/go-bindata/...)
go mod download go mod download

View File

@ -1,6 +1,7 @@
package model package model
type MediaFolder struct { type MediaFolder struct {
// TODO Change to int
ID string ID string
Name string Name string
Path string Path string

View File

@ -2,8 +2,8 @@ package subsonic
import ( import (
"context" "context"
"fmt"
"net/http" "net/http"
"strconv"
"time" "time"
"github.com/deluan/navidrome/conf" "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()) mediaFolderList, _ := c.browser.MediaFolders(r.Context())
folders := make([]responses.MusicFolder, len(mediaFolderList)) folders := make([]responses.MusicFolder, len(mediaFolderList))
for i, f := range 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 folders[i].Name = f.Name
} }
response := NewResponse() response := NewResponse()
@ -43,7 +45,7 @@ func (c *BrowsingController) getArtistIndex(r *http.Request, musicFolderId strin
res := &responses.Indexes{ res := &responses.Indexes{
IgnoredArticles: conf.Server.IgnoredArticles, IgnoredArticles: conf.Server.IgnoredArticles,
LastModified: fmt.Sprint(utils.ToMillis(lastModified)), LastModified: utils.ToMillis(lastModified),
} }
res.Index = make([]responses.Index, len(indexes)) 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.CoverArt = d.CoverArt
dir.SongCount = d.SongCount dir.SongCount = d.SongCount
dir.Duration = d.Duration dir.Duration = d.Duration
dir.PlayCount = d.PlayCount dir.PlayCount = int64(d.PlayCount)
dir.Year = d.Year dir.Year = d.Year
dir.Genre = d.Genre dir.Genre = d.Genre
if !d.Created.IsZero() { if !d.Created.IsZero() {

View File

@ -126,7 +126,7 @@ func ToChild(ctx context.Context, entry engine.Entry) responses.Child {
child.Starred = &entry.Starred child.Starred = &entry.Starred
} }
child.Path = entry.Path child.Path = entry.Path
child.PlayCount = entry.PlayCount child.PlayCount = int64(entry.PlayCount)
child.DiscNumber = entry.DiscNumber child.DiscNumber = entry.DiscNumber
if !entry.Created.IsZero() { if !entry.Created.IsZero() {
child.Created = &entry.Created child.Created = &entry.Created

View File

@ -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"}}

View File

@ -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"}}

View File

@ -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"}]}}

View File

@ -54,7 +54,7 @@ type License struct {
} }
type MusicFolder 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"` Name string `xml:"name,attr" json:"name"`
} }
@ -80,7 +80,7 @@ type Index struct {
type Indexes struct { type Indexes struct {
Index []Index `xml:"index" json:"index,omitempty"` 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"` IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"`
} }
@ -105,7 +105,7 @@ type Child struct {
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"` Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"` BitRate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
Path string `xml:"path,attr,omitempty" json:"path,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"` DiscNumber int `xml:"discNumber,attr,omitempty" json:"discNumber,omitempty"`
Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"` Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
AlbumId string `xml:"albumId,attr,omitempty" json:"albumId,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"` CoverArt string `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
SongCount int `xml:"songCount,attr,omitempty" json:"songCount,omitempty"` SongCount int `xml:"songCount,attr,omitempty" json:"songCount,omitempty"`
Duration int `xml:"duration,attr,omitempty" json:"duration,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"` Created *time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"` Starred *time.Time `xml:"starred,attr,omitempty" json:"starred,omitempty"`
Year int `xml:"year,attr,omitempty" json:"year,omitempty"` Year int `xml:"year,attr,omitempty" json:"year,omitempty"`

View File

@ -60,8 +60,8 @@ var _ = Describe("Responses", func() {
Context("with data", func() { Context("with data", func() {
BeforeEach(func() { BeforeEach(func() {
folders := make([]MusicFolder, 2) folders := make([]MusicFolder, 2)
folders[0] = MusicFolder{Id: "111", Name: "aaa"} folders[0] = MusicFolder{Id: 111, Name: "aaa"}
folders[1] = MusicFolder{Id: "222", Name: "bbb"} folders[1] = MusicFolder{Id: 222, Name: "bbb"}
response.MusicFolders.Folders = folders response.MusicFolders.Folders = folders
}) })
@ -76,7 +76,7 @@ var _ = Describe("Responses", func() {
Describe("Indexes", func() { Describe("Indexes", func() {
BeforeEach(func() { BeforeEach(func() {
response.Indexes = &Indexes{LastModified: "1", IgnoredArticles: "A"} response.Indexes = &Indexes{LastModified: 1, IgnoredArticles: "A"}
}) })
Context("without data", func() { Context("without data", func() {