icon.go 801 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. "net/http"
  7. "miniflux.app/http/request"
  8. "miniflux.app/http/response/json"
  9. )
  10. // FeedIcon returns a feed icon.
  11. func (c *Controller) FeedIcon(w http.ResponseWriter, r *http.Request) {
  12. feedID := request.RouteInt64Param(r, "feedID")
  13. if !c.store.HasIcon(feedID) {
  14. json.NotFound(w, r)
  15. return
  16. }
  17. icon, err := c.store.IconByFeedID(request.UserID(r), feedID)
  18. if err != nil {
  19. json.ServerError(w, r, err)
  20. return
  21. }
  22. if icon == nil {
  23. json.NotFound(w, r)
  24. return
  25. }
  26. json.OK(w, r, &feedIcon{
  27. ID: icon.ID,
  28. MimeType: icon.MimeType,
  29. Data: icon.DataURL(),
  30. })
  31. }