feed.go 2.9 KB

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