feed_icon.go 980 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package ui // import "miniflux.app/v2/internal/ui"
  4. import (
  5. "net/http"
  6. "time"
  7. "miniflux.app/v2/internal/http/request"
  8. "miniflux.app/v2/internal/http/response"
  9. "miniflux.app/v2/internal/http/response/html"
  10. )
  11. func (h *handler) showFeedIcon(w http.ResponseWriter, r *http.Request) {
  12. externalIconID := request.RouteStringParam(r, "externalIconID")
  13. icon, err := h.store.IconByExternalID(externalIconID)
  14. if err != nil {
  15. html.ServerError(w, r, err)
  16. return
  17. }
  18. if icon == nil {
  19. html.NotFound(w, r)
  20. return
  21. }
  22. response.New(w, r).WithCaching(icon.Hash, 72*time.Hour, func(b *response.Builder) {
  23. b.WithHeader("Content-Security-Policy", response.ContentSecurityPolicyForUntrustedContent)
  24. b.WithHeader("Content-Type", icon.MimeType)
  25. b.WithBody(icon.Content)
  26. if icon.MimeType != "image/svg+xml" {
  27. b.WithoutCompression()
  28. }
  29. b.Write()
  30. })
  31. }