feed.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. Crawler bool
  20. UserAgent string
  21. Cookie string
  22. CategoryID int64
  23. Username string
  24. Password string
  25. IgnoreHTTPCache bool
  26. AllowSelfSignedCertificates bool
  27. FetchViaProxy bool
  28. Disabled bool
  29. HideGlobally bool
  30. }
  31. // Merge updates the fields of the given feed.
  32. func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
  33. feed.Category.ID = f.CategoryID
  34. feed.Title = f.Title
  35. feed.SiteURL = f.SiteURL
  36. feed.FeedURL = f.FeedURL
  37. feed.ScraperRules = f.ScraperRules
  38. feed.RewriteRules = f.RewriteRules
  39. feed.BlocklistRules = f.BlocklistRules
  40. feed.KeeplistRules = f.KeeplistRules
  41. feed.Crawler = f.Crawler
  42. feed.UserAgent = f.UserAgent
  43. feed.Cookie = f.Cookie
  44. feed.ParsingErrorCount = 0
  45. feed.ParsingErrorMsg = ""
  46. feed.Username = f.Username
  47. feed.Password = f.Password
  48. feed.IgnoreHTTPCache = f.IgnoreHTTPCache
  49. feed.AllowSelfSignedCertificates = f.AllowSelfSignedCertificates
  50. feed.FetchViaProxy = f.FetchViaProxy
  51. feed.Disabled = f.Disabled
  52. feed.HideGlobally = f.HideGlobally
  53. return feed
  54. }
  55. // NewFeedForm parses the HTTP request and returns a FeedForm
  56. func NewFeedForm(r *http.Request) *FeedForm {
  57. categoryID, err := strconv.Atoi(r.FormValue("category_id"))
  58. if err != nil {
  59. categoryID = 0
  60. }
  61. return &FeedForm{
  62. FeedURL: r.FormValue("feed_url"),
  63. SiteURL: r.FormValue("site_url"),
  64. Title: r.FormValue("title"),
  65. ScraperRules: r.FormValue("scraper_rules"),
  66. UserAgent: r.FormValue("user_agent"),
  67. Cookie: r.FormValue("cookie"),
  68. RewriteRules: r.FormValue("rewrite_rules"),
  69. BlocklistRules: r.FormValue("blocklist_rules"),
  70. KeeplistRules: r.FormValue("keeplist_rules"),
  71. Crawler: r.FormValue("crawler") == "1",
  72. CategoryID: int64(categoryID),
  73. Username: r.FormValue("feed_username"),
  74. Password: r.FormValue("feed_password"),
  75. IgnoreHTTPCache: r.FormValue("ignore_http_cache") == "1",
  76. AllowSelfSignedCertificates: r.FormValue("allow_self_signed_certificates") == "1",
  77. FetchViaProxy: r.FormValue("fetch_via_proxy") == "1",
  78. Disabled: r.FormValue("disabled") == "1",
  79. HideGlobally: r.FormValue("hide_globally") == "1",
  80. }
  81. }