icon.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. "net/http"
  8. "github.com/miniflux/miniflux/http/context"
  9. "github.com/miniflux/miniflux/http/request"
  10. "github.com/miniflux/miniflux/http/response/json"
  11. )
  12. // FeedIcon returns a feed icon.
  13. func (c *Controller) FeedIcon(w http.ResponseWriter, r *http.Request) {
  14. feedID, err := request.IntParam(r, "feedID")
  15. if err != nil {
  16. json.BadRequest(w, err)
  17. return
  18. }
  19. if !c.store.HasIcon(feedID) {
  20. json.NotFound(w, errors.New("This feed doesn't have any icon"))
  21. return
  22. }
  23. icon, err := c.store.IconByFeedID(context.New(r).UserID(), feedID)
  24. if err != nil {
  25. json.ServerError(w, errors.New("Unable to fetch feed icon"))
  26. return
  27. }
  28. if icon == nil {
  29. json.NotFound(w, errors.New("This feed doesn't have any icon"))
  30. return
  31. }
  32. json.OK(w, r, &feedIcon{
  33. ID: icon.ID,
  34. MimeType: icon.MimeType,
  35. Data: icon.DataURL(),
  36. })
  37. }