integration.go 19 KB

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