icon.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. icon, err := h.store.IconByFeedID(request.UserID(r), feedID)
  12. if err != nil {
  13. json.ServerError(w, r, err)
  14. return
  15. }
  16. if icon == nil {
  17. json.NotFound(w, r)
  18. return
  19. }
  20. json.OK(w, r, &feedIconResponse{
  21. ID: icon.ID,
  22. MimeType: icon.MimeType,
  23. Data: icon.DataURL(),
  24. })
  25. }
  26. func (h *handler) getIconByIconID(w http.ResponseWriter, r *http.Request) {
  27. iconID := request.RouteInt64Param(r, "iconID")
  28. icon, err := h.store.IconByID(iconID)
  29. if err != nil {
  30. json.ServerError(w, r, err)
  31. return
  32. }
  33. if icon == nil {
  34. json.NotFound(w, r)
  35. return
  36. }
  37. json.OK(w, r, &feedIconResponse{
  38. ID: icon.ID,
  39. MimeType: icon.MimeType,
  40. Data: icon.DataURL(),
  41. })
  42. }