model.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package client // import "miniflux.app/v2/client"
  4. import (
  5. "fmt"
  6. "time"
  7. )
  8. // Entry statuses.
  9. const (
  10. EntryStatusUnread = "unread"
  11. EntryStatusRead = "read"
  12. )
  13. // User represents a user in the system.
  14. type User struct {
  15. ID int64 `json:"id"`
  16. Username string `json:"username"`
  17. Password string `json:"password,omitempty"`
  18. IsAdmin bool `json:"is_admin"`
  19. Theme string `json:"theme"`
  20. Language string `json:"language"`
  21. Timezone string `json:"timezone"`
  22. EntryDirection string `json:"entry_sorting_direction"`
  23. EntryOrder string `json:"entry_sorting_order"`
  24. Stylesheet string `json:"stylesheet"`
  25. CustomJS string `json:"custom_js"`
  26. GoogleID string `json:"google_id"`
  27. OpenIDConnectID string `json:"openid_connect_id"`
  28. EntriesPerPage int `json:"entries_per_page"`
  29. KeyboardShortcuts bool `json:"keyboard_shortcuts"`
  30. ShowReadingTime bool `json:"show_reading_time"`
  31. EntrySwipe bool `json:"entry_swipe"`
  32. GestureNav string `json:"gesture_nav"`
  33. LastLoginAt *time.Time `json:"last_login_at"`
  34. DisplayMode string `json:"display_mode"`
  35. DefaultReadingSpeed int `json:"default_reading_speed"`
  36. CJKReadingSpeed int `json:"cjk_reading_speed"`
  37. DefaultHomePage string `json:"default_home_page"`
  38. CategoriesSortingOrder string `json:"categories_sorting_order"`
  39. MarkReadOnView bool `json:"mark_read_on_view"`
  40. MediaPlaybackRate float64 `json:"media_playback_rate"`
  41. BlockFilterEntryRules string `json:"block_filter_entry_rules"`
  42. KeepFilterEntryRules string `json:"keep_filter_entry_rules"`
  43. ExternalFontHosts string `json:"external_font_hosts"`
  44. AlwaysOpenExternalLinks bool `json:"always_open_external_links"`
  45. OpenExternalLinksInNewTab bool `json:"open_external_links_in_new_tab"`
  46. }
  47. func (u User) String() string {
  48. return fmt.Sprintf("#%d - %s (admin=%v)", u.ID, u.Username, u.IsAdmin)
  49. }
  50. // UserCreationRequest represents the request to create a user.
  51. type UserCreationRequest struct {
  52. Username string `json:"username"`
  53. Password string `json:"password"`
  54. IsAdmin bool `json:"is_admin"`
  55. GoogleID string `json:"google_id"`
  56. OpenIDConnectID string `json:"openid_connect_id"`
  57. }
  58. // UserModificationRequest represents the request to update a user.
  59. type UserModificationRequest struct {
  60. Username *string `json:"username"`
  61. Password *string `json:"password"`
  62. IsAdmin *bool `json:"is_admin"`
  63. Theme *string `json:"theme"`
  64. Language *string `json:"language"`
  65. Timezone *string `json:"timezone"`
  66. EntryDirection *string `json:"entry_sorting_direction"`
  67. EntryOrder *string `json:"entry_sorting_order"`
  68. Stylesheet *string `json:"stylesheet"`
  69. CustomJS *string `json:"custom_js"`
  70. EntriesPerPage *int `json:"entries_per_page"`
  71. KeyboardShortcuts *bool `json:"keyboard_shortcuts"`
  72. ShowReadingTime *bool `json:"show_reading_time"`
  73. EntrySwipe *bool `json:"entry_swipe"`
  74. GestureNav *string `json:"gesture_nav"`
  75. DisplayMode *string `json:"display_mode"`
  76. DefaultReadingSpeed *int `json:"default_reading_speed"`
  77. CJKReadingSpeed *int `json:"cjk_reading_speed"`
  78. DefaultHomePage *string `json:"default_home_page"`
  79. CategoriesSortingOrder *string `json:"categories_sorting_order"`
  80. MarkReadOnView *bool `json:"mark_read_on_view"`
  81. MediaPlaybackRate *float64 `json:"media_playback_rate"`
  82. BlockFilterEntryRules *string `json:"block_filter_entry_rules"`
  83. KeepFilterEntryRules *string `json:"keep_filter_entry_rules"`
  84. ExternalFontHosts *string `json:"external_font_hosts"`
  85. AlwaysOpenExternalLinks *bool `json:"always_open_external_links"`
  86. OpenExternalLinksInNewTab *bool `json:"open_external_links_in_new_tab"`
  87. }
  88. // Users represents a list of users.
  89. type Users []User
  90. // Category represents a feed category.
  91. type Category struct {
  92. ID int64 `json:"id"`
  93. Title string `json:"title"`
  94. UserID int64 `json:"user_id,omitempty"`
  95. HideGlobally bool `json:"hide_globally,omitempty"`
  96. FeedCount *int `json:"feed_count,omitempty"`
  97. TotalUnread *int `json:"total_unread,omitempty"`
  98. }
  99. func (c Category) String() string {
  100. return fmt.Sprintf("#%d %s", c.ID, c.Title)
  101. }
  102. // Categories represents a list of categories.
  103. type Categories []*Category
  104. // CategoryCreationRequest represents the request to create a category.
  105. type CategoryCreationRequest struct {
  106. Title string `json:"title"`
  107. HideGlobally bool `json:"hide_globally"`
  108. }
  109. // CategoryModificationRequest represents the request to update a category.
  110. type CategoryModificationRequest struct {
  111. Title *string `json:"title"`
  112. HideGlobally *bool `json:"hide_globally"`
  113. }
  114. // Subscription represents a feed subscription.
  115. type Subscription struct {
  116. Title string `json:"title"`
  117. URL string `json:"url"`
  118. Type string `json:"type"`
  119. }
  120. func (s Subscription) String() string {
  121. return fmt.Sprintf(`Title=%q, URL=%q, Type=%q`, s.Title, s.URL, s.Type)
  122. }
  123. // Subscriptions represents a list of subscriptions.
  124. type Subscriptions []*Subscription
  125. // Feed represents a Miniflux feed.
  126. type Feed struct {
  127. ID int64 `json:"id"`
  128. UserID int64 `json:"user_id"`
  129. FeedURL string `json:"feed_url"`
  130. SiteURL string `json:"site_url"`
  131. Title string `json:"title"`
  132. Description string `json:"description"`
  133. Language string `json:"language"`
  134. CheckedAt time.Time `json:"checked_at"`
  135. NextCheckAt time.Time `json:"next_check_at"`
  136. EtagHeader string `json:"etag_header,omitempty"`
  137. LastModifiedHeader string `json:"last_modified_header,omitempty"`
  138. ParsingErrorMsg string `json:"parsing_error_message,omitempty"`
  139. ParsingErrorCount int `json:"parsing_error_count,omitempty"`
  140. Disabled bool `json:"disabled"`
  141. NoMediaPlayer bool `json:"no_media_player"`
  142. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  143. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  144. FetchViaProxy bool `json:"fetch_via_proxy"`
  145. ScraperRules string `json:"scraper_rules"`
  146. RewriteRules string `json:"rewrite_rules"`
  147. UrlRewriteRules string `json:"urlrewrite_rules"`
  148. BlocklistRules string `json:"blocklist_rules"`
  149. KeeplistRules string `json:"keeplist_rules"`
  150. BlockFilterEntryRules string `json:"block_filter_entry_rules"`
  151. KeepFilterEntryRules string `json:"keep_filter_entry_rules"`
  152. Crawler bool `json:"crawler"`
  153. IgnoreEntryUpdates bool `json:"ignore_entry_updates"`
  154. UserAgent string `json:"user_agent"`
  155. Cookie string `json:"cookie"`
  156. Username string `json:"username"`
  157. Password string `json:"password"`
  158. Category *Category `json:"category,omitempty"`
  159. HideGlobally bool `json:"hide_globally"`
  160. DisableHTTP2 bool `json:"disable_http2"`
  161. ProxyURL string `json:"proxy_url"`
  162. AppriseServiceURLs string `json:"apprise_service_urls"`
  163. WebhookURL string `json:"webhook_url"`
  164. NtfyEnabled bool `json:"ntfy_enabled"`
  165. NtfyPriority int `json:"ntfy_priority"`
  166. NtfyTopic string `json:"ntfy_topic"`
  167. PushoverEnabled bool `json:"pushover_enabled"`
  168. PushoverPriority int `json:"pushover_priority"`
  169. Icon *FeedIcon `json:"icon"`
  170. }
  171. // FeedCreationRequest represents the request to create a feed.
  172. type FeedCreationRequest struct {
  173. FeedURL string `json:"feed_url"`
  174. CategoryID int64 `json:"category_id"`
  175. UserAgent string `json:"user_agent"`
  176. Cookie string `json:"cookie"`
  177. Username string `json:"username"`
  178. Password string `json:"password"`
  179. Crawler bool `json:"crawler"`
  180. IgnoreEntryUpdates bool `json:"ignore_entry_updates"`
  181. Disabled bool `json:"disabled"`
  182. NoMediaPlayer bool `json:"no_media_player"`
  183. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  184. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  185. FetchViaProxy bool `json:"fetch_via_proxy"`
  186. ScraperRules string `json:"scraper_rules"`
  187. RewriteRules string `json:"rewrite_rules"`
  188. UrlRewriteRules string `json:"urlrewrite_rules"`
  189. BlocklistRules string `json:"blocklist_rules"`
  190. KeeplistRules string `json:"keeplist_rules"`
  191. BlockFilterEntryRules string `json:"block_filter_entry_rules"`
  192. KeepFilterEntryRules string `json:"keep_filter_entry_rules"`
  193. HideGlobally bool `json:"hide_globally"`
  194. DisableHTTP2 bool `json:"disable_http2"`
  195. ProxyURL string `json:"proxy_url"`
  196. }
  197. // FeedModificationRequest represents the request to update a feed.
  198. type FeedModificationRequest struct {
  199. FeedURL *string `json:"feed_url"`
  200. SiteURL *string `json:"site_url"`
  201. Title *string `json:"title"`
  202. Description *string `json:"description"`
  203. ScraperRules *string `json:"scraper_rules"`
  204. RewriteRules *string `json:"rewrite_rules"`
  205. UrlRewriteRules *string `json:"urlrewrite_rules"`
  206. BlocklistRules *string `json:"blocklist_rules"`
  207. KeeplistRules *string `json:"keeplist_rules"`
  208. BlockFilterEntryRules *string `json:"block_filter_entry_rules"`
  209. KeepFilterEntryRules *string `json:"keep_filter_entry_rules"`
  210. Crawler *bool `json:"crawler"`
  211. IgnoreEntryUpdates *bool `json:"ignore_entry_updates"`
  212. UserAgent *string `json:"user_agent"`
  213. Cookie *string `json:"cookie"`
  214. Username *string `json:"username"`
  215. Password *string `json:"password"`
  216. CategoryID *int64 `json:"category_id"`
  217. Disabled *bool `json:"disabled"`
  218. NoMediaPlayer *bool `json:"no_media_player"`
  219. IgnoreHTTPCache *bool `json:"ignore_http_cache"`
  220. AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"`
  221. FetchViaProxy *bool `json:"fetch_via_proxy"`
  222. HideGlobally *bool `json:"hide_globally"`
  223. DisableHTTP2 *bool `json:"disable_http2"`
  224. ProxyURL *string `json:"proxy_url"`
  225. }
  226. // FeedIcon represents the feed icon.
  227. type FeedIcon struct {
  228. ID int64 `json:"id"`
  229. MimeType string `json:"mime_type"`
  230. Data string `json:"data"`
  231. }
  232. type FeedCounters struct {
  233. ReadCounters map[int64]int `json:"reads"`
  234. UnreadCounters map[int64]int `json:"unreads"`
  235. }
  236. // Feeds represents a list of feeds.
  237. type Feeds []*Feed
  238. // Entry represents a subscription item in the system.
  239. type Entry struct {
  240. ID int64 `json:"id"`
  241. Date time.Time `json:"published_at"`
  242. ChangedAt time.Time `json:"changed_at"`
  243. CreatedAt time.Time `json:"created_at"`
  244. Feed *Feed `json:"feed,omitempty"`
  245. Hash string `json:"hash"`
  246. URL string `json:"url"`
  247. CommentsURL string `json:"comments_url"`
  248. Title string `json:"title"`
  249. Status string `json:"status"`
  250. Content string `json:"content"`
  251. Language string `json:"language"`
  252. Author string `json:"author"`
  253. ShareCode string `json:"share_code"`
  254. Enclosures Enclosures `json:"enclosures,omitempty"`
  255. Tags []string `json:"tags"`
  256. ReadingTime int `json:"reading_time"`
  257. UserID int64 `json:"user_id"`
  258. FeedID int64 `json:"feed_id"`
  259. Starred bool `json:"starred"`
  260. }
  261. // EntryModificationRequest represents a request to modify an entry.
  262. type EntryModificationRequest struct {
  263. Title *string `json:"title"`
  264. Content *string `json:"content"`
  265. }
  266. // Entries represents a list of entries.
  267. type Entries []*Entry
  268. // ShareCodeResponse represents the response of the share entry endpoint.
  269. type ShareCodeResponse struct {
  270. ShareCode string `json:"share_code"`
  271. }
  272. // Enclosure represents an attachment.
  273. type Enclosure struct {
  274. ID int64 `json:"id"`
  275. UserID int64 `json:"user_id"`
  276. EntryID int64 `json:"entry_id"`
  277. URL string `json:"url"`
  278. MimeType string `json:"mime_type"`
  279. Size int `json:"size"`
  280. MediaProgression int64 `json:"media_progression"`
  281. }
  282. type EnclosureUpdateRequest struct {
  283. MediaProgression int64 `json:"media_progression"`
  284. }
  285. // Enclosures represents a list of attachments.
  286. type Enclosures []*Enclosure
  287. const (
  288. FilterNotStarred = "0"
  289. FilterOnlyStarred = "1"
  290. )
  291. // Filter is used to filter entries.
  292. type Filter struct {
  293. Status string
  294. Offset int
  295. Limit int
  296. Order string
  297. Direction string
  298. Starred string
  299. Before int64
  300. After int64
  301. PublishedBefore int64
  302. PublishedAfter int64
  303. ChangedBefore int64
  304. ChangedAfter int64
  305. BeforeEntryID int64
  306. AfterEntryID int64
  307. Search string
  308. CategoryID int64
  309. FeedID int64
  310. Statuses []string
  311. Tags []string
  312. GloballyVisible bool
  313. }
  314. // EntryResultSet represents the response when fetching entries.
  315. type EntryResultSet struct {
  316. Total int `json:"total"`
  317. Entries Entries `json:"entries"`
  318. }
  319. // EntryIDsFilter holds optional filter and pagination parameters for the entry IDs endpoint.
  320. // Before using fields other than Limit, Offset, Starred, and Status, callers must
  321. // confirm that the server supports them. The client does not detect server versions
  322. // or automatically fall back to older API behavior.
  323. // The zero value of each int64 field means unspecified. Non-zero values are sent
  324. // unchanged for server-side validation.
  325. type EntryIDsFilter struct {
  326. Limit int
  327. Offset int
  328. Starred *bool
  329. Status string
  330. Order string
  331. Direction string
  332. FeedID int64
  333. CategoryID int64
  334. Before int64
  335. After int64
  336. PublishedBefore int64
  337. PublishedAfter int64
  338. ChangedBefore int64
  339. ChangedAfter int64
  340. BeforeEntryID int64
  341. AfterEntryID int64
  342. Search string
  343. // Statuses takes precedence over Status when non-empty.
  344. Statuses []string
  345. Tags []string
  346. // GloballyVisible is omitted when nil; otherwise its value is sent explicitly.
  347. GloballyVisible *bool
  348. }
  349. // EntryIDsResultSet represents the response when fetching entry ID lists.
  350. type EntryIDsResultSet struct {
  351. Total int `json:"total"`
  352. EntryIDs []int64 `json:"entry_ids"`
  353. }
  354. // VersionResponse represents the version and the build information of the Miniflux instance.
  355. type VersionResponse struct {
  356. Version string `json:"version"`
  357. Commit string `json:"commit"`
  358. BuildDate string `json:"build_date"`
  359. GoVersion string `json:"go_version"`
  360. Compiler string `json:"compiler"`
  361. Arch string `json:"arch"`
  362. OS string `json:"os"`
  363. }
  364. // APIKey represents an application API key.
  365. type APIKey struct {
  366. ID int64 `json:"id"`
  367. UserID int64 `json:"user_id"`
  368. Token string `json:"token"`
  369. Description string `json:"description"`
  370. LastUsedAt *time.Time `json:"last_used_at"`
  371. CreatedAt time.Time `json:"created_at"`
  372. }
  373. // APIKeys represents a collection of API keys.
  374. type APIKeys []*APIKey
  375. // APIKeyCreationRequest represents the request to create an API key.
  376. type APIKeyCreationRequest struct {
  377. Description string `json:"description"`
  378. }
  379. // SetOptionalField returns a pointer to the given value so optional request fields can be marked as set.
  380. //
  381. //go:fix inline
  382. func SetOptionalField[T any](value T) *T {
  383. return new(value)
  384. }