static_app_icon.go 988 B

12345678910111213141516171819202122232425262728293031323334353637
  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/logger"
  13. "miniflux.app/ui/static"
  14. )
  15. // AppIcon renders application icons.
  16. func (c *Controller) AppIcon(w http.ResponseWriter, r *http.Request) {
  17. filename := request.Param(r, "filename", "favicon.png")
  18. encodedBlob, found := static.Binaries[filename]
  19. if !found {
  20. logger.Info("[Controller:AppIcon] This icon doesn't exists: %s", filename)
  21. html.NotFound(w)
  22. return
  23. }
  24. blob, err := base64.StdEncoding.DecodeString(encodedBlob)
  25. if err != nil {
  26. logger.Error("[Controller:AppIcon] %v", err)
  27. html.NotFound(w)
  28. return
  29. }
  30. response.Cache(w, r, "image/png", static.BinariesChecksums[filename], blob, 48*time.Hour)
  31. }