2017-11-20 00:10:04 -05:00
|
|
|
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
package form // import "miniflux.app/ui/form"
|
2017-11-20 00:10:04 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
2017-11-28 00:30:04 -05:00
|
|
|
|
2018-08-25 00:51:50 -04:00
|
|
|
"miniflux.app/model"
|
2017-11-20 00:10:04 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// FeedForm represents a feed form in the UI
|
|
|
|
type FeedForm struct {
|
2021-02-21 16:42:49 -05:00
|
|
|
FeedURL string
|
|
|
|
SiteURL string
|
|
|
|
Title string
|
|
|
|
ScraperRules string
|
|
|
|
RewriteRules string
|
|
|
|
BlocklistRules string
|
|
|
|
KeeplistRules string
|
|
|
|
Crawler bool
|
|
|
|
UserAgent string
|
2021-03-22 23:27:58 -04:00
|
|
|
Cookie string
|
2021-02-21 16:42:49 -05:00
|
|
|
CategoryID int64
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
IgnoreHTTPCache bool
|
|
|
|
AllowSelfSignedCertificates bool
|
|
|
|
FetchViaProxy bool
|
|
|
|
Disabled bool
|
2021-08-15 11:32:43 -04:00
|
|
|
HideGlobally bool
|
2021-08-16 05:23:52 -04:00
|
|
|
CategoryHidden bool // Category has "hide_globally"
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
|
2017-11-28 00:30:04 -05:00
|
|
|
// Merge updates the fields of the given feed.
|
2017-11-20 00:10:04 -05:00
|
|
|
func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
|
|
|
|
feed.Category.ID = f.CategoryID
|
|
|
|
feed.Title = f.Title
|
|
|
|
feed.SiteURL = f.SiteURL
|
|
|
|
feed.FeedURL = f.FeedURL
|
2017-12-10 23:51:04 -05:00
|
|
|
feed.ScraperRules = f.ScraperRules
|
2017-12-12 01:16:32 -05:00
|
|
|
feed.RewriteRules = f.RewriteRules
|
2020-10-16 17:40:56 -04:00
|
|
|
feed.BlocklistRules = f.BlocklistRules
|
|
|
|
feed.KeeplistRules = f.KeeplistRules
|
2017-12-12 22:19:36 -05:00
|
|
|
feed.Crawler = f.Crawler
|
2018-09-19 21:19:24 -04:00
|
|
|
feed.UserAgent = f.UserAgent
|
2021-03-22 23:27:58 -04:00
|
|
|
feed.Cookie = f.Cookie
|
2017-11-20 00:10:04 -05:00
|
|
|
feed.ParsingErrorCount = 0
|
|
|
|
feed.ParsingErrorMsg = ""
|
2018-06-20 01:58:29 -04:00
|
|
|
feed.Username = f.Username
|
|
|
|
feed.Password = f.Password
|
2020-06-06 00:50:59 -04:00
|
|
|
feed.IgnoreHTTPCache = f.IgnoreHTTPCache
|
2021-02-21 16:42:49 -05:00
|
|
|
feed.AllowSelfSignedCertificates = f.AllowSelfSignedCertificates
|
2020-09-10 02:28:54 -04:00
|
|
|
feed.FetchViaProxy = f.FetchViaProxy
|
2019-07-27 00:13:06 -04:00
|
|
|
feed.Disabled = f.Disabled
|
2021-08-15 11:32:43 -04:00
|
|
|
feed.HideGlobally = f.HideGlobally
|
2017-11-20 00:10:04 -05:00
|
|
|
return feed
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewFeedForm parses the HTTP request and returns a FeedForm
|
|
|
|
func NewFeedForm(r *http.Request) *FeedForm {
|
|
|
|
categoryID, err := strconv.Atoi(r.FormValue("category_id"))
|
|
|
|
if err != nil {
|
|
|
|
categoryID = 0
|
|
|
|
}
|
|
|
|
return &FeedForm{
|
2021-02-21 16:42:49 -05:00
|
|
|
FeedURL: r.FormValue("feed_url"),
|
|
|
|
SiteURL: r.FormValue("site_url"),
|
|
|
|
Title: r.FormValue("title"),
|
|
|
|
ScraperRules: r.FormValue("scraper_rules"),
|
|
|
|
UserAgent: r.FormValue("user_agent"),
|
2021-03-22 23:27:58 -04:00
|
|
|
Cookie: r.FormValue("cookie"),
|
2021-02-21 16:42:49 -05:00
|
|
|
RewriteRules: r.FormValue("rewrite_rules"),
|
|
|
|
BlocklistRules: r.FormValue("blocklist_rules"),
|
|
|
|
KeeplistRules: r.FormValue("keeplist_rules"),
|
|
|
|
Crawler: r.FormValue("crawler") == "1",
|
|
|
|
CategoryID: int64(categoryID),
|
|
|
|
Username: r.FormValue("feed_username"),
|
|
|
|
Password: r.FormValue("feed_password"),
|
|
|
|
IgnoreHTTPCache: r.FormValue("ignore_http_cache") == "1",
|
|
|
|
AllowSelfSignedCertificates: r.FormValue("allow_self_signed_certificates") == "1",
|
|
|
|
FetchViaProxy: r.FormValue("fetch_via_proxy") == "1",
|
|
|
|
Disabled: r.FormValue("disabled") == "1",
|
2021-08-15 11:32:43 -04:00
|
|
|
HideGlobally: r.FormValue("hide_globally") == "1",
|
2017-11-20 00:10:04 -05:00
|
|
|
}
|
|
|
|
}
|