model.go 12 KB

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