icon.go 949 B

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