feed.go 2.2 KB

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