integration.go 19 KB

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