icon.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package api // import "miniflux.app/v2/internal/api"
  4. import (
  5. "net/http"
  6. "miniflux.app/v2/internal/http/request"
  7. "miniflux.app/v2/internal/http/response/json"
  8. )
  9. func (h *handler) getIconByFeedID(w http.ResponseWriter, r *http.Request) {
  10. feedID := request.RouteInt64Param(r, "feedID")
  11. if !h.store.HasFeedIcon(feedID) {
  12. json.NotFound(w, r)
  13. return
  14. }
  15. icon, err := h.store.IconByFeedID(request.UserID(r), feedID)
  16. if err != nil {
  17. json.ServerError(w, r, err)
  18. return
  19. }
  20. if icon == nil {
  21. json.NotFound(w, r)
  22. return
  23. }
  24. json.OK(w, r, &feedIconResponse{
  25. ID: icon.ID,
  26. MimeType: icon.MimeType,
  27. Data: icon.DataURL(),
  28. })
  29. }
  30. func (h *handler) getIconByIconID(w http.ResponseWriter, r *http.Request) {
  31. iconID := request.RouteInt64Param(r, "iconID")
  32. icon, err := h.store.IconByID(iconID)
  33. if err != nil {
  34. json.ServerError(w, r, err)
  35. return
  36. }
  37. if icon == nil {
  38. json.NotFound(w, r)
  39. return
  40. }
  41. json.OK(w, r, &feedIconResponse{
  42. ID: icon.ID,
  43. MimeType: icon.MimeType,
  44. Data: icon.DataURL(),
  45. })
  46. }