controller.go 1.3 KB

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