navidrome/api/get_indexes.go

55 lines
1.4 KiB
Go

package api
import (
"fmt"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain"
"github.com/deluan/gosonic/engine"
"github.com/deluan/gosonic/utils"
"github.com/karlkfi/inject"
)
type GetIndexesController struct {
BaseAPIController
properties domain.PropertyRepository
browser engine.Browser
}
func (c *GetIndexesController) Prepare() {
inject.ExtractAssignable(utils.Graph, &c.browser)
inject.ExtractAssignable(utils.Graph, &c.properties)
}
// TODO: Shortcuts amd validate musicFolder parameter
func (c *GetIndexesController) Get() {
var err error
var ifModifiedSince int64
c.Ctx.Input.Bind(&ifModifiedSince, "ifModifiedSince")
indexes, lastModified, err := c.browser.Indexes(utils.ToTime(ifModifiedSince))
if err != nil {
beego.Error("Error retrieving Indexes:", err)
c.SendError(responses.ERROR_GENERIC, "Internal Error")
}
res := responses.Indexes{
IgnoredArticles: beego.AppConfig.String("ignoredArticles"),
LastModified: fmt.Sprint(utils.ToMillis(lastModified)),
}
res.Index = make([]responses.Index, len(indexes))
for i, idx := range indexes {
res.Index[i].Name = idx.Id
res.Index[i].Artists = make([]responses.Artist, len(idx.Artists))
for j, a := range idx.Artists {
res.Index[i].Artists[j].Id = a.ArtistId
res.Index[i].Artists[j].Name = a.Artist
}
}
response := c.NewEmpty()
response.Indexes = &res
c.SendResponse(response)
}