static_stylesheet.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. "time"
  8. "miniflux.app/http/request"
  9. "miniflux.app/http/response"
  10. "miniflux.app/http/response/html"
  11. "miniflux.app/ui/static"
  12. )
  13. func (h *handler) showStylesheet(w http.ResponseWriter, r *http.Request) {
  14. filename := request.RouteStringParam(r, "name")
  15. if filename == "custom_css" {
  16. user, err := h.store.UserByID(request.UserID(r))
  17. if err != nil {
  18. html.NotFound(w, r)
  19. return
  20. }
  21. b := response.New(w, r)
  22. if user == nil {
  23. b.WithHeader("Content-Type", "text/css; charset=utf-8")
  24. b.WithBody("")
  25. b.Write()
  26. return
  27. }
  28. b.WithHeader("Content-Type", "text/css; charset=utf-8")
  29. b.WithBody(user.Extra["custom_css"])
  30. b.Write()
  31. return
  32. }
  33. etag, found := static.StylesheetsChecksums[filename]
  34. if !found {
  35. html.NotFound(w, r)
  36. return
  37. }
  38. response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) {
  39. b.WithHeader("Content-Type", "text/css; charset=utf-8")
  40. b.WithBody(static.Stylesheets[filename])
  41. b.Write()
  42. })
  43. }