integration.go 18 KB

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