feed.go 2.8 KB

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