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-10 06:15:55 +02:00
|
|
|
package ui // import "miniflux.app/v2/ui"
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2023-08-10 06:15:55 +02:00
|
|
|
"miniflux.app/v2/config"
|
|
|
|
"miniflux.app/v2/http/request"
|
|
|
|
"miniflux.app/v2/http/response/html"
|
|
|
|
"miniflux.app/v2/http/route"
|
|
|
|
"miniflux.app/v2/model"
|
|
|
|
feedHandler "miniflux.app/v2/reader/handler"
|
|
|
|
"miniflux.app/v2/ui/form"
|
|
|
|
"miniflux.app/v2/ui/session"
|
|
|
|
"miniflux.app/v2/ui/view"
|
2018-04-30 01:35:04 +02:00
|
|
|
)
|
|
|
|
|
2018-11-11 20:28:29 +01: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-30 01:35:04 +02:00
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
user, err := h.store.UserByID(request.UserID(r))
|
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
|
|
|
|
}
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
categories, err := h.store.Categories(user.ID)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
view.Set("categories", categories)
|
|
|
|
view.Set("menu", "feeds")
|
|
|
|
view.Set("user", user)
|
2018-11-11 20:28:29 +01:00
|
|
|
view.Set("countUnread", h.store.CountUnreadEntries(user.ID))
|
2020-09-28 01:01:06 +02:00
|
|
|
view.Set("countErrorFeeds", h.store.CountUserFeedsWithErrors(user.ID))
|
2020-12-17 06:16:04 +01:00
|
|
|
view.Set("defaultUserAgent", config.Opts.HTTPClientUserAgent())
|
2018-04-30 01:35:04 +02:00
|
|
|
|
|
|
|
subscriptionForm := form.NewSubscriptionForm(r)
|
|
|
|
if err := subscriptionForm.Validate(); err != nil {
|
|
|
|
view.Set("form", subscriptionForm)
|
|
|
|
view.Set("errorMessage", err.Error())
|
2018-07-07 05:39:28 +02:00
|
|
|
html.OK(w, r, view.Render("add_subscription"))
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:49:28 +01:00
|
|
|
feed, err := feedHandler.CreateFeed(h.store, user.ID, &model.FeedCreationRequest{
|
2021-02-21 22:42:49 +01:00
|
|
|
CategoryID: subscriptionForm.CategoryID,
|
|
|
|
FeedURL: subscriptionForm.URL,
|
|
|
|
Crawler: subscriptionForm.Crawler,
|
|
|
|
AllowSelfSignedCertificates: subscriptionForm.AllowSelfSignedCertificates,
|
|
|
|
UserAgent: subscriptionForm.UserAgent,
|
2021-03-23 04:27:58 +01:00
|
|
|
Cookie: subscriptionForm.Cookie,
|
2021-02-21 22:42:49 +01:00
|
|
|
Username: subscriptionForm.Username,
|
|
|
|
Password: subscriptionForm.Password,
|
|
|
|
ScraperRules: subscriptionForm.ScraperRules,
|
|
|
|
RewriteRules: subscriptionForm.RewriteRules,
|
|
|
|
BlocklistRules: subscriptionForm.BlocklistRules,
|
|
|
|
KeeplistRules: subscriptionForm.KeeplistRules,
|
2022-07-12 06:12:26 +02:00
|
|
|
UrlRewriteRules: subscriptionForm.UrlRewriteRules,
|
2021-02-21 22:42:49 +01:00
|
|
|
FetchViaProxy: subscriptionForm.FetchViaProxy,
|
2021-01-03 01:33:41 +01:00
|
|
|
})
|
2018-04-30 01:35:04 +02:00
|
|
|
if err != nil {
|
|
|
|
view.Set("form", subscriptionForm)
|
|
|
|
view.Set("errorMessage", err)
|
2018-07-07 05:39:28 +02:00
|
|
|
html.OK(w, r, view.Render("add_subscription"))
|
2018-04-30 01:35:04 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-11 20:28:29 +01:00
|
|
|
html.Redirect(w, r, route.Path(h.router, "feedEntries", "feedID", feed.ID))
|
2018-04-30 01:35:04 +02:00
|
|
|
}
|