4
0

controller.go 1.6 KB

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