feed_refresh.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2018 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 ui
  5. import (
  6. "net/http"
  7. "github.com/miniflux/miniflux/http/context"
  8. "github.com/miniflux/miniflux/http/request"
  9. "github.com/miniflux/miniflux/http/response"
  10. "github.com/miniflux/miniflux/http/response/html"
  11. "github.com/miniflux/miniflux/http/route"
  12. "github.com/miniflux/miniflux/logger"
  13. )
  14. // RefreshFeed refresh a subscription and redirect to the feed entries page.
  15. func (c *Controller) RefreshFeed(w http.ResponseWriter, r *http.Request) {
  16. feedID, err := request.IntParam(r, "feedID")
  17. if err != nil {
  18. html.BadRequest(w, err)
  19. return
  20. }
  21. ctx := context.New(r)
  22. if err := c.feedHandler.RefreshFeed(ctx.UserID(), feedID); err != nil {
  23. logger.Error("[Controller:RefreshFeed] %v", err)
  24. }
  25. response.Redirect(w, r, route.Path(c.router, "feedEntries", "feedID", feedID))
  26. }
  27. // RefreshAllFeeds refresh all feeds in the background for the current user.
  28. func (c *Controller) RefreshAllFeeds(w http.ResponseWriter, r *http.Request) {
  29. userID := context.New(r).UserID()
  30. jobs, err := c.store.NewUserBatch(userID, c.store.CountFeeds(userID))
  31. if err != nil {
  32. html.ServerError(w, err)
  33. return
  34. }
  35. go func() {
  36. c.pool.Push(jobs)
  37. }()
  38. response.Redirect(w, r, route.Path(c.router, "feeds"))
  39. }