4
0

integration.go 15 KB

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