mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-08 19:32:16 +03:00
New Directory response. Simplified other responses
This commit is contained in:
parent
de94fe3ef2
commit
68786d4b39
@ -7,9 +7,10 @@ type Subsonic struct {
|
|||||||
Status string `xml:"status,attr" json:"status"`
|
Status string `xml:"status,attr" json:"status"`
|
||||||
Version string `xml:"version,attr" json:"version"`
|
Version string `xml:"version,attr" json:"version"`
|
||||||
Error *Error `xml:",omitempty" json:"error,omitempty"`
|
Error *Error `xml:",omitempty" json:"error,omitempty"`
|
||||||
License *License `xml:",omitempty" json:"license,omitempty"`
|
License *License `xml:"license,omitempty" json:"license,omitempty"`
|
||||||
MusicFolders *MusicFolders `xml:",omitempty" json:"musicFolders,omitempty"`
|
MusicFolders *MusicFolders `xml:"musicFolders,omitempty" json:"musicFolders,omitempty"`
|
||||||
Indexes *Indexes `xml:",omitempty" json:"indexes,omitempty"`
|
Indexes *Indexes `xml:"indexes,omitempty" json:"indexes,omitempty"`
|
||||||
|
Directory *Directory `xml:"directory,omitempty" json:"directory,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JsonWrapper struct {
|
type JsonWrapper struct {
|
||||||
@ -17,42 +18,60 @@ type JsonWrapper struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
XMLName xml.Name `xml:"error" json:"-"`
|
|
||||||
Code int `xml:"code,attr"`
|
Code int `xml:"code,attr"`
|
||||||
Message string `xml:"message,attr"`
|
Message string `xml:"message,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type License struct {
|
type License struct {
|
||||||
XMLName xml.Name `xml:"license" json:"-"`
|
|
||||||
Valid bool `xml:"valid,attr" json:"valid"`
|
Valid bool `xml:"valid,attr" json:"valid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MusicFolder struct {
|
type MusicFolder struct {
|
||||||
XMLName xml.Name `xml:"musicFolder" json:"-"`
|
|
||||||
Id string `xml:"id,attr" json:"id"`
|
Id string `xml:"id,attr" json:"id"`
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MusicFolders struct {
|
type MusicFolders struct {
|
||||||
XMLName xml.Name `xml:"musicFolders" json:"-"`
|
Folders []MusicFolder `xml:"musicFolder" json:"musicFolder,omitempty"`
|
||||||
Folders []MusicFolder `xml:"musicFolders" json:"musicFolder,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Artist struct {
|
type Artist struct {
|
||||||
XMLName xml.Name `xml:"artist" json:"-"`
|
|
||||||
Id string `xml:"id,attr" json:"id"`
|
Id string `xml:"id,attr" json:"id"`
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Index struct {
|
type Index struct {
|
||||||
XMLName xml.Name `xml:"index" json:"-"`
|
|
||||||
Name string `xml:"name,attr" json:"name"`
|
Name string `xml:"name,attr" json:"name"`
|
||||||
Artists []Artist `xml:"index" json:"artist"`
|
Artists []Artist `xml:"artist" json:"artist"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Indexes struct {
|
type Indexes struct {
|
||||||
XMLName xml.Name `xml:"indexes" json:"-"`
|
Index []Index `xml:"index" json:"index,omitempty"`
|
||||||
Index []Index `xml:"indexes" json:"index,omitempty"`
|
|
||||||
LastModified string `xml:"lastModified,attr" json:"lastModified"`
|
LastModified string `xml:"lastModified,attr" json:"lastModified"`
|
||||||
IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"`
|
IgnoredArticles string `xml:"ignoredArticles,attr" json:"ignoredArticles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Child struct {
|
||||||
|
Id string `xml:"id,attr" json:"id"`
|
||||||
|
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
||||||
|
Title string `xml:"title,attr" json:"title"`
|
||||||
|
Album string `xml:"album,attr" json:"album"`
|
||||||
|
Artist string `xml:"artist,attr" json:"artist"`
|
||||||
|
Track int `xml:"track,attr" json:"track"`
|
||||||
|
Year int `xml:"year,attr" json:"year"`
|
||||||
|
Genre string `xml:"genre,attr" json:"genre"`
|
||||||
|
CoverArt string `xml:"coverArt,attr" json:"coverArt"`
|
||||||
|
Size string `xml:"size,attr" json:"size"`
|
||||||
|
ContentType string `xml:"contentType,attr" json:"contentType"`
|
||||||
|
Suffix string `xml:"suffix,attr" json:"suffix"`
|
||||||
|
TranscodedContentType string `xml:"transcodedContentType,attr" json:"transcodedContentType"`
|
||||||
|
TranscodedSuffix string `xml:"transcodedSuffix,attr" json:"transcodedSuffix"`
|
||||||
|
Duration int `xml:"duration,attr" json:"duration"`
|
||||||
|
BitRate int `xml:"bitRate,attr" json:"bitRate"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Directory struct {
|
||||||
|
Child []Child `xml:"child" json:"child,omitempty"`
|
||||||
|
Id string `xml:"id,attr" json:"id"`
|
||||||
|
Name string `xml:"name,attr" json:"name"`
|
||||||
|
}
|
@ -10,7 +10,7 @@ func TestSubsonicResponses(t *testing.T) {
|
|||||||
|
|
||||||
response := &Subsonic{Status: "ok", Version: "1.0.0"}
|
response := &Subsonic{Status: "ok", Version: "1.0.0"}
|
||||||
|
|
||||||
Convey("Subject: Subsonic Responses", t, func(){
|
Convey("Subject: Subsonic Responses", t, func() {
|
||||||
Convey("EmptyResponse", func() {
|
Convey("EmptyResponse", func() {
|
||||||
Convey("XML", func() {
|
Convey("XML", func() {
|
||||||
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"></subsonic-response>`)
|
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"></subsonic-response>`)
|
||||||
@ -82,6 +82,34 @@ func TestSubsonicResponses(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Directory", func() {
|
||||||
|
response.Directory = &Directory{Id: "1", Name: "N"}
|
||||||
|
Convey("With data", func() {
|
||||||
|
child := make([]Child, 1)
|
||||||
|
child[0] = Child{
|
||||||
|
Id:"1", IsDir: true, Title: "title", Album: "album", Artist: "artist", Track: 1,
|
||||||
|
Year: 1985, Genre: "Rock", CoverArt: "1", Size: "8421341", ContentType: "audio/flac",
|
||||||
|
Suffix: "flac", TranscodedContentType: "audio/mpeg", TranscodedSuffix: "mp3",
|
||||||
|
Duration: 146, BitRate: 320,
|
||||||
|
}
|
||||||
|
response.Directory.Child = child
|
||||||
|
Convey("XML", func() {
|
||||||
|
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"><child id="1" isDir="true" title="title" album="album" artist="artist" track="1" year="1985" genre="Rock" coverArt="1" size="8421341" contentType="audio/flac" suffix="flac" transcodedContentType="audio/mpeg" transcodedSuffix="mp3" duration="146" bitRate="320"></child></directory></subsonic-response>`)
|
||||||
|
})
|
||||||
|
Convey("JSON", func() {
|
||||||
|
So(response, ShouldMatchJSON, `{"directory":{"child":[{"album":"album","artist":"artist","bitRate":320,"contentType":"audio/flac","coverArt":"1","duration":146,"genre":"Rock","id":"1","isDir":true,"size":"8421341","suffix":"flac","title":"title","track":1,"transcodedContentType":"audio/mpeg","transcodedSuffix":"mp3","year":1985}],"id":"1","name":"N"},"status":"ok","version":"1.0.0"}`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
Convey("Without data", func() {
|
||||||
|
Convey("XML", func() {
|
||||||
|
So(response, ShouldMatchXML, `<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.0.0"><directory id="1" name="N"></directory></subsonic-response>`)
|
||||||
|
})
|
||||||
|
Convey("JSON", func() {
|
||||||
|
So(response, ShouldMatchJSON, `{"directory":{"id":"1","name":"N"},"status":"ok","version":"1.0.0"}`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Reset(func() {
|
Reset(func() {
|
||||||
response = &Subsonic{Status: "ok", Version: "1.0.0"}
|
response = &Subsonic{Status: "ok", Version: "1.0.0"}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user