feed.go 5.2 KB

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