feed_icon.go 963 B

123456789101112131415161718192021222324252627282930313233343536
  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. )
  10. func (h *handler) showFeedIcon(w http.ResponseWriter, r *http.Request) {
  11. externalIconID := request.RouteStringParam(r, "externalIconID")
  12. icon, err := h.store.IconByExternalID(externalIconID)
  13. if err != nil {
  14. response.HTMLServerError(w, r, err)
  15. return
  16. }
  17. if icon == nil {
  18. response.HTMLNotFound(w, r)
  19. return
  20. }
  21. response.NewBuilder(w, r).WithCaching(icon.Hash, 72*time.Hour, func(b *response.Builder) {
  22. b.WithHeader("Content-Security-Policy", response.ContentSecurityPolicyForUntrustedContent)
  23. b.WithHeader("Content-Type", icon.MimeType)
  24. b.WithBodyAsBytes(icon.Content)
  25. if icon.MimeType != "image/svg+xml" {
  26. b.WithoutCompression()
  27. }
  28. b.Write()
  29. })
  30. }