integration.go 19 KB

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