2016-03-03 18:08:44 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/astaxie/beego"
|
|
|
|
"github.com/deluan/gosonic/api/responses"
|
2016-03-09 05:05:54 +01:00
|
|
|
"github.com/deluan/gosonic/engine"
|
2016-03-03 19:17:52 +01:00
|
|
|
"github.com/deluan/gosonic/utils"
|
2016-03-03 18:08:44 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type GetCoverArtController struct {
|
|
|
|
BaseAPIController
|
2016-03-09 05:05:54 +01:00
|
|
|
cover engine.Cover
|
2016-03-03 18:08:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GetCoverArtController) Prepare() {
|
2016-03-11 21:16:17 +01:00
|
|
|
utils.ResolveDependencies(&c.cover)
|
2016-03-03 18:08:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *GetCoverArtController) Get() {
|
2016-03-07 20:13:01 +01:00
|
|
|
id := c.RequiredParamString("id", "id parameter required")
|
2016-03-11 06:37:07 +01:00
|
|
|
size := c.ParamInt("size", 0)
|
2016-03-03 18:08:44 +01:00
|
|
|
|
2016-03-09 05:31:48 +01:00
|
|
|
err := c.cover.Get(id, size, c.Ctx.ResponseWriter)
|
2016-03-03 18:08:44 +01:00
|
|
|
|
2016-03-09 05:05:54 +01:00
|
|
|
switch {
|
2016-03-10 17:25:15 +01:00
|
|
|
case err == engine.ErrDataNotFound:
|
2016-03-09 05:05:54 +01:00
|
|
|
beego.Error(err, "Id:", id)
|
|
|
|
c.SendError(responses.ERROR_DATA_NOT_FOUND, "Directory not found")
|
|
|
|
case err != nil:
|
|
|
|
beego.Error(err)
|
|
|
|
c.SendError(responses.ERROR_GENERIC, "Internal Error")
|
2016-03-03 18:08:44 +01:00
|
|
|
}
|
|
|
|
}
|