integration.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. LinkdingEnabled bool
  53. LinkdingURL string
  54. LinkdingAPIKey string
  55. LinkdingTags string
  56. LinkdingMarkAsUnread bool
  57. MatrixBotEnabled bool
  58. MatrixBotUser string
  59. MatrixBotPassword string
  60. MatrixBotURL string
  61. MatrixBotChatID string
  62. AppriseEnabled bool
  63. AppriseURL string
  64. AppriseServicesURL string
  65. ShioriEnabled bool
  66. ShioriURL string
  67. ShioriUsername string
  68. ShioriPassword string
  69. ShaarliEnabled bool
  70. ShaarliURL string
  71. ShaarliAPISecret string
  72. WebhookEnabled bool
  73. WebhookURL string
  74. WebhookSecret string
  75. }
  76. // Merge copy form values to the model.
  77. func (i IntegrationForm) Merge(integration *model.Integration) {
  78. integration.PinboardEnabled = i.PinboardEnabled
  79. integration.PinboardToken = i.PinboardToken
  80. integration.PinboardTags = i.PinboardTags
  81. integration.PinboardMarkAsUnread = i.PinboardMarkAsUnread
  82. integration.InstapaperEnabled = i.InstapaperEnabled
  83. integration.InstapaperUsername = i.InstapaperUsername
  84. integration.InstapaperPassword = i.InstapaperPassword
  85. integration.FeverEnabled = i.FeverEnabled
  86. integration.FeverUsername = i.FeverUsername
  87. integration.GoogleReaderEnabled = i.GoogleReaderEnabled
  88. integration.GoogleReaderUsername = i.GoogleReaderUsername
  89. integration.WallabagEnabled = i.WallabagEnabled
  90. integration.WallabagOnlyURL = i.WallabagOnlyURL
  91. integration.WallabagURL = i.WallabagURL
  92. integration.WallabagClientID = i.WallabagClientID
  93. integration.WallabagClientSecret = i.WallabagClientSecret
  94. integration.WallabagUsername = i.WallabagUsername
  95. integration.WallabagPassword = i.WallabagPassword
  96. integration.NotionEnabled = i.NotionEnabled
  97. integration.NotionPageID = i.NotionPageID
  98. integration.NotionToken = i.NotionToken
  99. integration.NunuxKeeperEnabled = i.NunuxKeeperEnabled
  100. integration.NunuxKeeperURL = i.NunuxKeeperURL
  101. integration.NunuxKeeperAPIKey = i.NunuxKeeperAPIKey
  102. integration.EspialEnabled = i.EspialEnabled
  103. integration.EspialURL = i.EspialURL
  104. integration.EspialAPIKey = i.EspialAPIKey
  105. integration.EspialTags = i.EspialTags
  106. integration.ReadwiseEnabled = i.ReadwiseEnabled
  107. integration.ReadwiseAPIKey = i.ReadwiseAPIKey
  108. integration.PocketEnabled = i.PocketEnabled
  109. integration.PocketAccessToken = i.PocketAccessToken
  110. integration.PocketConsumerKey = i.PocketConsumerKey
  111. integration.TelegramBotEnabled = i.TelegramBotEnabled
  112. integration.TelegramBotToken = i.TelegramBotToken
  113. integration.TelegramBotChatID = i.TelegramBotChatID
  114. integration.TelegramBotTopicID = i.TelegramBotTopicID
  115. integration.TelegramBotDisableWebPagePreview = i.TelegramBotDisableWebPagePreview
  116. integration.TelegramBotDisableNotification = i.TelegramBotDisableNotification
  117. integration.LinkdingEnabled = i.LinkdingEnabled
  118. integration.LinkdingURL = i.LinkdingURL
  119. integration.LinkdingAPIKey = i.LinkdingAPIKey
  120. integration.LinkdingTags = i.LinkdingTags
  121. integration.LinkdingMarkAsUnread = i.LinkdingMarkAsUnread
  122. integration.MatrixBotEnabled = i.MatrixBotEnabled
  123. integration.MatrixBotUser = i.MatrixBotUser
  124. integration.MatrixBotPassword = i.MatrixBotPassword
  125. integration.MatrixBotURL = i.MatrixBotURL
  126. integration.MatrixBotChatID = i.MatrixBotChatID
  127. integration.AppriseEnabled = i.AppriseEnabled
  128. integration.AppriseServicesURL = i.AppriseServicesURL
  129. integration.AppriseURL = i.AppriseURL
  130. integration.ShioriEnabled = i.ShioriEnabled
  131. integration.ShioriURL = i.ShioriURL
  132. integration.ShioriUsername = i.ShioriUsername
  133. integration.ShioriPassword = i.ShioriPassword
  134. integration.ShaarliEnabled = i.ShaarliEnabled
  135. integration.ShaarliURL = i.ShaarliURL
  136. integration.ShaarliAPISecret = i.ShaarliAPISecret
  137. integration.WebhookEnabled = i.WebhookEnabled
  138. integration.WebhookURL = i.WebhookURL
  139. }
  140. // NewIntegrationForm returns a new IntegrationForm.
  141. func NewIntegrationForm(r *http.Request) *IntegrationForm {
  142. return &IntegrationForm{
  143. PinboardEnabled: r.FormValue("pinboard_enabled") == "1",
  144. PinboardToken: r.FormValue("pinboard_token"),
  145. PinboardTags: r.FormValue("pinboard_tags"),
  146. PinboardMarkAsUnread: r.FormValue("pinboard_mark_as_unread") == "1",
  147. InstapaperEnabled: r.FormValue("instapaper_enabled") == "1",
  148. InstapaperUsername: r.FormValue("instapaper_username"),
  149. InstapaperPassword: r.FormValue("instapaper_password"),
  150. FeverEnabled: r.FormValue("fever_enabled") == "1",
  151. FeverUsername: r.FormValue("fever_username"),
  152. FeverPassword: r.FormValue("fever_password"),
  153. GoogleReaderEnabled: r.FormValue("googlereader_enabled") == "1",
  154. GoogleReaderUsername: r.FormValue("googlereader_username"),
  155. GoogleReaderPassword: r.FormValue("googlereader_password"),
  156. WallabagEnabled: r.FormValue("wallabag_enabled") == "1",
  157. WallabagOnlyURL: r.FormValue("wallabag_only_url") == "1",
  158. WallabagURL: r.FormValue("wallabag_url"),
  159. WallabagClientID: r.FormValue("wallabag_client_id"),
  160. WallabagClientSecret: r.FormValue("wallabag_client_secret"),
  161. WallabagUsername: r.FormValue("wallabag_username"),
  162. WallabagPassword: r.FormValue("wallabag_password"),
  163. NotionEnabled: r.FormValue("notion_enabled") == "1",
  164. NotionPageID: r.FormValue("notion_page_id"),
  165. NotionToken: r.FormValue("notion_token"),
  166. NunuxKeeperEnabled: r.FormValue("nunux_keeper_enabled") == "1",
  167. NunuxKeeperURL: r.FormValue("nunux_keeper_url"),
  168. NunuxKeeperAPIKey: r.FormValue("nunux_keeper_api_key"),
  169. EspialEnabled: r.FormValue("espial_enabled") == "1",
  170. EspialURL: r.FormValue("espial_url"),
  171. EspialAPIKey: r.FormValue("espial_api_key"),
  172. EspialTags: r.FormValue("espial_tags"),
  173. ReadwiseEnabled: r.FormValue("readwise_enabled") == "1",
  174. ReadwiseAPIKey: r.FormValue("readwise_api_key"),
  175. PocketEnabled: r.FormValue("pocket_enabled") == "1",
  176. PocketAccessToken: r.FormValue("pocket_access_token"),
  177. PocketConsumerKey: r.FormValue("pocket_consumer_key"),
  178. TelegramBotEnabled: r.FormValue("telegram_bot_enabled") == "1",
  179. TelegramBotToken: r.FormValue("telegram_bot_token"),
  180. TelegramBotChatID: r.FormValue("telegram_bot_chat_id"),
  181. TelegramBotTopicID: optionalInt64Field(r.FormValue("telegram_bot_topic_id")),
  182. TelegramBotDisableWebPagePreview: r.FormValue("telegram_bot_disable_web_page_preview") == "1",
  183. TelegramBotDisableNotification: r.FormValue("telegram_bot_disable_notification") == "1",
  184. LinkdingEnabled: r.FormValue("linkding_enabled") == "1",
  185. LinkdingURL: r.FormValue("linkding_url"),
  186. LinkdingAPIKey: r.FormValue("linkding_api_key"),
  187. LinkdingTags: r.FormValue("linkding_tags"),
  188. LinkdingMarkAsUnread: r.FormValue("linkding_mark_as_unread") == "1",
  189. MatrixBotEnabled: r.FormValue("matrix_bot_enabled") == "1",
  190. MatrixBotUser: r.FormValue("matrix_bot_user"),
  191. MatrixBotPassword: r.FormValue("matrix_bot_password"),
  192. MatrixBotURL: r.FormValue("matrix_bot_url"),
  193. MatrixBotChatID: r.FormValue("matrix_bot_chat_id"),
  194. AppriseEnabled: r.FormValue("apprise_enabled") == "1",
  195. AppriseURL: r.FormValue("apprise_url"),
  196. AppriseServicesURL: r.FormValue("apprise_services_url"),
  197. ShioriEnabled: r.FormValue("shiori_enabled") == "1",
  198. ShioriURL: r.FormValue("shiori_url"),
  199. ShioriUsername: r.FormValue("shiori_username"),
  200. ShioriPassword: r.FormValue("shiori_password"),
  201. ShaarliEnabled: r.FormValue("shaarli_enabled") == "1",
  202. ShaarliURL: r.FormValue("shaarli_url"),
  203. ShaarliAPISecret: r.FormValue("shaarli_api_secret"),
  204. WebhookEnabled: r.FormValue("webhook_enabled") == "1",
  205. WebhookURL: r.FormValue("webhook_url"),
  206. }
  207. }
  208. func optionalInt64Field(formValue string) *int64 {
  209. if formValue == "" {
  210. return nil
  211. }
  212. value, _ := strconv.ParseInt(formValue, 10, 64)
  213. return &value
  214. }