2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package ui // import "miniflux.app/v2/internal/ui"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
import (
|
2023-09-24 19:32:09 -04:00
|
|
|
"log/slog"
|
2018-04-29 19:35:04 -04:00
|
|
|
"net/http"
|
2023-10-20 18:12:02 -04:00
|
|
|
"time"
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2024-01-02 21:33:15 -05:00
|
|
|
"miniflux.app/v2/internal/config"
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/html"
|
|
|
|
"miniflux.app/v2/internal/http/route"
|
2023-10-20 18:12:02 -04:00
|
|
|
"miniflux.app/v2/internal/locale"
|
2023-08-10 22:46:45 -04:00
|
|
|
feedHandler "miniflux.app/v2/internal/reader/handler"
|
2023-10-18 22:57:02 -04:00
|
|
|
"miniflux.app/v2/internal/ui/session"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) refreshFeed(w http.ResponseWriter, r *http.Request) {
|
2018-09-24 00:02:26 -04:00
|
|
|
feedID := request.RouteInt64Param(r, "feedID")
|
2023-08-08 10:12:41 -04:00
|
|
|
forceRefresh := request.QueryBoolParam(r, "forceRefresh", false)
|
2023-11-01 14:28:24 -04:00
|
|
|
if localizedError := feedHandler.RefreshFeed(h.store, request.UserID(r), feedID, forceRefresh); localizedError != nil {
|
2023-09-24 19:32:09 -04:00
|
|
|
slog.Warn("Unable to refresh feed",
|
|
|
|
slog.Int64("user_id", request.UserID(r)),
|
|
|
|
slog.Int64("feed_id", feedID),
|
|
|
|
slog.Bool("force_refresh", forceRefresh),
|
2023-11-01 14:28:24 -04:00
|
|
|
slog.Any("error", localizedError.Error()),
|
2023-09-24 19:32:09 -04:00
|
|
|
)
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "feedEntries", "feedID", feedID))
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
2018-09-03 17:26:40 -04:00
|
|
|
userID := request.UserID(r)
|
2023-10-20 18:12:02 -04:00
|
|
|
printer := locale.NewPrinter(request.UserLanguage(r))
|
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
2023-10-18 22:57:02 -04:00
|
|
|
|
2023-10-20 18:12:02 -04:00
|
|
|
// Avoid accidental and excessive refreshes.
|
2024-01-02 21:33:15 -05:00
|
|
|
if time.Now().UTC().Unix()-request.LastForceRefresh(r) < int64(config.Opts.ForceRefreshInterval())*60 {
|
|
|
|
time := config.Opts.ForceRefreshInterval()
|
|
|
|
sess.NewFlashErrorMessage(printer.Plural("alert.too_many_feeds_refresh", time, time))
|
2023-10-20 18:12:02 -04:00
|
|
|
} else {
|
|
|
|
// We allow the end-user to force refresh all its feeds
|
|
|
|
// without taking into consideration the number of errors.
|
|
|
|
batchBuilder := h.store.NewBatchBuilder()
|
|
|
|
batchBuilder.WithoutDisabledFeeds()
|
|
|
|
batchBuilder.WithUserID(userID)
|
2023-10-18 22:57:02 -04:00
|
|
|
|
2023-10-20 18:12:02 -04:00
|
|
|
jobs, err := batchBuilder.FetchJobs()
|
|
|
|
if err != nil {
|
|
|
|
html.ServerError(w, r, err)
|
|
|
|
return
|
|
|
|
}
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2023-10-20 18:12:02 -04: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)),
|
|
|
|
)
|
2023-10-17 00:20:58 -04:00
|
|
|
|
2023-10-20 18:12:02 -04:00
|
|
|
go h.pool.Push(jobs)
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2023-10-20 18:12:02 -04:00
|
|
|
sess.SetLastForceRefresh()
|
|
|
|
sess.NewFlashMessage(printer.Printf("alert.background_feed_refresh"))
|
|
|
|
}
|
2023-10-18 22:57:02 -04:00
|
|
|
|
2023-10-20 18:12:02 -04:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "feeds"))
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|