icon.go 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/http/handler"
  8. )
  9. // FeedIcon returns a feed icon.
  10. func (c *Controller) FeedIcon(ctx *handler.Context, request *handler.Request, response *handler.Response) {
  11. userID := ctx.UserID()
  12. feedID, err := request.IntegerParam("feedID")
  13. if err != nil {
  14. response.JSON().BadRequest(err)
  15. return
  16. }
  17. if !c.store.HasIcon(feedID) {
  18. response.JSON().NotFound(errors.New("This feed doesn't have any icon"))
  19. return
  20. }
  21. icon, err := c.store.IconByFeedID(userID, feedID)
  22. if err != nil {
  23. response.JSON().ServerError(errors.New("Unable to fetch feed icon"))
  24. return
  25. }
  26. if icon == nil {
  27. response.JSON().NotFound(errors.New("This feed doesn't have any icon"))
  28. return
  29. }
  30. response.JSON().Standard(&feedIcon{
  31. ID: icon.ID,
  32. MimeType: icon.MimeType,
  33. Data: icon.DataURL(),
  34. })
  35. }