integration.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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. LinkwardenEnabled bool
  65. LinkwardenURL string
  66. LinkwardenAPIKey string
  67. MatrixBotEnabled bool
  68. MatrixBotUser string
  69. MatrixBotPassword string
  70. MatrixBotURL string
  71. MatrixBotChatID string
  72. AppriseEnabled bool
  73. AppriseURL string
  74. AppriseServicesURL string
  75. ReadeckEnabled bool
  76. ReadeckURL string
  77. ReadeckAPIKey string
  78. ReadeckLabels string
  79. ReadeckOnlyURL bool
  80. ShioriEnabled bool
  81. ShioriURL string
  82. ShioriUsername string
  83. ShioriPassword string
  84. ShaarliEnabled bool
  85. ShaarliURL string
  86. ShaarliAPISecret string
  87. WebhookEnabled bool
  88. WebhookURL string
  89. WebhookSecret string
  90. RSSBridgeEnabled bool
  91. RSSBridgeURL string
  92. OmnivoreEnabled bool
  93. OmnivoreAPIKey string
  94. OmnivoreURL string
  95. RaindropEnabled bool
  96. RaindropToken string
  97. RaindropCollectionID string
  98. RaindropTags string
  99. BetulaEnabled bool
  100. BetulaURL string
  101. BetulaToken string
  102. NtfyEnabled bool
  103. NtfyTopic string
  104. NtfyURL string
  105. NtfyAPIToken string
  106. NtfyUsername string
  107. NtfyPassword string
  108. NtfyIconURL string
  109. NtfyInternalLinks bool
  110. CuboxEnabled bool
  111. CuboxAPILink string
  112. DiscordEnabled bool
  113. DiscordWebhookLink string
  114. SlackEnabled bool
  115. SlackWebhookLink string
  116. PushoverEnabled bool
  117. PushoverUser string
  118. PushoverToken string
  119. PushoverDevice string
  120. PushoverPrefix string
  121. }
  122. // Merge copy form values to the model.
  123. func (i IntegrationForm) Merge(integration *model.Integration) {
  124. integration.PinboardEnabled = i.PinboardEnabled
  125. integration.PinboardToken = i.PinboardToken
  126. integration.PinboardTags = i.PinboardTags
  127. integration.PinboardMarkAsUnread = i.PinboardMarkAsUnread
  128. integration.InstapaperEnabled = i.InstapaperEnabled
  129. integration.InstapaperUsername = i.InstapaperUsername
  130. integration.InstapaperPassword = i.InstapaperPassword
  131. integration.FeverEnabled = i.FeverEnabled
  132. integration.FeverUsername = i.FeverUsername
  133. integration.GoogleReaderEnabled = i.GoogleReaderEnabled
  134. integration.GoogleReaderUsername = i.GoogleReaderUsername
  135. integration.WallabagEnabled = i.WallabagEnabled
  136. integration.WallabagOnlyURL = i.WallabagOnlyURL
  137. integration.WallabagURL = i.WallabagURL
  138. integration.WallabagClientID = i.WallabagClientID
  139. integration.WallabagClientSecret = i.WallabagClientSecret
  140. integration.WallabagUsername = i.WallabagUsername
  141. integration.WallabagPassword = i.WallabagPassword
  142. integration.NotionEnabled = i.NotionEnabled
  143. integration.NotionPageID = i.NotionPageID
  144. integration.NotionToken = i.NotionToken
  145. integration.NunuxKeeperEnabled = i.NunuxKeeperEnabled
  146. integration.NunuxKeeperURL = i.NunuxKeeperURL
  147. integration.NunuxKeeperAPIKey = i.NunuxKeeperAPIKey
  148. integration.EspialEnabled = i.EspialEnabled
  149. integration.EspialURL = i.EspialURL
  150. integration.EspialAPIKey = i.EspialAPIKey
  151. integration.EspialTags = i.EspialTags
  152. integration.ReadwiseEnabled = i.ReadwiseEnabled
  153. integration.ReadwiseAPIKey = i.ReadwiseAPIKey
  154. integration.PocketEnabled = i.PocketEnabled
  155. integration.PocketAccessToken = i.PocketAccessToken
  156. integration.PocketConsumerKey = i.PocketConsumerKey
  157. integration.TelegramBotEnabled = i.TelegramBotEnabled
  158. integration.TelegramBotToken = i.TelegramBotToken
  159. integration.TelegramBotChatID = i.TelegramBotChatID
  160. integration.TelegramBotTopicID = i.TelegramBotTopicID
  161. integration.TelegramBotDisableWebPagePreview = i.TelegramBotDisableWebPagePreview
  162. integration.TelegramBotDisableNotification = i.TelegramBotDisableNotification
  163. integration.TelegramBotDisableButtons = i.TelegramBotDisableButtons
  164. integration.LinkAceEnabled = i.LinkAceEnabled
  165. integration.LinkAceURL = i.LinkAceURL
  166. integration.LinkAceAPIKey = i.LinkAceAPIKey
  167. integration.LinkAceTags = i.LinkAceTags
  168. integration.LinkAcePrivate = i.LinkAcePrivate
  169. integration.LinkAceCheckDisabled = i.LinkAceCheckDisabled
  170. integration.LinkdingEnabled = i.LinkdingEnabled
  171. integration.LinkdingURL = i.LinkdingURL
  172. integration.LinkdingAPIKey = i.LinkdingAPIKey
  173. integration.LinkdingTags = i.LinkdingTags
  174. integration.LinkdingMarkAsUnread = i.LinkdingMarkAsUnread
  175. integration.LinkwardenEnabled = i.LinkwardenEnabled
  176. integration.LinkwardenURL = i.LinkwardenURL
  177. integration.LinkwardenAPIKey = i.LinkwardenAPIKey
  178. integration.MatrixBotEnabled = i.MatrixBotEnabled
  179. integration.MatrixBotUser = i.MatrixBotUser
  180. integration.MatrixBotPassword = i.MatrixBotPassword
  181. integration.MatrixBotURL = i.MatrixBotURL
  182. integration.MatrixBotChatID = i.MatrixBotChatID
  183. integration.AppriseEnabled = i.AppriseEnabled
  184. integration.AppriseServicesURL = i.AppriseServicesURL
  185. integration.AppriseURL = i.AppriseURL
  186. integration.ReadeckEnabled = i.ReadeckEnabled
  187. integration.ReadeckURL = i.ReadeckURL
  188. integration.ReadeckAPIKey = i.ReadeckAPIKey
  189. integration.ReadeckLabels = i.ReadeckLabels
  190. integration.ReadeckOnlyURL = i.ReadeckOnlyURL
  191. integration.ShioriEnabled = i.ShioriEnabled
  192. integration.ShioriURL = i.ShioriURL
  193. integration.ShioriUsername = i.ShioriUsername
  194. integration.ShioriPassword = i.ShioriPassword
  195. integration.ShaarliEnabled = i.ShaarliEnabled
  196. integration.ShaarliURL = i.ShaarliURL
  197. integration.ShaarliAPISecret = i.ShaarliAPISecret
  198. integration.WebhookEnabled = i.WebhookEnabled
  199. integration.WebhookURL = i.WebhookURL
  200. integration.RSSBridgeEnabled = i.RSSBridgeEnabled
  201. integration.RSSBridgeURL = i.RSSBridgeURL
  202. integration.OmnivoreEnabled = i.OmnivoreEnabled
  203. integration.OmnivoreAPIKey = i.OmnivoreAPIKey
  204. integration.OmnivoreURL = i.OmnivoreURL
  205. integration.RaindropEnabled = i.RaindropEnabled
  206. integration.RaindropToken = i.RaindropToken
  207. integration.RaindropCollectionID = i.RaindropCollectionID
  208. integration.RaindropTags = i.RaindropTags
  209. integration.BetulaEnabled = i.BetulaEnabled
  210. integration.BetulaURL = i.BetulaURL
  211. integration.BetulaToken = i.BetulaToken
  212. integration.NtfyEnabled = i.NtfyEnabled
  213. integration.NtfyTopic = i.NtfyTopic
  214. integration.NtfyURL = i.NtfyURL
  215. integration.NtfyAPIToken = i.NtfyAPIToken
  216. integration.NtfyUsername = i.NtfyUsername
  217. integration.NtfyPassword = i.NtfyPassword
  218. integration.NtfyIconURL = i.NtfyIconURL
  219. integration.NtfyInternalLinks = i.NtfyInternalLinks
  220. integration.CuboxEnabled = i.CuboxEnabled
  221. integration.CuboxAPILink = i.CuboxAPILink
  222. integration.DiscordEnabled = i.DiscordEnabled
  223. integration.DiscordWebhookLink = i.DiscordWebhookLink
  224. integration.SlackEnabled = i.SlackEnabled
  225. integration.SlackWebhookLink = i.SlackWebhookLink
  226. integration.PushoverEnabled = i.PushoverEnabled
  227. integration.PushoverUser = i.PushoverUser
  228. integration.PushoverToken = i.PushoverToken
  229. integration.PushoverDevice = i.PushoverDevice
  230. integration.PushoverPrefix = i.PushoverPrefix
  231. }
  232. // NewIntegrationForm returns a new IntegrationForm.
  233. func NewIntegrationForm(r *http.Request) *IntegrationForm {
  234. return &IntegrationForm{
  235. PinboardEnabled: r.FormValue("pinboard_enabled") == "1",
  236. PinboardToken: r.FormValue("pinboard_token"),
  237. PinboardTags: r.FormValue("pinboard_tags"),
  238. PinboardMarkAsUnread: r.FormValue("pinboard_mark_as_unread") == "1",
  239. InstapaperEnabled: r.FormValue("instapaper_enabled") == "1",
  240. InstapaperUsername: r.FormValue("instapaper_username"),
  241. InstapaperPassword: r.FormValue("instapaper_password"),
  242. FeverEnabled: r.FormValue("fever_enabled") == "1",
  243. FeverUsername: r.FormValue("fever_username"),
  244. FeverPassword: r.FormValue("fever_password"),
  245. GoogleReaderEnabled: r.FormValue("googlereader_enabled") == "1",
  246. GoogleReaderUsername: r.FormValue("googlereader_username"),
  247. GoogleReaderPassword: r.FormValue("googlereader_password"),
  248. WallabagEnabled: r.FormValue("wallabag_enabled") == "1",
  249. WallabagOnlyURL: r.FormValue("wallabag_only_url") == "1",
  250. WallabagURL: r.FormValue("wallabag_url"),
  251. WallabagClientID: r.FormValue("wallabag_client_id"),
  252. WallabagClientSecret: r.FormValue("wallabag_client_secret"),
  253. WallabagUsername: r.FormValue("wallabag_username"),
  254. WallabagPassword: r.FormValue("wallabag_password"),
  255. NotionEnabled: r.FormValue("notion_enabled") == "1",
  256. NotionPageID: r.FormValue("notion_page_id"),
  257. NotionToken: r.FormValue("notion_token"),
  258. NunuxKeeperEnabled: r.FormValue("nunux_keeper_enabled") == "1",
  259. NunuxKeeperURL: r.FormValue("nunux_keeper_url"),
  260. NunuxKeeperAPIKey: r.FormValue("nunux_keeper_api_key"),
  261. EspialEnabled: r.FormValue("espial_enabled") == "1",
  262. EspialURL: r.FormValue("espial_url"),
  263. EspialAPIKey: r.FormValue("espial_api_key"),
  264. EspialTags: r.FormValue("espial_tags"),
  265. ReadwiseEnabled: r.FormValue("readwise_enabled") == "1",
  266. ReadwiseAPIKey: r.FormValue("readwise_api_key"),
  267. PocketEnabled: r.FormValue("pocket_enabled") == "1",
  268. PocketAccessToken: r.FormValue("pocket_access_token"),
  269. PocketConsumerKey: r.FormValue("pocket_consumer_key"),
  270. TelegramBotEnabled: r.FormValue("telegram_bot_enabled") == "1",
  271. TelegramBotToken: r.FormValue("telegram_bot_token"),
  272. TelegramBotChatID: r.FormValue("telegram_bot_chat_id"),
  273. TelegramBotTopicID: optionalInt64Field(r.FormValue("telegram_bot_topic_id")),
  274. TelegramBotDisableWebPagePreview: r.FormValue("telegram_bot_disable_web_page_preview") == "1",
  275. TelegramBotDisableNotification: r.FormValue("telegram_bot_disable_notification") == "1",
  276. TelegramBotDisableButtons: r.FormValue("telegram_bot_disable_buttons") == "1",
  277. LinkAceEnabled: r.FormValue("linkace_enabled") == "1",
  278. LinkAceURL: r.FormValue("linkace_url"),
  279. LinkAceAPIKey: r.FormValue("linkace_api_key"),
  280. LinkAceTags: r.FormValue("linkace_tags"),
  281. LinkAcePrivate: r.FormValue("linkace_is_private") == "1",
  282. LinkAceCheckDisabled: r.FormValue("linkace_check_disabled") == "1",
  283. LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
  284. LinkdingURL: r.FormValue("linkding_url"),
  285. LinkdingAPIKey: r.FormValue("linkding_api_key"),
  286. LinkdingTags: r.FormValue("linkding_tags"),
  287. LinkdingMarkAsUnread: r.FormValue("linkding_mark_as_unread") == "1",
  288. LinkwardenEnabled: r.FormValue("linkwarden_enabled") == "1",
  289. LinkwardenURL: r.FormValue("linkwarden_url"),
  290. LinkwardenAPIKey: r.FormValue("linkwarden_api_key"),
  291. MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
  292. MatrixBotUser: r.FormValue("matrix_bot_user"),
  293. MatrixBotPassword: r.FormValue("matrix_bot_password"),
  294. MatrixBotURL: r.FormValue("matrix_bot_url"),
  295. MatrixBotChatID: r.FormValue("matrix_bot_chat_id"),
  296. AppriseEnabled: r.FormValue("apprise_enabled") == "1",
  297. AppriseURL: r.FormValue("apprise_url"),
  298. AppriseServicesURL: r.FormValue("apprise_services_url"),
  299. ReadeckEnabled: r.FormValue("readeck_enabled") == "1",
  300. ReadeckURL: r.FormValue("readeck_url"),
  301. ReadeckAPIKey: r.FormValue("readeck_api_key"),
  302. ReadeckLabels: r.FormValue("readeck_labels"),
  303. ReadeckOnlyURL: r.FormValue("readeck_only_url") == "1",
  304. ShioriEnabled: r.FormValue("shiori_enabled") == "1",
  305. ShioriURL: r.FormValue("shiori_url"),
  306. ShioriUsername: r.FormValue("shiori_username"),
  307. ShioriPassword: r.FormValue("shiori_password"),
  308. ShaarliEnabled: r.FormValue("shaarli_enabled") == "1",
  309. ShaarliURL: r.FormValue("shaarli_url"),
  310. ShaarliAPISecret: r.FormValue("shaarli_api_secret"),
  311. WebhookEnabled: r.FormValue("webhook_enabled") == "1",
  312. WebhookURL: r.FormValue("webhook_url"),
  313. RSSBridgeEnabled: r.FormValue("rssbridge_enabled") == "1",
  314. RSSBridgeURL: r.FormValue("rssbridge_url"),
  315. OmnivoreEnabled: r.FormValue("omnivore_enabled") == "1",
  316. OmnivoreAPIKey: r.FormValue("omnivore_api_key"),
  317. OmnivoreURL: r.FormValue("omnivore_url"),
  318. RaindropEnabled: r.FormValue("raindrop_enabled") == "1",
  319. RaindropToken: r.FormValue("raindrop_token"),
  320. RaindropCollectionID: r.FormValue("raindrop_collection_id"),
  321. RaindropTags: r.FormValue("raindrop_tags"),
  322. BetulaEnabled: r.FormValue("betula_enabled") == "1",
  323. BetulaURL: r.FormValue("betula_url"),
  324. BetulaToken: r.FormValue("betula_token"),
  325. NtfyEnabled: r.FormValue("ntfy_enabled") == "1",
  326. NtfyTopic: r.FormValue("ntfy_topic"),
  327. NtfyURL: r.FormValue("ntfy_url"),
  328. NtfyAPIToken: r.FormValue("ntfy_api_token"),
  329. NtfyUsername: r.FormValue("ntfy_username"),
  330. NtfyPassword: r.FormValue("ntfy_password"),
  331. NtfyIconURL: r.FormValue("ntfy_icon_url"),
  332. NtfyInternalLinks: r.FormValue("ntfy_internal_links") == "1",
  333. CuboxEnabled: r.FormValue("cubox_enabled") == "1",
  334. CuboxAPILink: r.FormValue("cubox_api_link"),
  335. DiscordEnabled: r.FormValue("discord_enabled") == "1",
  336. DiscordWebhookLink: r.FormValue("discord_webhook_link"),
  337. SlackEnabled: r.FormValue("slack_enabled") == "1",
  338. SlackWebhookLink: r.FormValue("slack_webhook_link"),
  339. PushoverEnabled: r.FormValue("pushover_enabled") == "1",
  340. PushoverUser: r.FormValue("pushover_user"),
  341. PushoverToken: r.FormValue("pushover_token"),
  342. PushoverDevice: r.FormValue("pushover_device"),
  343. PushoverPrefix: r.FormValue("pushover_prefix"),
  344. }
  345. }
  346. func optionalInt64Field(formValue string) *int64 {
  347. if formValue == "" {
  348. return nil
  349. }
  350. value, _ := strconv.ParseInt(formValue, 10, 64)
  351. return &value
  352. }