controller.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.NewEntryQueryBuilder(user.ID)
  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.CSRF(),
  42. "flashMessage": ctx.FlashMessage(),
  43. }
  44. return params, nil
  45. }
  46. // NewController returns a new Controller.
  47. func NewController(cfg *config.Config, store *storage.Storage, pool *scheduler.WorkerPool, feedHandler *feed.Handler, opmlHandler *opml.Handler) *Controller {
  48. return &Controller{
  49. cfg: cfg,
  50. store: store,
  51. pool: pool,
  52. feedHandler: feedHandler,
  53. opmlHandler: opmlHandler,
  54. }
  55. }