model.go 12 KB

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