integration.go 13 KB

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