integration.go 19 KB

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