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