static_app_icon.go 962 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. // AppIcon shows application icons.
  15. func (c *Controller) AppIcon(w http.ResponseWriter, r *http.Request) {
  16. filename := request.RouteStringParam(r, "filename")
  17. etag, found := static.BinariesChecksums[filename]
  18. if !found {
  19. html.NotFound(w, r)
  20. return
  21. }
  22. response.New(w, r).WithCaching(etag, 72*time.Hour, func(b *response.Builder) {
  23. blob, err := base64.StdEncoding.DecodeString(static.Binaries[filename])
  24. if err != nil {
  25. html.ServerError(w, r, err)
  26. return
  27. }
  28. b.WithHeader("Content-Type", "image/png")
  29. b.WithoutCompression()
  30. b.WithBody(blob)
  31. b.Write()
  32. })
  33. }