mirror of
https://github.com/miniflux/v2.git
synced 2025-08-01 17:38:37 +00:00
Refactor feed discovery and avoid an extra HTTP request if the url provided is the feed
This commit is contained in:
parent
14e25ab9fe
commit
eeaab72a9f
31 changed files with 455 additions and 200 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"miniflux.app/v2/internal/http/route"
|
||||
"miniflux.app/v2/internal/locale"
|
||||
"miniflux.app/v2/internal/model"
|
||||
"miniflux.app/v2/internal/reader/fetcher"
|
||||
feedHandler "miniflux.app/v2/internal/reader/handler"
|
||||
"miniflux.app/v2/internal/reader/subscription"
|
||||
"miniflux.app/v2/internal/ui/form"
|
||||
|
@ -51,20 +52,24 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
var rssbridgeURL string
|
||||
var rssBridgeURL string
|
||||
if intg, err := h.store.Integration(user.ID); err == nil && intg != nil && intg.RSSBridgeEnabled {
|
||||
rssbridgeURL = intg.RSSBridgeURL
|
||||
rssBridgeURL = intg.RSSBridgeURL
|
||||
}
|
||||
|
||||
subscriptions, localizedError := subscription.FindSubscriptions(
|
||||
requestBuilder := fetcher.NewRequestBuilder()
|
||||
requestBuilder.WithTimeout(config.Opts.HTTPClientTimeout())
|
||||
requestBuilder.WithProxy(config.Opts.HTTPClientProxy())
|
||||
requestBuilder.WithUserAgent(subscriptionForm.UserAgent)
|
||||
requestBuilder.WithCookie(subscriptionForm.Cookie)
|
||||
requestBuilder.WithUsernameAndPassword(subscriptionForm.Username, subscriptionForm.Password)
|
||||
requestBuilder.UseProxy(subscriptionForm.FetchViaProxy)
|
||||
requestBuilder.IgnoreTLSErrors(subscriptionForm.AllowSelfSignedCertificates)
|
||||
|
||||
subscriptionFinder := subscription.NewSubscriptionFinder(requestBuilder)
|
||||
subscriptions, localizedError := subscriptionFinder.FindSubscriptions(
|
||||
subscriptionForm.URL,
|
||||
subscriptionForm.UserAgent,
|
||||
subscriptionForm.Cookie,
|
||||
subscriptionForm.Username,
|
||||
subscriptionForm.Password,
|
||||
subscriptionForm.FetchViaProxy,
|
||||
subscriptionForm.AllowSelfSignedCertificates,
|
||||
rssbridgeURL,
|
||||
rssBridgeURL,
|
||||
)
|
||||
if localizedError != nil {
|
||||
v.Set("form", subscriptionForm)
|
||||
|
@ -79,7 +84,35 @@ func (h *handler) submitSubscription(w http.ResponseWriter, r *http.Request) {
|
|||
v.Set("form", subscriptionForm)
|
||||
v.Set("errorMessage", locale.NewLocalizedError("error.subscription_not_found").Translate(user.Language))
|
||||
html.OK(w, r, v.Render("add_subscription"))
|
||||
case n == 1:
|
||||
case n == 1 && subscriptionFinder.IsFeedAlreadyDownloaded():
|
||||
feed, localizedError := feedHandler.CreateFeedFromSubscriptionDiscovery(h.store, user.ID, &model.FeedCreationRequestFromSubscriptionDiscovery{
|
||||
Content: subscriptionFinder.FeedResponseInfo().Content,
|
||||
ETag: subscriptionFinder.FeedResponseInfo().ETag,
|
||||
LastModified: subscriptionFinder.FeedResponseInfo().LastModified,
|
||||
CategoryID: subscriptionForm.CategoryID,
|
||||
FeedURL: subscriptions[0].URL,
|
||||
Crawler: subscriptionForm.Crawler,
|
||||
AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates,
|
||||
UserAgent: subscriptionForm.UserAgent,
|
||||
Cookie: subscriptionForm.Cookie,
|
||||
Username: subscriptionForm.Username,
|
||||
Password: subscriptionForm.Password,
|
||||
ScraperRules: subscriptionForm.ScraperRules,
|
||||
RewriteRules: subscriptionForm.RewriteRules,
|
||||
BlocklistRules: subscriptionForm.BlocklistRules,
|
||||
KeeplistRules: subscriptionForm.KeeplistRules,
|
||||
UrlRewriteRules: subscriptionForm.UrlRewriteRules,
|
||||
FetchViaProxy: subscriptionForm.FetchViaProxy,
|
||||
})
|
||||
if localizedError != nil {
|
||||
v.Set("form", subscriptionForm)
|
||||
v.Set("errorMessage", localizedError.Translate(user.Language))
|
||||
html.OK(w, r, v.Render("add_subscription"))
|
||||
return
|
||||
}
|
||||
|
||||
html.Redirect(w, r, route.Path(h.router, "feedEntries", "feedID", feed.ID))
|
||||
case n == 1 && !subscriptionFinder.IsFeedAlreadyDownloaded():
|
||||
feed, localizedError := feedHandler.CreateFeed(h.store, user.ID, &model.FeedCreationRequest{
|
||||
CategoryID: subscriptionForm.CategoryID,
|
||||
FeedURL: subscriptions[0].URL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue