static_javascript.go 843 B

12345678910111213141516171819202122232425262728293031
  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. // Javascript renders application client side code.
  14. func (c *Controller) Javascript(w http.ResponseWriter, r *http.Request) {
  15. filename := request.RouteStringParam(r, "name")
  16. etag, found := static.JavascriptsChecksums[filename]
  17. if !found {
  18. html.NotFound(w, r)
  19. return
  20. }
  21. response.New(w, r).WithCaching(etag, 48*time.Hour, func(b *response.Builder) {
  22. b.WithHeader("Content-Type", "text/javascript; charset=utf-8")
  23. b.WithBody(static.Javascripts[filename])
  24. b.Write()
  25. })
  26. }