feed.go 4.7 KB

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