feed.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. UrlRewriteRules string
  18. BlocklistRules string
  19. KeeplistRules string
  20. BlockFilterEntryRules string
  21. KeepFilterEntryRules string
  22. Crawler bool
  23. IgnoreEntryUpdates bool
  24. UserAgent string
  25. Cookie string
  26. CategoryID int64
  27. Username string
  28. Password string
  29. IgnoreHTTPCache bool
  30. AllowSelfSignedCertificates bool
  31. FetchViaProxy bool
  32. Disabled bool
  33. NoMediaPlayer bool
  34. HideGlobally bool
  35. CategoryHidden bool // Category has "hide_globally"
  36. AppriseServiceURLs string
  37. WebhookURL string
  38. DisableHTTP2 bool
  39. NtfyEnabled bool
  40. NtfyPriority int
  41. NtfyTopic string
  42. PushoverEnabled bool
  43. PushoverPriority int
  44. ProxyURL string
  45. }
  46. // Merge updates the fields of the given feed.
  47. func (f FeedForm) Merge(feed *model.Feed) *model.Feed {
  48. feed.Category.ID = f.CategoryID
  49. feed.Title = f.Title
  50. feed.SiteURL = f.SiteURL
  51. feed.FeedURL = f.FeedURL
  52. feed.Description = f.Description
  53. feed.ScraperRules = f.ScraperRules
  54. feed.RewriteRules = f.RewriteRules
  55. feed.UrlRewriteRules = f.UrlRewriteRules
  56. feed.BlocklistRules = f.BlocklistRules
  57. feed.KeeplistRules = f.KeeplistRules
  58. feed.BlockFilterEntryRules = f.BlockFilterEntryRules
  59. feed.KeepFilterEntryRules = f.KeepFilterEntryRules
  60. feed.Crawler = f.Crawler
  61. feed.IgnoreEntryUpdates = f.IgnoreEntryUpdates
  62. feed.UserAgent = f.UserAgent
  63. feed.Cookie = f.Cookie
  64. feed.ParsingErrorCount = 0
  65. feed.ParsingErrorMsg = ""
  66. feed.Username = f.Username
  67. feed.Password = f.Password
  68. feed.IgnoreHTTPCache = f.IgnoreHTTPCache
  69. feed.AllowSelfSignedCertificates = f.AllowSelfSignedCertificates
  70. feed.FetchViaProxy = f.FetchViaProxy
  71. feed.Disabled = f.Disabled
  72. feed.NoMediaPlayer = f.NoMediaPlayer
  73. feed.HideGlobally = f.HideGlobally
  74. feed.AppriseServiceURLs = f.AppriseServiceURLs
  75. feed.WebhookURL = f.WebhookURL
  76. feed.DisableHTTP2 = f.DisableHTTP2
  77. feed.NtfyEnabled = f.NtfyEnabled
  78. feed.NtfyPriority = f.NtfyPriority
  79. feed.NtfyTopic = f.NtfyTopic
  80. feed.PushoverEnabled = f.PushoverEnabled
  81. feed.PushoverPriority = f.PushoverPriority
  82. feed.ProxyURL = f.ProxyURL
  83. return feed
  84. }
  85. // NewFeedForm parses the HTTP request and returns a FeedForm
  86. func NewFeedForm(r *http.Request) *FeedForm {
  87. categoryID, err := strconv.Atoi(r.FormValue("category_id"))
  88. if err != nil {
  89. categoryID = 0
  90. }
  91. ntfyPriority, err := strconv.Atoi(r.FormValue("ntfy_priority"))
  92. if err != nil {
  93. ntfyPriority = 0
  94. }
  95. pushoverPriority, err := strconv.Atoi(r.FormValue("pushover_priority"))
  96. if err != nil {
  97. pushoverPriority = 0
  98. }
  99. return &FeedForm{
  100. FeedURL: r.FormValue("feed_url"),
  101. SiteURL: r.FormValue("site_url"),
  102. Title: r.FormValue("title"),
  103. Description: r.FormValue("description"),
  104. ScraperRules: r.FormValue("scraper_rules"),
  105. UserAgent: r.FormValue("user_agent"),
  106. Cookie: r.FormValue("cookie"),
  107. RewriteRules: r.FormValue("rewrite_rules"),
  108. UrlRewriteRules: r.FormValue("urlrewrite_rules"),
  109. BlocklistRules: r.FormValue("blocklist_rules"),
  110. KeeplistRules: r.FormValue("keeplist_rules"),
  111. BlockFilterEntryRules: r.FormValue("block_filter_entry_rules"),
  112. KeepFilterEntryRules: r.FormValue("keep_filter_entry_rules"),
  113. Crawler: r.FormValue("crawler") == "1",
  114. IgnoreEntryUpdates: r.FormValue("ignore_entry_updates") == "1",
  115. CategoryID: int64(categoryID),
  116. Username: r.FormValue("feed_username"),
  117. Password: r.FormValue("feed_password"),
  118. IgnoreHTTPCache: r.FormValue("ignore_http_cache") == "1",
  119. AllowSelfSignedCertificates: r.FormValue("allow_self_signed_certificates") == "1",
  120. FetchViaProxy: r.FormValue("fetch_via_proxy") == "1",
  121. Disabled: r.FormValue("disabled") == "1",
  122. NoMediaPlayer: r.FormValue("no_media_player") == "1",
  123. HideGlobally: r.FormValue("hide_globally") == "1",
  124. AppriseServiceURLs: r.FormValue("apprise_service_urls"),
  125. WebhookURL: r.FormValue("webhook_url"),
  126. DisableHTTP2: r.FormValue("disable_http2") == "1",
  127. NtfyEnabled: r.FormValue("ntfy_enabled") == "1",
  128. NtfyPriority: ntfyPriority,
  129. NtfyTopic: r.FormValue("ntfy_topic"),
  130. PushoverEnabled: r.FormValue("pushover_enabled") == "1",
  131. PushoverPriority: pushoverPriority,
  132. ProxyURL: r.FormValue("proxy_url"),
  133. }
  134. }