icon.go 896 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 := request.RouteInt64Param(r, "feedID")
  14. if !c.store.HasIcon(feedID) {
  15. json.NotFound(w, errors.New("This feed doesn't have any icon"))
  16. return
  17. }
  18. icon, err := c.store.IconByFeedID(request.UserID(r), feedID)
  19. if err != nil {
  20. json.ServerError(w, err)
  21. return
  22. }
  23. if icon == nil {
  24. json.NotFound(w, errors.New("This feed doesn't have any icon"))
  25. return
  26. }
  27. json.OK(w, r, &feedIcon{
  28. ID: icon.ID,
  29. MimeType: icon.MimeType,
  30. Data: icon.DataURL(),
  31. })
  32. }