model.go 11 KB

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