controller.go 1.7 KB

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