model.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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,omitempty"`
  92. Title string `json:"title,omitempty"`
  93. UserID int64 `json:"user_id,omitempty"`
  94. }
  95. func (c Category) String() string {
  96. return fmt.Sprintf("#%d %s", c.ID, c.Title)
  97. }
  98. // Categories represents a list of categories.
  99. type Categories []*Category
  100. // Subscription represents a feed subscription.
  101. type Subscription struct {
  102. Title string `json:"title"`
  103. URL string `json:"url"`
  104. Type string `json:"type"`
  105. }
  106. func (s Subscription) String() string {
  107. return fmt.Sprintf(`Title=%q, URL=%q, Type=%q`, s.Title, s.URL, s.Type)
  108. }
  109. // Subscriptions represents a list of subscriptions.
  110. type Subscriptions []*Subscription
  111. // Feed represents a Miniflux feed.
  112. type Feed struct {
  113. ID int64 `json:"id"`
  114. UserID int64 `json:"user_id"`
  115. FeedURL string `json:"feed_url"`
  116. SiteURL string `json:"site_url"`
  117. Title string `json:"title"`
  118. CheckedAt time.Time `json:"checked_at,omitempty"`
  119. EtagHeader string `json:"etag_header,omitempty"`
  120. LastModifiedHeader string `json:"last_modified_header,omitempty"`
  121. ParsingErrorMsg string `json:"parsing_error_message,omitempty"`
  122. ParsingErrorCount int `json:"parsing_error_count,omitempty"`
  123. Disabled bool `json:"disabled"`
  124. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  125. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  126. FetchViaProxy bool `json:"fetch_via_proxy"`
  127. ScraperRules string `json:"scraper_rules"`
  128. RewriteRules string `json:"rewrite_rules"`
  129. BlocklistRules string `json:"blocklist_rules"`
  130. KeeplistRules string `json:"keeplist_rules"`
  131. Crawler bool `json:"crawler"`
  132. UserAgent string `json:"user_agent"`
  133. Cookie string `json:"cookie"`
  134. Username string `json:"username"`
  135. Password string `json:"password"`
  136. Category *Category `json:"category,omitempty"`
  137. HideGlobally bool `json:"hide_globally"`
  138. DisableHTTP2 bool `json:"disable_http2"`
  139. }
  140. // FeedCreationRequest represents the request to create a feed.
  141. type FeedCreationRequest struct {
  142. FeedURL string `json:"feed_url"`
  143. CategoryID int64 `json:"category_id"`
  144. UserAgent string `json:"user_agent"`
  145. Cookie string `json:"cookie"`
  146. Username string `json:"username"`
  147. Password string `json:"password"`
  148. Crawler bool `json:"crawler"`
  149. Disabled bool `json:"disabled"`
  150. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  151. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  152. FetchViaProxy bool `json:"fetch_via_proxy"`
  153. ScraperRules string `json:"scraper_rules"`
  154. RewriteRules string `json:"rewrite_rules"`
  155. BlocklistRules string `json:"blocklist_rules"`
  156. KeeplistRules string `json:"keeplist_rules"`
  157. HideGlobally bool `json:"hide_globally"`
  158. DisableHTTP2 bool `json:"disable_http2"`
  159. }
  160. // FeedModificationRequest represents the request to update a feed.
  161. type FeedModificationRequest struct {
  162. FeedURL *string `json:"feed_url"`
  163. SiteURL *string `json:"site_url"`
  164. Title *string `json:"title"`
  165. ScraperRules *string `json:"scraper_rules"`
  166. RewriteRules *string `json:"rewrite_rules"`
  167. BlocklistRules *string `json:"blocklist_rules"`
  168. KeeplistRules *string `json:"keeplist_rules"`
  169. Crawler *bool `json:"crawler"`
  170. UserAgent *string `json:"user_agent"`
  171. Cookie *string `json:"cookie"`
  172. Username *string `json:"username"`
  173. Password *string `json:"password"`
  174. CategoryID *int64 `json:"category_id"`
  175. Disabled *bool `json:"disabled"`
  176. IgnoreHTTPCache *bool `json:"ignore_http_cache"`
  177. AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"`
  178. FetchViaProxy *bool `json:"fetch_via_proxy"`
  179. HideGlobally *bool `json:"hide_globally"`
  180. DisableHTTP2 *bool `json:"disable_http2"`
  181. }
  182. // FeedIcon represents the feed icon.
  183. type FeedIcon struct {
  184. ID int64 `json:"id"`
  185. MimeType string `json:"mime_type"`
  186. Data string `json:"data"`
  187. }
  188. type FeedCounters struct {
  189. ReadCounters map[int64]int `json:"reads"`
  190. UnreadCounters map[int64]int `json:"unreads"`
  191. }
  192. // Feeds represents a list of feeds.
  193. type Feeds []*Feed
  194. // Entry represents a subscription item in the system.
  195. type Entry struct {
  196. ID int64 `json:"id"`
  197. Date time.Time `json:"published_at"`
  198. ChangedAt time.Time `json:"changed_at"`
  199. CreatedAt time.Time `json:"created_at"`
  200. Feed *Feed `json:"feed,omitempty"`
  201. Hash string `json:"hash"`
  202. URL string `json:"url"`
  203. CommentsURL string `json:"comments_url"`
  204. Title string `json:"title"`
  205. Status string `json:"status"`
  206. Content string `json:"content"`
  207. Author string `json:"author"`
  208. ShareCode string `json:"share_code"`
  209. Enclosures Enclosures `json:"enclosures,omitempty"`
  210. Tags []string `json:"tags"`
  211. ReadingTime int `json:"reading_time"`
  212. UserID int64 `json:"user_id"`
  213. FeedID int64 `json:"feed_id"`
  214. Starred bool `json:"starred"`
  215. }
  216. // EntryModificationRequest represents a request to modify an entry.
  217. type EntryModificationRequest struct {
  218. Title *string `json:"title"`
  219. Content *string `json:"content"`
  220. }
  221. // Entries represents a list of entries.
  222. type Entries []*Entry
  223. // Enclosure represents an attachment.
  224. type Enclosure struct {
  225. ID int64 `json:"id"`
  226. UserID int64 `json:"user_id"`
  227. EntryID int64 `json:"entry_id"`
  228. URL string `json:"url"`
  229. MimeType string `json:"mime_type"`
  230. Size int `json:"size"`
  231. MediaProgression int64 `json:"media_progression"`
  232. }
  233. type EnclosureUpdateRequest struct {
  234. MediaProgression int64 `json:"media_progression"`
  235. }
  236. // Enclosures represents a list of attachments.
  237. type Enclosures []*Enclosure
  238. const (
  239. FilterNotStarred = "0"
  240. FilterOnlyStarred = "1"
  241. )
  242. // Filter is used to filter entries.
  243. type Filter struct {
  244. Status string
  245. Offset int
  246. Limit int
  247. Order string
  248. Direction string
  249. Starred string
  250. Before int64
  251. After int64
  252. PublishedBefore int64
  253. PublishedAfter int64
  254. ChangedBefore int64
  255. ChangedAfter int64
  256. BeforeEntryID int64
  257. AfterEntryID int64
  258. Search string
  259. CategoryID int64
  260. FeedID int64
  261. Statuses []string
  262. GloballyVisible bool
  263. }
  264. // EntryResultSet represents the response when fetching entries.
  265. type EntryResultSet struct {
  266. Total int `json:"total"`
  267. Entries Entries `json:"entries"`
  268. }
  269. // VersionResponse represents the version and the build information of the Miniflux instance.
  270. type VersionResponse struct {
  271. Version string `json:"version"`
  272. Commit string `json:"commit"`
  273. BuildDate string `json:"build_date"`
  274. GoVersion string `json:"go_version"`
  275. Compiler string `json:"compiler"`
  276. Arch string `json:"arch"`
  277. OS string `json:"os"`
  278. }
  279. func SetOptionalField[T any](value T) *T {
  280. return &value
  281. }