static_app_icon.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. etag, err := static.GetBinaryFileChecksum(filename)
  16. if err != nil {
  17. html.NotFound(w, r)
  18. return
  19. }
  20. response.New(w, r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) {
  21. blob, err := static.LoadBinaryFile(filename)
  22. if err != nil {
  23. html.ServerError(w, r, err)
  24. return
  25. }
  26. switch filepath.Ext(filename) {
  27. case ".png":
  28. b.WithoutCompression()
  29. b.WithHeader("Content-Type", "image/png")
  30. case ".svg":
  31. b.WithHeader("Content-Type", "image/svg+xml")
  32. }
  33. b.WithBody(blob)
  34. b.Write()
  35. })
  36. }