feed.go 3.1 KB

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