category_refresh.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package ui // import "miniflux.app/v2/internal/ui"
  4. import (
  5. "net/http"
  6. "miniflux.app/v2/internal/http/request"
  7. "miniflux.app/v2/internal/http/response/html"
  8. "miniflux.app/v2/internal/http/route"
  9. )
  10. func (h *handler) refreshCategoryEntriesPage(w http.ResponseWriter, r *http.Request) {
  11. categoryID := h.refreshCategory(w, r)
  12. html.Redirect(w, r, route.Path(h.router, "categoryEntries", "categoryID", categoryID))
  13. }
  14. func (h *handler) refreshCategoryFeedsPage(w http.ResponseWriter, r *http.Request) {
  15. categoryID := h.refreshCategory(w, r)
  16. html.Redirect(w, r, route.Path(h.router, "categoryFeeds", "categoryID", categoryID))
  17. }
  18. func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64 {
  19. userID := request.UserID(r)
  20. categoryID := request.RouteInt64Param(r, "categoryID")
  21. jobs, err := h.store.NewCategoryBatch(userID, categoryID, h.store.CountFeeds(userID))
  22. if err != nil {
  23. html.ServerError(w, r, err)
  24. return 0
  25. }
  26. go func() {
  27. h.pool.Push(jobs)
  28. }()
  29. return categoryID
  30. }