controller.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. "github.com/miniflux/miniflux2/model"
  7. "github.com/miniflux/miniflux2/reader/feed"
  8. "github.com/miniflux/miniflux2/reader/opml"
  9. "github.com/miniflux/miniflux2/scheduler"
  10. "github.com/miniflux/miniflux2/server/core"
  11. "github.com/miniflux/miniflux2/storage"
  12. )
  13. type tplParams map[string]interface{}
  14. func (t tplParams) Merge(d tplParams) tplParams {
  15. for k, v := range d {
  16. t[k] = v
  17. }
  18. return t
  19. }
  20. // Controller contains all HTTP handlers for the user interface.
  21. type Controller struct {
  22. store *storage.Storage
  23. pool *scheduler.WorkerPool
  24. feedHandler *feed.Handler
  25. opmlHandler *opml.Handler
  26. }
  27. func (c *Controller) getCommonTemplateArgs(ctx *core.Context) (tplParams, error) {
  28. user := ctx.LoggedUser()
  29. builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
  30. builder.WithStatus(model.EntryStatusUnread)
  31. countUnread, err := builder.CountEntries()
  32. if err != nil {
  33. return nil, err
  34. }
  35. params := tplParams{
  36. "menu": "",
  37. "user": user,
  38. "countUnread": countUnread,
  39. "csrf": ctx.CsrfToken(),
  40. }
  41. return params, nil
  42. }
  43. // NewController returns a new Controller.
  44. func NewController(store *storage.Storage, pool *scheduler.WorkerPool, feedHandler *feed.Handler, opmlHandler *opml.Handler) *Controller {
  45. return &Controller{
  46. store: store,
  47. pool: pool,
  48. feedHandler: feedHandler,
  49. opmlHandler: opmlHandler,
  50. }
  51. }