static_app_icon.go 902 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. "path/filepath"
  7. "time"
  8. "miniflux.app/v2/internal/http/request"
  9. "miniflux.app/v2/internal/http/response"
  10. "miniflux.app/v2/internal/ui/static"
  11. )
  12. func (h *handler) showAppIcon(w http.ResponseWriter, r *http.Request) {
  13. filename := request.RouteStringParam(r, "filename")
  14. value, ok := static.BinaryBundles[filename]
  15. if !ok {
  16. response.HTMLNotFound(w, r)
  17. return
  18. }
  19. response.NewBuilder(w, r).WithCaching(value.Checksum, 72*time.Hour, func(b *response.Builder) {
  20. switch filepath.Ext(filename) {
  21. case ".png":
  22. b.WithoutCompression()
  23. b.WithHeader("Content-Type", "image/png")
  24. case ".svg":
  25. b.WithHeader("Content-Type", "image/svg+xml")
  26. }
  27. b.WithBodyAsBytes(value.Data)
  28. b.Write()
  29. })
  30. }