getRandomSongs.view (partially) implemented
This commit is contained in:
+20
-2
@@ -40,7 +40,7 @@ func (c *AlbumListController) GetAlbumList() {
|
||||
}
|
||||
|
||||
offset := c.ParamInt("offset", 0)
|
||||
size := utils.MinInt(c.ParamInt("size", 0), 500)
|
||||
size := utils.MinInt(c.ParamInt("size", 10), 500)
|
||||
|
||||
albums, err := method(offset, size)
|
||||
if err != nil {
|
||||
@@ -63,7 +63,7 @@ func (c *AlbumListController) GetAlbumList2() {
|
||||
}
|
||||
|
||||
offset := c.ParamInt("offset", 0)
|
||||
size := utils.MinInt(c.ParamInt("size", 0), 500)
|
||||
size := utils.MinInt(c.ParamInt("size", 10), 500)
|
||||
|
||||
albums, err := method(offset, size)
|
||||
if err != nil {
|
||||
@@ -125,3 +125,21 @@ func (c *AlbumListController) GetNowPlaying() {
|
||||
}
|
||||
c.SendResponse(response)
|
||||
}
|
||||
|
||||
func (c *AlbumListController) GetRandomSongs() {
|
||||
size := utils.MinInt(c.ParamInt("size", 10), 500)
|
||||
|
||||
songs, err := c.listGen.GetRandomSongs(size)
|
||||
if err != nil {
|
||||
beego.Error("Error retrieving random songs:", err)
|
||||
c.SendError(responses.ErrorGeneric, "Internal Error")
|
||||
}
|
||||
|
||||
response := c.NewEmpty()
|
||||
response.RandomSongs = &responses.Songs{}
|
||||
response.RandomSongs.Songs = make([]responses.Child, len(songs))
|
||||
for i, entry := range songs {
|
||||
response.RandomSongs.Songs[i] = c.ToChild(entry)
|
||||
}
|
||||
c.SendResponse(response)
|
||||
}
|
||||
|
||||
@@ -44,10 +44,10 @@ func (c *BaseAPIController) ParamStrings(param string) []string {
|
||||
}
|
||||
|
||||
func (c *BaseAPIController) ParamTime(param string, def time.Time) time.Time {
|
||||
var value int64
|
||||
if c.Input().Get(param) == "" {
|
||||
return def
|
||||
}
|
||||
var value int64
|
||||
c.Ctx.Input.Bind(&value, param)
|
||||
return utils.ToTime(value)
|
||||
}
|
||||
@@ -73,7 +73,10 @@ func (c *BaseAPIController) RequiredParamInt(param string, msg string) int {
|
||||
}
|
||||
|
||||
func (c *BaseAPIController) ParamInt(param string, def int) int {
|
||||
value := def
|
||||
if c.Input().Get(param) == "" {
|
||||
return def
|
||||
}
|
||||
var value int
|
||||
c.Ctx.Input.Bind(&value, param)
|
||||
return value
|
||||
}
|
||||
@@ -91,10 +94,10 @@ func (c *BaseAPIController) ParamInts(param string) []int {
|
||||
}
|
||||
|
||||
func (c *BaseAPIController) ParamBool(param string, def bool) bool {
|
||||
value := def
|
||||
if c.Input().Get(param) == "" {
|
||||
return def
|
||||
}
|
||||
var value bool
|
||||
c.Ctx.Input.Bind(&value, param)
|
||||
return value
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ type Subsonic struct {
|
||||
Starred2 *Starred `xml:"starred2,omitempty" json:"starred2,omitempty"`
|
||||
NowPlaying *NowPlaying `xml:"nowPlaying,omitempty" json:"nowPlaying,omitempty"`
|
||||
Song *Child `xml:"song,omitempty" json:"song,omitempty"`
|
||||
RandomSongs *Songs `xml:"randomSongs,omitempty" json:"randomSongs,omitempty"`
|
||||
|
||||
// ID3
|
||||
Artist *Indexes `xml:"artists,omitempty" json:"artists,omitempty"`
|
||||
@@ -114,6 +115,10 @@ type Child struct {
|
||||
*/
|
||||
}
|
||||
|
||||
type Songs struct {
|
||||
Songs []Child `xml:"song" json:"song,omitempty"`
|
||||
}
|
||||
|
||||
type Directory struct {
|
||||
Child []Child `xml:"child" json:"child,omitempty"`
|
||||
Id string `xml:"id,attr" json:"id"`
|
||||
|
||||
Reference in New Issue
Block a user