static.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2017 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 controller
  5. import (
  6. "encoding/base64"
  7. "github.com/miniflux/miniflux2/server/core"
  8. "github.com/miniflux/miniflux2/server/static"
  9. "log"
  10. "time"
  11. )
  12. func (c *Controller) Stylesheet(ctx *core.Context, request *core.Request, response *core.Response) {
  13. stylesheet := request.GetStringParam("name", "white")
  14. body := static.Stylesheets["common"]
  15. etag := static.StylesheetsChecksums["common"]
  16. if theme, found := static.Stylesheets[stylesheet]; found {
  17. body += theme
  18. etag += static.StylesheetsChecksums[stylesheet]
  19. }
  20. response.Cache("text/css", etag, []byte(body), 48*time.Hour)
  21. }
  22. func (c *Controller) Javascript(ctx *core.Context, request *core.Request, response *core.Response) {
  23. response.Cache("text/javascript", static.JavascriptChecksums["app"], []byte(static.Javascript["app"]), 48*time.Hour)
  24. }
  25. func (c *Controller) Favicon(ctx *core.Context, request *core.Request, response *core.Response) {
  26. blob, err := base64.StdEncoding.DecodeString(static.Binaries["favicon.ico"])
  27. if err != nil {
  28. log.Println(err)
  29. response.Html().NotFound()
  30. return
  31. }
  32. response.Cache("image/x-icon", static.BinariesChecksums["favicon.ico"], blob, 48*time.Hour)
  33. }