icon.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package api
  5. import (
  6. "errors"
  7. "github.com/miniflux/miniflux/server/api/payload"
  8. "github.com/miniflux/miniflux/server/core"
  9. )
  10. // FeedIcon returns a feed icon.
  11. func (c *Controller) FeedIcon(ctx *core.Context, request *core.Request, response *core.Response) {
  12. userID := ctx.UserID()
  13. feedID, err := request.IntegerParam("feedID")
  14. if err != nil {
  15. response.JSON().BadRequest(err)
  16. return
  17. }
  18. if !c.store.HasIcon(feedID) {
  19. response.JSON().NotFound(errors.New("This feed doesn't have any icon"))
  20. return
  21. }
  22. icon, err := c.store.IconByFeedID(userID, feedID)
  23. if err != nil {
  24. response.JSON().ServerError(errors.New("Unable to fetch feed icon"))
  25. return
  26. }
  27. if icon == nil {
  28. response.JSON().NotFound(errors.New("This feed doesn't have any icon"))
  29. return
  30. }
  31. response.JSON().Standard(&payload.FeedIcon{
  32. ID: icon.ID,
  33. MimeType: icon.MimeType,
  34. Data: icon.DataURL(),
  35. })
  36. }