feed.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package form // import "miniflux.app/v2/internal/ui/form"
  4. import (
  5. "net/http"
  6. "strconv"
  7. "miniflux.app/v2/internal/model"
  8. )
  9. // FeedForm represents a feed form in the UI
  10. type FeedForm struct {
  11. FeedURL string
  12. SiteURL string
  13. Title string
  14. Description string
  15. ScraperRules string
  16. RewriteRules string
  17. BlocklistRules string
  18. KeeplistRules string
  19. UrlRewriteRules string
  20. Crawler bool
  21. UserAgent string
  22. Cookie string
  23. CategoryID int64
  24. Username string
  25. Password string
  26. IgnoreHTTPCache bool
  27. AllowSelfSignedCertificates bool
  28. FetchViaProxy bool
  29. Disabled bool
  30. NoMediaPlayer bool
  31. HideGlobally bool
  32. CategoryHidden bool // Category has "hide_globally"
  33. AppriseServiceURLs string
  34. DisableHTTP2 bool
  35. NtfyEnabled bool
  36. NtfyPriority int
  37. }
  38. // Merge updates the fields of the given feed.
  39. func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
  40. feed.Category.ID = f.CategoryID
  41. feed.Title = f.Title
  42. feed.SiteURL = f.SiteURL
  43. feed.FeedURL = f.FeedURL
  44. feed.Description = f.Description
  45. feed.ScraperRules = f.ScraperRules
  46. feed.RewriteRules = f.RewriteRules
  47. feed.BlocklistRules = f.BlocklistRules
  48. feed.KeeplistRules = f.KeeplistRules
  49. feed.UrlRewriteRules = f.UrlRewriteRules
  50. feed.Crawler = f.Crawler
  51. feed.UserAgent = f.UserAgent
  52. feed.Cookie = f.Cookie
  53. feed.ParsingErrorCount = 0
  54. feed.ParsingErrorMsg = ""
  55. feed.Username = f.Username
  56. feed.Password = f.Password
  57. feed.IgnoreHTTPCache = f.IgnoreHTTPCache
  58. feed.AllowSelfSignedCertificates = f.AllowSelfSignedCertificates
  59. feed.FetchViaProxy = f.FetchViaProxy
  60. feed.Disabled = f.Disabled
  61. feed.NoMediaPlayer = f.NoMediaPlayer
  62. feed.HideGlobally = f.HideGlobally
  63. feed.AppriseServiceURLs = f.AppriseServiceURLs
  64. feed.DisableHTTP2 = f.DisableHTTP2
  65. feed.NtfyEnabled = f.NtfyEnabled
  66. feed.NtfyPriority = f.NtfyPriority
  67. return feed
  68. }
  69. // NewFeedForm parses the HTTP request and returns a FeedForm
  70. func NewFeedForm(r *http.Request) *FeedForm {
  71. categoryID, err := strconv.Atoi(r.FormValue("category_id"))
  72. if err != nil {
  73. categoryID = 0
  74. }
  75. ntfyPriority, err := strconv.Atoi(r.FormValue("ntfy_priority"))
  76. if err != nil {
  77. ntfyPriority = 0
  78. }
  79. return &FeedForm{
  80. FeedURL: r.FormValue("feed_url"),
  81. SiteURL: r.FormValue("site_url"),
  82. Title: r.FormValue("title"),
  83. Description: r.FormValue("description"),
  84. ScraperRules: r.FormValue("scraper_rules"),
  85. UserAgent: r.FormValue("user_agent"),
  86. Cookie: r.FormValue("cookie"),
  87. RewriteRules: r.FormValue("rewrite_rules"),
  88. BlocklistRules: r.FormValue("blocklist_rules"),
  89. KeeplistRules: r.FormValue("keeplist_rules"),
  90. UrlRewriteRules: r.FormValue("urlrewrite_rules"),
  91. Crawler: r.FormValue("crawler") == "1",
  92. CategoryID: int64(categoryID),
  93. Username: r.FormValue("feed_username"),
  94. Password: r.FormValue("feed_password"),
  95. IgnoreHTTPCache: r.FormValue("ignore_http_cache") == "1",
  96. AllowSelfSignedCertificates: r.FormValue("allow_self_signed_certificates") == "1",
  97. FetchViaProxy: r.FormValue("fetch_via_proxy") == "1",
  98. Disabled: r.FormValue("disabled") == "1",
  99. NoMediaPlayer: r.FormValue("no_media_player") == "1",
  100. HideGlobally: r.FormValue("hide_globally") == "1",
  101. AppriseServiceURLs: r.FormValue("apprise_service_urls"),
  102. DisableHTTP2: r.FormValue("disable_http2") == "1",
  103. NtfyEnabled: r.FormValue("ntfy_enabled") == "1",
  104. NtfyPriority: ntfyPriority,
  105. }
  106. }