integration.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. OmnivoreEnabled bool
  79. OmnivoreAPIKey string
  80. OmnivoreURL string
  81. }
  82. // Merge copy form values to the model.
  83. func (i IntegrationForm) Merge(integration *model.Integration) {
  84. integration.PinboardEnabled = i.PinboardEnabled
  85. integration.PinboardToken = i.PinboardToken
  86. integration.PinboardTags = i.PinboardTags
  87. integration.PinboardMarkAsUnread = i.PinboardMarkAsUnread
  88. integration.InstapaperEnabled = i.InstapaperEnabled
  89. integration.InstapaperUsername = i.InstapaperUsername
  90. integration.InstapaperPassword = i.InstapaperPassword
  91. integration.FeverEnabled = i.FeverEnabled
  92. integration.FeverUsername = i.FeverUsername
  93. integration.GoogleReaderEnabled = i.GoogleReaderEnabled
  94. integration.GoogleReaderUsername = i.GoogleReaderUsername
  95. integration.WallabagEnabled = i.WallabagEnabled
  96. integration.WallabagOnlyURL = i.WallabagOnlyURL
  97. integration.WallabagURL = i.WallabagURL
  98. integration.WallabagClientID = i.WallabagClientID
  99. integration.WallabagClientSecret = i.WallabagClientSecret
  100. integration.WallabagUsername = i.WallabagUsername
  101. integration.WallabagPassword = i.WallabagPassword
  102. integration.NotionEnabled = i.NotionEnabled
  103. integration.NotionPageID = i.NotionPageID
  104. integration.NotionToken = i.NotionToken
  105. integration.NunuxKeeperEnabled = i.NunuxKeeperEnabled
  106. integration.NunuxKeeperURL = i.NunuxKeeperURL
  107. integration.NunuxKeeperAPIKey = i.NunuxKeeperAPIKey
  108. integration.EspialEnabled = i.EspialEnabled
  109. integration.EspialURL = i.EspialURL
  110. integration.EspialAPIKey = i.EspialAPIKey
  111. integration.EspialTags = i.EspialTags
  112. integration.ReadwiseEnabled = i.ReadwiseEnabled
  113. integration.ReadwiseAPIKey = i.ReadwiseAPIKey
  114. integration.PocketEnabled = i.PocketEnabled
  115. integration.PocketAccessToken = i.PocketAccessToken
  116. integration.PocketConsumerKey = i.PocketConsumerKey
  117. integration.TelegramBotEnabled = i.TelegramBotEnabled
  118. integration.TelegramBotToken = i.TelegramBotToken
  119. integration.TelegramBotChatID = i.TelegramBotChatID
  120. integration.TelegramBotTopicID = i.TelegramBotTopicID
  121. integration.TelegramBotDisableWebPagePreview = i.TelegramBotDisableWebPagePreview
  122. integration.TelegramBotDisableNotification = i.TelegramBotDisableNotification
  123. integration.TelegramBotDisableButtons = i.TelegramBotDisableButtons
  124. integration.LinkdingEnabled = i.LinkdingEnabled
  125. integration.LinkdingURL = i.LinkdingURL
  126. integration.LinkdingAPIKey = i.LinkdingAPIKey
  127. integration.LinkdingTags = i.LinkdingTags
  128. integration.LinkdingMarkAsUnread = i.LinkdingMarkAsUnread
  129. integration.MatrixBotEnabled = i.MatrixBotEnabled
  130. integration.MatrixBotUser = i.MatrixBotUser
  131. integration.MatrixBotPassword = i.MatrixBotPassword
  132. integration.MatrixBotURL = i.MatrixBotURL
  133. integration.MatrixBotChatID = i.MatrixBotChatID
  134. integration.AppriseEnabled = i.AppriseEnabled
  135. integration.AppriseServicesURL = i.AppriseServicesURL
  136. integration.AppriseURL = i.AppriseURL
  137. integration.ShioriEnabled = i.ShioriEnabled
  138. integration.ShioriURL = i.ShioriURL
  139. integration.ShioriUsername = i.ShioriUsername
  140. integration.ShioriPassword = i.ShioriPassword
  141. integration.ShaarliEnabled = i.ShaarliEnabled
  142. integration.ShaarliURL = i.ShaarliURL
  143. integration.ShaarliAPISecret = i.ShaarliAPISecret
  144. integration.WebhookEnabled = i.WebhookEnabled
  145. integration.WebhookURL = i.WebhookURL
  146. integration.RSSBridgeEnabled = i.RSSBridgeEnabled
  147. integration.RSSBridgeURL = i.RSSBridgeURL
  148. integration.OmnivoreEnabled = i.OmnivoreEnabled
  149. integration.OmnivoreAPIKey = i.OmnivoreAPIKey
  150. integration.OmnivoreURL = i.OmnivoreURL
  151. }
  152. // NewIntegrationForm returns a new IntegrationForm.
  153. func NewIntegrationForm(r *http.Request) *IntegrationForm {
  154. return &IntegrationForm{
  155. PinboardEnabled: r.FormValue("pinboard_enabled") == "1",
  156. PinboardToken: r.FormValue("pinboard_token"),
  157. PinboardTags: r.FormValue("pinboard_tags"),
  158. PinboardMarkAsUnread: r.FormValue("pinboard_mark_as_unread") == "1",
  159. InstapaperEnabled: r.FormValue("instapaper_enabled") == "1",
  160. InstapaperUsername: r.FormValue("instapaper_username"),
  161. InstapaperPassword: r.FormValue("instapaper_password"),
  162. FeverEnabled: r.FormValue("fever_enabled") == "1",
  163. FeverUsername: r.FormValue("fever_username"),
  164. FeverPassword: r.FormValue("fever_password"),
  165. GoogleReaderEnabled: r.FormValue("googlereader_enabled") == "1",
  166. GoogleReaderUsername: r.FormValue("googlereader_username"),
  167. GoogleReaderPassword: r.FormValue("googlereader_password"),
  168. WallabagEnabled: r.FormValue("wallabag_enabled") == "1",
  169. WallabagOnlyURL: r.FormValue("wallabag_only_url") == "1",
  170. WallabagURL: r.FormValue("wallabag_url"),
  171. WallabagClientID: r.FormValue("wallabag_client_id"),
  172. WallabagClientSecret: r.FormValue("wallabag_client_secret"),
  173. WallabagUsername: r.FormValue("wallabag_username"),
  174. WallabagPassword: r.FormValue("wallabag_password"),
  175. NotionEnabled: r.FormValue("notion_enabled") == "1",
  176. NotionPageID: r.FormValue("notion_page_id"),
  177. NotionToken: r.FormValue("notion_token"),
  178. NunuxKeeperEnabled: r.FormValue("nunux_keeper_enabled") == "1",
  179. NunuxKeeperURL: r.FormValue("nunux_keeper_url"),
  180. NunuxKeeperAPIKey: r.FormValue("nunux_keeper_api_key"),
  181. EspialEnabled: r.FormValue("espial_enabled") == "1",
  182. EspialURL: r.FormValue("espial_url"),
  183. EspialAPIKey: r.FormValue("espial_api_key"),
  184. EspialTags: r.FormValue("espial_tags"),
  185. ReadwiseEnabled: r.FormValue("readwise_enabled") == "1",
  186. ReadwiseAPIKey: r.FormValue("readwise_api_key"),
  187. PocketEnabled: r.FormValue("pocket_enabled") == "1",
  188. PocketAccessToken: r.FormValue("pocket_access_token"),
  189. PocketConsumerKey: r.FormValue("pocket_consumer_key"),
  190. TelegramBotEnabled: r.FormValue("telegram_bot_enabled") == "1",
  191. TelegramBotToken: r.FormValue("telegram_bot_token"),
  192. TelegramBotChatID: r.FormValue("telegram_bot_chat_id"),
  193. TelegramBotTopicID: optionalInt64Field(r.FormValue("telegram_bot_topic_id")),
  194. TelegramBotDisableWebPagePreview: r.FormValue("telegram_bot_disable_web_page_preview") == "1",
  195. TelegramBotDisableNotification: r.FormValue("telegram_bot_disable_notification") == "1",
  196. TelegramBotDisableButtons: r.FormValue("telegram_bot_disable_buttons") == "1",
  197. LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
  198. LinkdingURL: r.FormValue("linkding_url"),
  199. LinkdingAPIKey: r.FormValue("linkding_api_key"),
  200. LinkdingTags: r.FormValue("linkding_tags"),
  201. LinkdingMarkAsUnread: r.FormValue("linkding_mark_as_unread") == "1",
  202. MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
  203. MatrixBotUser: r.FormValue("matrix_bot_user"),
  204. MatrixBotPassword: r.FormValue("matrix_bot_password"),
  205. MatrixBotURL: r.FormValue("matrix_bot_url"),
  206. MatrixBotChatID: r.FormValue("matrix_bot_chat_id"),
  207. AppriseEnabled: r.FormValue("apprise_enabled") == "1",
  208. AppriseURL: r.FormValue("apprise_url"),
  209. AppriseServicesURL: r.FormValue("apprise_services_url"),
  210. ShioriEnabled: r.FormValue("shiori_enabled") == "1",
  211. ShioriURL: r.FormValue("shiori_url"),
  212. ShioriUsername: r.FormValue("shiori_username"),
  213. ShioriPassword: r.FormValue("shiori_password"),
  214. ShaarliEnabled: r.FormValue("shaarli_enabled") == "1",
  215. ShaarliURL: r.FormValue("shaarli_url"),
  216. ShaarliAPISecret: r.FormValue("shaarli_api_secret"),
  217. WebhookEnabled: r.FormValue("webhook_enabled") == "1",
  218. WebhookURL: r.FormValue("webhook_url"),
  219. RSSBridgeEnabled: r.FormValue("rssbridge_enabled") == "1",
  220. RSSBridgeURL: r.FormValue("rssbridge_url"),
  221. OmnivoreEnabled: r.FormValue("omnivore_enabled") == "1",
  222. OmnivoreAPIKey: r.FormValue("omnivore_api_key"),
  223. OmnivoreURL: r.FormValue("omnivore_url"),
  224. }
  225. }
  226. func optionalInt64Field(formValue string) *int64 {
  227. if formValue == "" {
  228. return nil
  229. }
  230. value, _ := strconv.ParseInt(formValue, 10, 64)
  231. return &value
  232. }