Add refreshAllFeeds to the API

Adds refreshAllFeeds to the API, following the suggestion given in the
comments of #359.
This commit is contained in:
Aled Griffiths 2020-02-26 21:32:18 +00:00 committed by Frédéric Guillot
parent 7389c79c52
commit 7b32f59281
4 changed files with 22 additions and 3 deletions

View file

@ -7,13 +7,14 @@ package api // import "miniflux.app/api"
import (
"miniflux.app/reader/feed"
"miniflux.app/storage"
"miniflux.app/worker"
"github.com/gorilla/mux"
)
// Serve declares API routes for the application.
func Serve(router *mux.Router, store *storage.Storage, feedHandler *feed.Handler) {
handler := &handler{store, feedHandler}
func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool, feedHandler *feed.Handler) {
handler := &handler{store, pool, feedHandler}
sr := router.PathPrefix("/v1").Subrouter()
sr.Use(newMiddleware(store).serve)
@ -31,6 +32,7 @@ func Serve(router *mux.Router, store *storage.Storage, feedHandler *feed.Handler
sr.HandleFunc("/discover", handler.getSubscriptions).Methods("POST")
sr.HandleFunc("/feeds", handler.createFeed).Methods("POST")
sr.HandleFunc("/feeds", handler.getFeeds).Methods("GET")
sr.HandleFunc("/feeds/refresh", handler.refreshAllFeeds).Methods("PUT")
sr.HandleFunc("/feeds/{feedID}/refresh", handler.refreshFeed).Methods("PUT")
sr.HandleFunc("/feeds/{feedID}", handler.getFeed).Methods("GET")
sr.HandleFunc("/feeds/{feedID}", handler.updateFeed).Methods("PUT")

View file

@ -82,6 +82,21 @@ func (h *handler) refreshFeed(w http.ResponseWriter, r *http.Request) {
json.NoContent(w, r)
}
func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
userID := request.UserID(r)
jobs, err := h.store.NewUserBatch(userID, h.store.CountFeeds(userID))
if err != nil {
json.ServerError(w, r, err)
return
}
go func() {
h.pool.Push(jobs)
}()
json.NoContent(w, r)
}
func (h *handler) updateFeed(w http.ResponseWriter, r *http.Request) {
feedID := request.RouteInt64Param(r, "feedID")
feedChanges, err := decodeFeedModificationPayload(r.Body)

View file

@ -7,9 +7,11 @@ package api // import "miniflux.app/api"
import (
"miniflux.app/reader/feed"
"miniflux.app/storage"
"miniflux.app/worker"
)
type handler struct {
store *storage.Storage
pool *worker.Pool
feedHandler *feed.Handler
}

View file

@ -166,7 +166,7 @@ func setupHandler(store *storage.Storage, feedHandler *feed.Handler, pool *worke
router.Use(middleware)
fever.Serve(router, store)
api.Serve(router, store, feedHandler)
api.Serve(router, store, pool, feedHandler)
ui.Serve(router, store, pool, feedHandler)
router.HandleFunc("/healthcheck", func(w http.ResponseWriter, r *http.Request) {