static_app_icon.go 927 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. "encoding/base64"
  7. "net/http"
  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, found := static.BinariesChecksums[filename]
  17. if !found {
  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 := base64.StdEncoding.DecodeString(static.Binaries[filename])
  23. if err != nil {
  24. html.ServerError(w, r, err)
  25. return
  26. }
  27. b.WithHeader("Content-Type", "image/png")
  28. b.WithoutCompression()
  29. b.WithBody(blob)
  30. b.Write()
  31. })
  32. }