static_app_icon.go 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package ui // import "miniflux.app/ui"
  5. import (
  6. "net/http"
  7. "path/filepath"
  8. "time"
  9. "miniflux.app/http/request"
  10. "miniflux.app/http/response"
  11. "miniflux.app/http/response/html"
  12. "miniflux.app/ui/static"
  13. )
  14. func (h *handler) showAppIcon(w http.ResponseWriter, r *http.Request) {
  15. filename := request.RouteStringParam(r, "filename")
  16. etag, err := static.GetBinaryFileChecksum(filename)
  17. if err != nil {
  18. html.NotFound(w, r)
  19. return
  20. }
  21. response.New(w, r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) {
  22. blob, err := static.LoadBinaryFile(filename)
  23. if err != nil {
  24. html.ServerError(w, r, err)
  25. return
  26. }
  27. switch filepath.Ext(filename) {
  28. case ".png":
  29. b.WithHeader("Content-Type", "image/png")
  30. case ".svg":
  31. b.WithHeader("Content-Type", "image/svg+xml")
  32. }
  33. b.WithoutCompression()
  34. b.WithBody(blob)
  35. b.Write()
  36. })
  37. }