2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
2023-09-25 01:32:09 +02:00
|
|
|
"log/slog"
|
2018-04-30 01:35:04 +02:00
|
|
|
"net/http"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/html"
|
|
|
|
"miniflux.app/v2/internal/http/route"
|
|
|
|
feedHandler "miniflux.app/v2/internal/reader/handler"
|
2023-10-19 04:57:02 +02:00
|
|
|
"miniflux.app/v2/internal/ui/session"
|
|
|
|
"miniflux.app/v2/internal/ui/view"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
func (h *handler) refreshFeed(w http.ResponseWriter, r *http.Request) {
|
2018-09-24 06:02:26 +02:00
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
2023-08-08 16:12:41 +02:00
|
|
|
forceRefresh := request.QueryBoolParam(r, "forceRefresh", false)
|
|
|
|
if err := feedHandler.RefreshFeed(h.store, request.UserID(r), feedID, forceRefresh); err != nil {
|
2023-09-25 01:32:09 +02:00
|
|
|
slog.Warn("Unable to refresh feed",
|
|
|
|
slog.Int64("user_id", request.UserID(r)),
|
|
|
|
slog.Int64("feed_id", feedID),
|
|
|
|
slog.Bool("force_refresh", forceRefresh),
|
|
|
|
slog.Any("error", err),
|
|
|
|
)
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "feedEntries", "feedID", feedID))
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
2018-09-03 23:26:40 +02:00
|
|
|
userID := request.UserID(r)
|
2023-10-19 04:57:02 +02:00
|
|
|
|
|
|
|
user, err := h.store.UserByID(userID)
|
|
|
|
if err != nil {
|
|
|
|
html.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
jobs, err := h.store.NewUserBatch(userID, h.store.CountFeeds(userID))
|
2018-04-30 01:35:04 +02:00
|
|
|
if err != nil {
|
2018-10-08 03:42:43 +02:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-17 06:20:58 +02:00
|
|
|
slog.Info(
|
|
|
|
"Triggered a manual refresh of all feeds from the web ui",
|
|
|
|
slog.Int64("user_id", userID),
|
|
|
|
slog.Int("nb_jobs", len(jobs)),
|
|
|
|
)
|
|
|
|
|
|
|
|
go h.pool.Push(jobs)
|
2018-04-30 01:35:04 +02:00
|
|
|
|
2023-10-19 04:57:02 +02:00
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
|
|
|
view.Set("menu", "feeds")
|
|
|
|
view.Set("user", user)
|
|
|
|
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
|
|
|
|
|
|
|
html.OK(w, r, view.Render("feed_background_refresh"))
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|