integration.go 11 KB

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