4
0

integration.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. // IntegrationForm represents user integration settings form.
  10. type IntegrationForm struct {
  11. PinboardEnabled bool
  12. PinboardToken string
  13. PinboardTags string
  14. PinboardMarkAsUnread bool
  15. InstapaperEnabled bool
  16. InstapaperUsername string
  17. InstapaperPassword string
  18. FeverEnabled bool
  19. FeverUsername string
  20. FeverPassword string
  21. GoogleReaderEnabled bool
  22. GoogleReaderUsername string
  23. GoogleReaderPassword string
  24. WallabagEnabled bool
  25. WallabagOnlyURL bool
  26. WallabagURL string
  27. WallabagClientID string
  28. WallabagClientSecret string
  29. WallabagUsername string
  30. WallabagPassword string
  31. NotionEnabled bool
  32. NotionPageID string
  33. NotionToken string
  34. NunuxKeeperEnabled bool
  35. NunuxKeeperURL string
  36. NunuxKeeperAPIKey string
  37. EspialEnabled bool
  38. EspialURL string
  39. EspialAPIKey string
  40. EspialTags string
  41. ReadwiseEnabled bool
  42. ReadwiseAPIKey string
  43. PocketEnabled bool
  44. PocketAccessToken string
  45. PocketConsumerKey string
  46. TelegramBotEnabled bool
  47. TelegramBotToken string
  48. TelegramBotChatID string
  49. TelegramBotTopicID *int64
  50. TelegramBotDisableWebPagePreview bool
  51. TelegramBotDisableNotification bool
  52. TelegramBotDisableButtons bool
  53. LinkdingEnabled bool
  54. LinkdingURL string
  55. LinkdingAPIKey string
  56. LinkdingTags string
  57. LinkdingMarkAsUnread bool
  58. MatrixBotEnabled bool
  59. MatrixBotUser string
  60. MatrixBotPassword string
  61. MatrixBotURL string
  62. MatrixBotChatID string
  63. AppriseEnabled bool
  64. AppriseURL string
  65. AppriseServicesURL string
  66. ShioriEnabled bool
  67. ShioriURL string
  68. ShioriUsername string
  69. ShioriPassword string
  70. ShaarliEnabled bool
  71. ShaarliURL string
  72. ShaarliAPISecret string
  73. WebhookEnabled bool
  74. WebhookURL string
  75. WebhookSecret string
  76. RSSBridgeEnabled bool
  77. RSSBridgeURL string
  78. }
  79. // Merge copy form values to the model.
  80. func (i IntegrationForm) Merge(integration *model.Integration) {
  81. integration.PinboardEnabled = i.PinboardEnabled
  82. integration.PinboardToken = i.PinboardToken
  83. integration.PinboardTags = i.PinboardTags
  84. integration.PinboardMarkAsUnread = i.PinboardMarkAsUnread
  85. integration.InstapaperEnabled = i.InstapaperEnabled
  86. integration.InstapaperUsername = i.InstapaperUsername
  87. integration.InstapaperPassword = i.InstapaperPassword
  88. integration.FeverEnabled = i.FeverEnabled
  89. integration.FeverUsername = i.FeverUsername
  90. integration.GoogleReaderEnabled = i.GoogleReaderEnabled
  91. integration.GoogleReaderUsername = i.GoogleReaderUsername
  92. integration.WallabagEnabled = i.WallabagEnabled
  93. integration.WallabagOnlyURL = i.WallabagOnlyURL
  94. integration.WallabagURL = i.WallabagURL
  95. integration.WallabagClientID = i.WallabagClientID
  96. integration.WallabagClientSecret = i.WallabagClientSecret
  97. integration.WallabagUsername = i.WallabagUsername
  98. integration.WallabagPassword = i.WallabagPassword
  99. integration.NotionEnabled = i.NotionEnabled
  100. integration.NotionPageID = i.NotionPageID
  101. integration.NotionToken = i.NotionToken
  102. integration.NunuxKeeperEnabled = i.NunuxKeeperEnabled
  103. integration.NunuxKeeperURL = i.NunuxKeeperURL
  104. integration.NunuxKeeperAPIKey = i.NunuxKeeperAPIKey
  105. integration.EspialEnabled = i.EspialEnabled
  106. integration.EspialURL = i.EspialURL
  107. integration.EspialAPIKey = i.EspialAPIKey
  108. integration.EspialTags = i.EspialTags
  109. integration.ReadwiseEnabled = i.ReadwiseEnabled
  110. integration.ReadwiseAPIKey = i.ReadwiseAPIKey
  111. integration.PocketEnabled = i.PocketEnabled
  112. integration.PocketAccessToken = i.PocketAccessToken
  113. integration.PocketConsumerKey = i.PocketConsumerKey
  114. integration.TelegramBotEnabled = i.TelegramBotEnabled
  115. integration.TelegramBotToken = i.TelegramBotToken
  116. integration.TelegramBotChatID = i.TelegramBotChatID
  117. integration.TelegramBotTopicID = i.TelegramBotTopicID
  118. integration.TelegramBotDisableWebPagePreview = i.TelegramBotDisableWebPagePreview
  119. integration.TelegramBotDisableNotification = i.TelegramBotDisableNotification
  120. integration.TelegramBotDisableButtons = i.TelegramBotDisableButtons
  121. integration.LinkdingEnabled = i.LinkdingEnabled
  122. integration.LinkdingURL = i.LinkdingURL
  123. integration.LinkdingAPIKey = i.LinkdingAPIKey
  124. integration.LinkdingTags = i.LinkdingTags
  125. integration.LinkdingMarkAsUnread = i.LinkdingMarkAsUnread
  126. integration.MatrixBotEnabled = i.MatrixBotEnabled
  127. integration.MatrixBotUser = i.MatrixBotUser
  128. integration.MatrixBotPassword = i.MatrixBotPassword
  129. integration.MatrixBotURL = i.MatrixBotURL
  130. integration.MatrixBotChatID = i.MatrixBotChatID
  131. integration.AppriseEnabled = i.AppriseEnabled
  132. integration.AppriseServicesURL = i.AppriseServicesURL
  133. integration.AppriseURL = i.AppriseURL
  134. integration.ShioriEnabled = i.ShioriEnabled
  135. integration.ShioriURL = i.ShioriURL
  136. integration.ShioriUsername = i.ShioriUsername
  137. integration.ShioriPassword = i.ShioriPassword
  138. integration.ShaarliEnabled = i.ShaarliEnabled
  139. integration.ShaarliURL = i.ShaarliURL
  140. integration.ShaarliAPISecret = i.ShaarliAPISecret
  141. integration.WebhookEnabled = i.WebhookEnabled
  142. integration.WebhookURL = i.WebhookURL
  143. integration.RSSBridgeEnabled = i.RSSBridgeEnabled
  144. integration.RSSBridgeURL = i.RSSBridgeURL
  145. }
  146. // NewIntegrationForm returns a new IntegrationForm.
  147. func NewIntegrationForm(r *http.Request) *IntegrationForm {
  148. return &IntegrationForm{
  149. PinboardEnabled: r.FormValue("pinboard_enabled") == "1",
  150. PinboardToken: r.FormValue("pinboard_token"),
  151. PinboardTags: r.FormValue("pinboard_tags"),
  152. PinboardMarkAsUnread: r.FormValue("pinboard_mark_as_unread") == "1",
  153. InstapaperEnabled: r.FormValue("instapaper_enabled") == "1",
  154. InstapaperUsername: r.FormValue("instapaper_username"),
  155. InstapaperPassword: r.FormValue("instapaper_password"),
  156. FeverEnabled: r.FormValue("fever_enabled") == "1",
  157. FeverUsername: r.FormValue("fever_username"),
  158. FeverPassword: r.FormValue("fever_password"),
  159. GoogleReaderEnabled: r.FormValue("googlereader_enabled") == "1",
  160. GoogleReaderUsername: r.FormValue("googlereader_username"),
  161. GoogleReaderPassword: r.FormValue("googlereader_password"),
  162. WallabagEnabled: r.FormValue("wallabag_enabled") == "1",
  163. WallabagOnlyURL: r.FormValue("wallabag_only_url") == "1",
  164. WallabagURL: r.FormValue("wallabag_url"),
  165. WallabagClientID: r.FormValue("wallabag_client_id"),
  166. WallabagClientSecret: r.FormValue("wallabag_client_secret"),
  167. WallabagUsername: r.FormValue("wallabag_username"),
  168. WallabagPassword: r.FormValue("wallabag_password"),
  169. NotionEnabled: r.FormValue("notion_enabled") == "1",
  170. NotionPageID: r.FormValue("notion_page_id"),
  171. NotionToken: r.FormValue("notion_token"),
  172. NunuxKeeperEnabled: r.FormValue("nunux_keeper_enabled") == "1",
  173. NunuxKeeperURL: r.FormValue("nunux_keeper_url"),
  174. NunuxKeeperAPIKey: r.FormValue("nunux_keeper_api_key"),
  175. EspialEnabled: r.FormValue("espial_enabled") == "1",
  176. EspialURL: r.FormValue("espial_url"),
  177. EspialAPIKey: r.FormValue("espial_api_key"),
  178. EspialTags: r.FormValue("espial_tags"),
  179. ReadwiseEnabled: r.FormValue("readwise_enabled") == "1",
  180. ReadwiseAPIKey: r.FormValue("readwise_api_key"),
  181. PocketEnabled: r.FormValue("pocket_enabled") == "1",
  182. PocketAccessToken: r.FormValue("pocket_access_token"),
  183. PocketConsumerKey: r.FormValue("pocket_consumer_key"),
  184. TelegramBotEnabled: r.FormValue("telegram_bot_enabled") == "1",
  185. TelegramBotToken: r.FormValue("telegram_bot_token"),
  186. TelegramBotChatID: r.FormValue("telegram_bot_chat_id"),
  187. TelegramBotTopicID: optionalInt64Field(r.FormValue("telegram_bot_topic_id")),
  188. TelegramBotDisableWebPagePreview: r.FormValue("telegram_bot_disable_web_page_preview") == "1",
  189. TelegramBotDisableNotification: r.FormValue("telegram_bot_disable_notification") == "1",
  190. TelegramBotDisableButtons: r.FormValue("telegram_bot_disable_buttons") == "1",
  191. LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
  192. LinkdingURL: r.FormValue("linkding_url"),
  193. LinkdingAPIKey: r.FormValue("linkding_api_key"),
  194. LinkdingTags: r.FormValue("linkding_tags"),
  195. LinkdingMarkAsUnread: r.FormValue("linkding_mark_as_unread") == "1",
  196. MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
  197. MatrixBotUser: r.FormValue("matrix_bot_user"),
  198. MatrixBotPassword: r.FormValue("matrix_bot_password"),
  199. MatrixBotURL: r.FormValue("matrix_bot_url"),
  200. MatrixBotChatID: r.FormValue("matrix_bot_chat_id"),
  201. AppriseEnabled: r.FormValue("apprise_enabled") == "1",
  202. AppriseURL: r.FormValue("apprise_url"),
  203. AppriseServicesURL: r.FormValue("apprise_services_url"),
  204. ShioriEnabled: r.FormValue("shiori_enabled") == "1",
  205. ShioriURL: r.FormValue("shiori_url"),
  206. ShioriUsername: r.FormValue("shiori_username"),
  207. ShioriPassword: r.FormValue("shiori_password"),
  208. ShaarliEnabled: r.FormValue("shaarli_enabled") == "1",
  209. ShaarliURL: r.FormValue("shaarli_url"),
  210. ShaarliAPISecret: r.FormValue("shaarli_api_secret"),
  211. WebhookEnabled: r.FormValue("webhook_enabled") == "1",
  212. WebhookURL: r.FormValue("webhook_url"),
  213. RSSBridgeEnabled: r.FormValue("rssbridge_enabled") == "1",
  214. RSSBridgeURL: r.FormValue("rssbridge_url"),
  215. }
  216. }
  217. func optionalInt64Field(formValue string) *int64 {
  218. if formValue == "" {
  219. return nil
  220. }
  221. value, _ := strconv.ParseInt(formValue, 10, 64)
  222. return &value
  223. }