model.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. EntryStatusRemoved = "removed"
  13. )
  14. // User represents a user in the system.
  15. type User struct {
  16. ID int64 `json:"id"`
  17. Username string `json:"username"`
  18. Password string `json:"password,omitempty"`
  19. IsAdmin bool `json:"is_admin"`
  20. Theme string `json:"theme"`
  21. Language string `json:"language"`
  22. Timezone string `json:"timezone"`
  23. EntryDirection string `json:"entry_sorting_direction"`
  24. EntryOrder string `json:"entry_sorting_order"`
  25. Stylesheet string `json:"stylesheet"`
  26. CustomJS string `json:"custom_js"`
  27. GoogleID string `json:"google_id"`
  28. OpenIDConnectID string `json:"openid_connect_id"`
  29. EntriesPerPage int `json:"entries_per_page"`
  30. KeyboardShortcuts bool `json:"keyboard_shortcuts"`
  31. ShowReadingTime bool `json:"show_reading_time"`
  32. EntrySwipe bool `json:"entry_swipe"`
  33. GestureNav string `json:"gesture_nav"`
  34. LastLoginAt *time.Time `json:"last_login_at"`
  35. DisplayMode string `json:"display_mode"`
  36. DefaultReadingSpeed int `json:"default_reading_speed"`
  37. CJKReadingSpeed int `json:"cjk_reading_speed"`
  38. DefaultHomePage string `json:"default_home_page"`
  39. CategoriesSortingOrder string `json:"categories_sorting_order"`
  40. MarkReadOnView bool `json:"mark_read_on_view"`
  41. MediaPlaybackRate float64 `json:"media_playback_rate"`
  42. BlockFilterEntryRules string `json:"block_filter_entry_rules"`
  43. KeepFilterEntryRules string `json:"keep_filter_entry_rules"`
  44. ExternalFontHosts string `json:"external_font_hosts"`
  45. }
  46. func (u User) String() string {
  47. return fmt.Sprintf("#%d - %s (admin=%v)", u.ID, u.Username, u.IsAdmin)
  48. }
  49. // UserCreationRequest represents the request to create a user.
  50. type UserCreationRequest struct {
  51. Username string `json:"username"`
  52. Password string `json:"password"`
  53. IsAdmin bool `json:"is_admin"`
  54. GoogleID string `json:"google_id"`
  55. OpenIDConnectID string `json:"openid_connect_id"`
  56. }
  57. // UserModificationRequest represents the request to update a user.
  58. type UserModificationRequest struct {
  59. Username *string `json:"username"`
  60. Password *string `json:"password"`
  61. IsAdmin *bool `json:"is_admin"`
  62. Theme *string `json:"theme"`
  63. Language *string `json:"language"`
  64. Timezone *string `json:"timezone"`
  65. EntryDirection *string `json:"entry_sorting_direction"`
  66. EntryOrder *string `json:"entry_sorting_order"`
  67. Stylesheet *string `json:"stylesheet"`
  68. CustomJS *string `json:"custom_js"`
  69. GoogleID *string `json:"google_id"`
  70. OpenIDConnectID *string `json:"openid_connect_id"`
  71. EntriesPerPage *int `json:"entries_per_page"`
  72. KeyboardShortcuts *bool `json:"keyboard_shortcuts"`
  73. ShowReadingTime *bool `json:"show_reading_time"`
  74. EntrySwipe *bool `json:"entry_swipe"`
  75. GestureNav *string `json:"gesture_nav"`
  76. DisplayMode *string `json:"display_mode"`
  77. DefaultReadingSpeed *int `json:"default_reading_speed"`
  78. CJKReadingSpeed *int `json:"cjk_reading_speed"`
  79. DefaultHomePage *string `json:"default_home_page"`
  80. CategoriesSortingOrder *string `json:"categories_sorting_order"`
  81. MarkReadOnView *bool `json:"mark_read_on_view"`
  82. MediaPlaybackRate *float64 `json:"media_playback_rate"`
  83. BlockFilterEntryRules *string `json:"block_filter_entry_rules"`
  84. KeepFilterEntryRules *string `json:"keep_filter_entry_rules"`
  85. ExternalFontHosts *string `json:"external_font_hosts"`
  86. }
  87. // Users represents a list of users.
  88. type Users []User
  89. // Category represents a feed category.
  90. type Category struct {
  91. ID int64 `json:"id"`
  92. Title string `json:"title"`
  93. UserID int64 `json:"user_id,omitempty"`
  94. HideGlobally bool `json:"hide_globally,omitempty"`
  95. FeedCount *int `json:"feed_count,omitempty"`
  96. TotalUnread *int `json:"total_unread,omitempty"`
  97. }
  98. func (c Category) String() string {
  99. return fmt.Sprintf("#%d %s", c.ID, c.Title)
  100. }
  101. // Categories represents a list of categories.
  102. type Categories []*Category
  103. // CategoryCreationRequest represents the request to create a category.
  104. type CategoryCreationRequest struct {
  105. Title string `json:"title"`
  106. HideGlobally bool `json:"hide_globally"`
  107. }
  108. // CategoryModificationRequest represents the request to update a category.
  109. type CategoryModificationRequest struct {
  110. Title *string `json:"title"`
  111. HideGlobally *bool `json:"hide_globally"`
  112. }
  113. // Subscription represents a feed subscription.
  114. type Subscription struct {
  115. Title string `json:"title"`
  116. URL string `json:"url"`
  117. Type string `json:"type"`
  118. }
  119. func (s Subscription) String() string {
  120. return fmt.Sprintf(`Title=%q, URL=%q, Type=%q`, s.Title, s.URL, s.Type)
  121. }
  122. // Subscriptions represents a list of subscriptions.
  123. type Subscriptions []*Subscription
  124. // Feed represents a Miniflux feed.
  125. type Feed struct {
  126. ID int64 `json:"id"`
  127. UserID int64 `json:"user_id"`
  128. FeedURL string `json:"feed_url"`
  129. SiteURL string `json:"site_url"`
  130. Title string `json:"title"`
  131. CheckedAt time.Time `json:"checked_at,omitempty"`
  132. EtagHeader string `json:"etag_header,omitempty"`
  133. LastModifiedHeader string `json:"last_modified_header,omitempty"`
  134. ParsingErrorMsg string `json:"parsing_error_message,omitempty"`
  135. ParsingErrorCount int `json:"parsing_error_count,omitempty"`
  136. Disabled bool `json:"disabled"`
  137. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  138. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  139. FetchViaProxy bool `json:"fetch_via_proxy"`
  140. ScraperRules string `json:"scraper_rules"`
  141. RewriteRules string `json:"rewrite_rules"`
  142. BlocklistRules string `json:"blocklist_rules"`
  143. KeeplistRules string `json:"keeplist_rules"`
  144. Crawler bool `json:"crawler"`
  145. UserAgent string `json:"user_agent"`
  146. Cookie string `json:"cookie"`
  147. Username string `json:"username"`
  148. Password string `json:"password"`
  149. Category *Category `json:"category,omitempty"`
  150. HideGlobally bool `json:"hide_globally"`
  151. DisableHTTP2 bool `json:"disable_http2"`
  152. ProxyURL string `json:"proxy_url"`
  153. }
  154. // FeedCreationRequest represents the request to create a feed.
  155. type FeedCreationRequest struct {
  156. FeedURL string `json:"feed_url"`
  157. CategoryID int64 `json:"category_id"`
  158. UserAgent string `json:"user_agent"`
  159. Cookie string `json:"cookie"`
  160. Username string `json:"username"`
  161. Password string `json:"password"`
  162. Crawler bool `json:"crawler"`
  163. Disabled bool `json:"disabled"`
  164. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  165. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  166. FetchViaProxy bool `json:"fetch_via_proxy"`
  167. ScraperRules string `json:"scraper_rules"`
  168. RewriteRules string `json:"rewrite_rules"`
  169. BlocklistRules string `json:"blocklist_rules"`
  170. KeeplistRules string `json:"keeplist_rules"`
  171. HideGlobally bool `json:"hide_globally"`
  172. DisableHTTP2 bool `json:"disable_http2"`
  173. ProxyURL string `json:"proxy_url"`
  174. }
  175. // FeedModificationRequest represents the request to update a feed.
  176. type FeedModificationRequest struct {
  177. FeedURL *string `json:"feed_url"`
  178. SiteURL *string `json:"site_url"`
  179. Title *string `json:"title"`
  180. ScraperRules *string `json:"scraper_rules"`
  181. RewriteRules *string `json:"rewrite_rules"`
  182. BlocklistRules *string `json:"blocklist_rules"`
  183. KeeplistRules *string `json:"keeplist_rules"`
  184. Crawler *bool `json:"crawler"`
  185. UserAgent *string `json:"user_agent"`
  186. Cookie *string `json:"cookie"`
  187. Username *string `json:"username"`
  188. Password *string `json:"password"`
  189. CategoryID *int64 `json:"category_id"`
  190. Disabled *bool `json:"disabled"`
  191. IgnoreHTTPCache *bool `json:"ignore_http_cache"`
  192. AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"`
  193. FetchViaProxy *bool `json:"fetch_via_proxy"`
  194. HideGlobally *bool `json:"hide_globally"`
  195. DisableHTTP2 *bool `json:"disable_http2"`
  196. ProxyURL *string `json:"proxy_url"`
  197. }
  198. // FeedIcon represents the feed icon.
  199. type FeedIcon struct {
  200. ID int64 `json:"id"`
  201. MimeType string `json:"mime_type"`
  202. Data string `json:"data"`
  203. }
  204. type FeedCounters struct {
  205. ReadCounters map[int64]int `json:"reads"`
  206. UnreadCounters map[int64]int `json:"unreads"`
  207. }
  208. // Feeds represents a list of feeds.
  209. type Feeds []*Feed
  210. // Entry represents a subscription item in the system.
  211. type Entry struct {
  212. ID int64 `json:"id"`
  213. Date time.Time `json:"published_at"`
  214. ChangedAt time.Time `json:"changed_at"`
  215. CreatedAt time.Time `json:"created_at"`
  216. Feed *Feed `json:"feed,omitempty"`
  217. Hash string `json:"hash"`
  218. URL string `json:"url"`
  219. CommentsURL string `json:"comments_url"`
  220. Title string `json:"title"`
  221. Status string `json:"status"`
  222. Content string `json:"content"`
  223. Author string `json:"author"`
  224. ShareCode string `json:"share_code"`
  225. Enclosures Enclosures `json:"enclosures,omitempty"`
  226. Tags []string `json:"tags"`
  227. ReadingTime int `json:"reading_time"`
  228. UserID int64 `json:"user_id"`
  229. FeedID int64 `json:"feed_id"`
  230. Starred bool `json:"starred"`
  231. }
  232. // EntryModificationRequest represents a request to modify an entry.
  233. type EntryModificationRequest struct {
  234. Title *string `json:"title"`
  235. Content *string `json:"content"`
  236. }
  237. // Entries represents a list of entries.
  238. type Entries []*Entry
  239. // Enclosure represents an attachment.
  240. type Enclosure struct {
  241. ID int64 `json:"id"`
  242. UserID int64 `json:"user_id"`
  243. EntryID int64 `json:"entry_id"`
  244. URL string `json:"url"`
  245. MimeType string `json:"mime_type"`
  246. Size int `json:"size"`
  247. MediaProgression int64 `json:"media_progression"`
  248. }
  249. type EnclosureUpdateRequest struct {
  250. MediaProgression int64 `json:"media_progression"`
  251. }
  252. // Enclosures represents a list of attachments.
  253. type Enclosures []*Enclosure
  254. const (
  255. FilterNotStarred = "0"
  256. FilterOnlyStarred = "1"
  257. )
  258. // Filter is used to filter entries.
  259. type Filter struct {
  260. Status string
  261. Offset int
  262. Limit int
  263. Order string
  264. Direction string
  265. Starred string
  266. Before int64
  267. After int64
  268. PublishedBefore int64
  269. PublishedAfter int64
  270. ChangedBefore int64
  271. ChangedAfter int64
  272. BeforeEntryID int64
  273. AfterEntryID int64
  274. Search string
  275. CategoryID int64
  276. FeedID int64
  277. Statuses []string
  278. GloballyVisible bool
  279. }
  280. // EntryResultSet represents the response when fetching entries.
  281. type EntryResultSet struct {
  282. Total int `json:"total"`
  283. Entries Entries `json:"entries"`
  284. }
  285. // VersionResponse represents the version and the build information of the Miniflux instance.
  286. type VersionResponse struct {
  287. Version string `json:"version"`
  288. Commit string `json:"commit"`
  289. BuildDate string `json:"build_date"`
  290. GoVersion string `json:"go_version"`
  291. Compiler string `json:"compiler"`
  292. Arch string `json:"arch"`
  293. OS string `json:"os"`
  294. }
  295. func SetOptionalField[T any](value T) *T {
  296. return &value
  297. }