feed.go 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package form // import "miniflux.app/ui/form"
  5. import (
  6. "net/http"
  7. "strconv"
  8. "miniflux.app/model"
  9. )
  10. // FeedForm represents a feed form in the UI
  11. type FeedForm struct {
  12. FeedURL string
  13. SiteURL string
  14. Title string
  15. ScraperRules string
  16. RewriteRules string
  17. BlocklistRules string
  18. KeeplistRules string
  19. UrlRewriteRules string
  20. Crawler bool
  21. UserAgent string
  22. Cookie string
  23. CategoryID int64
  24. Username string
  25. Password string
  26. IgnoreHTTPCache bool
  27. AllowSelfSignedCertificates bool
  28. FetchViaProxy bool
  29. Disabled bool
  30. HideGlobally bool
  31. CategoryHidden bool // Category has "hide_globally"
  32. }
  33. // Merge updates the fields of the given feed.
  34. func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
  35. feed.Category.ID = f.CategoryID
  36. feed.Title = f.Title
  37. feed.SiteURL = f.SiteURL
  38. feed.FeedURL = f.FeedURL
  39. feed.ScraperRules = f.ScraperRules
  40. feed.RewriteRules = f.RewriteRules
  41. feed.BlocklistRules = f.BlocklistRules
  42. feed.KeeplistRules = f.KeeplistRules
  43. feed.UrlRewriteRules = f.UrlRewriteRules
  44. feed.Crawler = f.Crawler
  45. feed.UserAgent = f.UserAgent
  46. feed.Cookie = f.Cookie
  47. feed.ParsingErrorCount = 0
  48. feed.ParsingErrorMsg = ""
  49. feed.Username = f.Username
  50. feed.Password = f.Password
  51. feed.IgnoreHTTPCache = f.IgnoreHTTPCache
  52. feed.AllowSelfSignedCertificates = f.AllowSelfSignedCertificates
  53. feed.FetchViaProxy = f.FetchViaProxy
  54. feed.Disabled = f.Disabled
  55. feed.HideGlobally = f.HideGlobally
  56. return feed
  57. }
  58. // NewFeedForm parses the HTTP request and returns a FeedForm
  59. func NewFeedForm(r *http.Request) *FeedForm {
  60. categoryID, err := strconv.Atoi(r.FormValue("category_id"))
  61. if err != nil {
  62. categoryID = 0
  63. }
  64. return &FeedForm{
  65. FeedURL: r.FormValue("feed_url"),
  66. SiteURL: r.FormValue("site_url"),
  67. Title: r.FormValue("title"),
  68. ScraperRules: r.FormValue("scraper_rules"),
  69. UserAgent: r.FormValue("user_agent"),
  70. Cookie: r.FormValue("cookie"),
  71. RewriteRules: r.FormValue("rewrite_rules"),
  72. BlocklistRules: r.FormValue("blocklist_rules"),
  73. KeeplistRules: r.FormValue("keeplist_rules"),
  74. UrlRewriteRules: r.FormValue("urlrewrite_rules"),
  75. Crawler: r.FormValue("crawler") == "1",
  76. CategoryID: int64(categoryID),
  77. Username: r.FormValue("feed_username"),
  78. Password: r.FormValue("feed_password"),
  79. IgnoreHTTPCache: r.FormValue("ignore_http_cache") == "1",
  80. AllowSelfSignedCertificates: r.FormValue("allow_self_signed_certificates") == "1",
  81. FetchViaProxy: r.FormValue("fetch_via_proxy") == "1",
  82. Disabled: r.FormValue("disabled") == "1",
  83. HideGlobally: r.FormValue("hide_globally") == "1",
  84. }
  85. }