Checking ifModifiedSince param
This commit is contained in:
+31
-16
@@ -7,11 +7,12 @@ import (
|
||||
"github.com/karlkfi/inject"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/consts"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type GetIndexesController struct {
|
||||
beego.Controller
|
||||
repo repositories.ArtistIndex
|
||||
repo repositories.ArtistIndex
|
||||
properties repositories.Property
|
||||
}
|
||||
|
||||
@@ -21,28 +22,42 @@ func (c *GetIndexesController) Prepare() {
|
||||
}
|
||||
|
||||
func (c *GetIndexesController) Get() {
|
||||
indexes, err := c.repo.GetAll()
|
||||
if err != nil {
|
||||
beego.Error("Error retrieving Indexes:", err)
|
||||
c.CustomAbort(200, string(responses.NewError(responses.ERROR_GENERIC, "Internal Error")))
|
||||
}
|
||||
res := &responses.ArtistIndex{}
|
||||
var err error
|
||||
|
||||
res.LastModified, err = c.properties.Get(consts.LastScan)
|
||||
ifModifiedSince := c.Input().Get("ifModifiedSince")
|
||||
if ifModifiedSince == "" {
|
||||
ifModifiedSince = "0"
|
||||
}
|
||||
|
||||
res := &responses.ArtistIndex{}
|
||||
res.IgnoredArticles = beego.AppConfig.String("ignoredArticles")
|
||||
|
||||
res.LastModified, err = c.properties.DefaultGet(consts.LastScan, "-1")
|
||||
if err != nil {
|
||||
beego.Error("Error retrieving LastScan property:", err)
|
||||
c.CustomAbort(200, string(responses.NewError(responses.ERROR_GENERIC, "Internal Error")))
|
||||
}
|
||||
|
||||
res.IgnoredArticles = beego.AppConfig.String("ignoredArticles")
|
||||
res.Index = make([]responses.IdxIndex, len(indexes))
|
||||
for i, idx := range indexes {
|
||||
res.Index[i].Name = idx.Id
|
||||
res.Index[i].Artists = make([]responses.IdxArtist, 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
|
||||
i, _ := strconv.Atoi(ifModifiedSince)
|
||||
l, _ := strconv.Atoi(res.LastModified)
|
||||
|
||||
if (l > i) {
|
||||
indexes, err := c.repo.GetAll()
|
||||
if err != nil {
|
||||
beego.Error("Error retrieving Indexes:", err)
|
||||
c.CustomAbort(200, string(responses.NewError(responses.ERROR_GENERIC, "Internal Error")))
|
||||
}
|
||||
|
||||
res.Index = make([]responses.IdxIndex, len(indexes))
|
||||
for i, idx := range indexes {
|
||||
res.Index[i].Name = idx.Id
|
||||
res.Index[i].Artists = make([]responses.IdxArtist, 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
c.Ctx.Output.Body(responses.NewXML(res))
|
||||
|
||||
Reference in New Issue
Block a user