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 (
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
|
"miniflux.app/v2/internal/http/request"
|
|
|
|
"miniflux.app/v2/internal/http/response/html"
|
|
|
|
"miniflux.app/v2/internal/http/route"
|
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
|
feedHandler "miniflux.app/v2/internal/reader/handler"
|
|
|
|
"miniflux.app/v2/internal/ui/form"
|
|
|
|
"miniflux.app/v2/internal/ui/session"
|
|
|
|
"miniflux.app/v2/internal/ui/view"
|
2018-04-29 19:35:04 -04:00
|
|
|
)
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
func (h *handler) showChooseSubscriptionPage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
sess := session.New(h.store, request.SessionID(r))
|
|
|
|
view := view.New(h.tpl, r, sess)
|
2018-04-29 19:35:04 -04:00
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
2018-04-29 19:35:04 -04:00
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
categories, err := h.store.Categories(user.ID)
|
2018-04-29 19:35:04 -04:00
|
|
|
if err != nil {
|
2018-10-07 21:42:43 -04:00
|
|
|
html.ServerError(w, r, err)
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
view.Set("categories", categories)
|
|
|
|
view.Set("menu", "feeds")
|
|
|
|
view.Set("user", user)
|
2018-11-11 14:28:29 -05:00
|
|
|
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
2020-09-27 19:01:06 -04:00
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
2020-12-17 00:16:04 -05:00
|
|
|
view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
2018-04-29 19:35:04 -04:00
|
|
|
|
|
|
|
subscriptionForm := form.NewSubscriptionForm(r)
|
2023-10-21 22:50:29 -04:00
|
|
|
if validationErr := subscriptionForm.Validate(); validationErr != nil {
|
2018-04-29 19:35:04 -04:00
|
|
|
view.Set("form", subscriptionForm)
|
2023-10-21 22:50:29 -04:00
|
|
|
view.Set("errorMessage", validationErr.Translate(user.Language))
|
2018-07-06 23:39:28 -04:00
|
|
|
html.OK(w, r, view.Render("add_subscription"))
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-10-21 22:50:29 -04:00
|
|
|
feed, localizedError := feedHandler.CreateFeed(h.store, user.ID, &model.FeedCreationRequest{
|
2021-02-21 16:42:49 -05:00
|
|
|
CategoryID: subscriptionForm.CategoryID,
|
|
|
|
FeedURL: subscriptionForm.URL,
|
|
|
|
Crawler: subscriptionForm.Crawler,
|
|
|
|
AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates,
|
|
|
|
UserAgent: subscriptionForm.UserAgent,
|
2021-03-22 23:27:58 -04:00
|
|
|
Cookie: subscriptionForm.Cookie,
|
2021-02-21 16:42:49 -05:00
|
|
|
Username: subscriptionForm.Username,
|
|
|
|
Password: subscriptionForm.Password,
|
|
|
|
ScraperRules: subscriptionForm.ScraperRules,
|
|
|
|
RewriteRules: subscriptionForm.RewriteRules,
|
|
|
|
BlocklistRules: subscriptionForm.BlocklistRules,
|
|
|
|
KeeplistRules: subscriptionForm.KeeplistRules,
|
2022-07-12 00:12:26 -04:00
|
|
|
UrlRewriteRules: subscriptionForm.UrlRewriteRules,
|
2021-02-21 16:42:49 -05:00
|
|
|
FetchViaProxy: subscriptionForm.FetchViaProxy,
|
2024-02-25 01:08:23 -05:00
|
|
|
DisableHTTP2: subscriptionForm.DisableHTTP2,
|
2021-01-02 19:33:41 -05:00
|
|
|
})
|
2023-10-21 22:50:29 -04:00
|
|
|
if localizedError != nil {
|
2018-04-29 19:35:04 -04:00
|
|
|
view.Set("form", subscriptionForm)
|
2023-10-21 22:50:29 -04:00
|
|
|
view.Set("errorMessage", localizedError.Translate(user.Language))
|
2018-07-06 23:39:28 -04:00
|
|
|
html.OK(w, r, view.Render("add_subscription"))
|
2018-04-29 19:35:04 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-11 14:28:29 -05:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "feedEntries", "feedID", feed.ID))
|
2018-04-29 19:35:04 -04:00
|
|
|
}
|