feed.go 4.8 KB

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