integration.go 17 KB

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