category_refresh.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. "log/slog"
  6. "net/http"
  7. "miniflux.app/v2/internal/http/request"
  8. "miniflux.app/v2/internal/http/response/html"
  9. "miniflux.app/v2/internal/http/route"
  10. )
  11. func (h *handler) refreshCategoryEntriesPage(w http.ResponseWriter, r *http.Request) {
  12. categoryID := h.refreshCategory(w, r)
  13. html.Redirect(w, r, route.Path(h.router, "categoryEntries", "categoryID", categoryID))
  14. }
  15. func (h *handler) refreshCategoryFeedsPage(w http.ResponseWriter, r *http.Request) {
  16. categoryID := h.refreshCategory(w, r)
  17. html.Redirect(w, r, route.Path(h.router, "categoryFeeds", "categoryID", categoryID))
  18. }
  19. func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64 {
  20. userID := request.UserID(r)
  21. categoryID := request.RouteInt64Param(r, "categoryID")
  22. jobs, err := h.store.NewCategoryBatch(userID, categoryID, h.store.CountFeeds(userID))
  23. if err != nil {
  24. html.ServerError(w, r, err)
  25. return 0
  26. }
  27. slog.Info(
  28. "Triggered a manual refresh of all feeds for a given category from the web ui",
  29. slog.Int64("user_id", userID),
  30. slog.Int64("category_id", categoryID),
  31. slog.Int("nb_jobs", len(jobs)),
  32. )
  33. go h.pool.Push(jobs)
  34. return categoryID
  35. }