model.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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="%s", URL="%s", Type="%s"`, 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. }
  129. // FeedCreationRequest represents the request to create a feed.
  130. type FeedCreationRequest struct {
  131. FeedURL string `json:"feed_url"`
  132. CategoryID int64 `json:"category_id"`
  133. UserAgent string `json:"user_agent"`
  134. Cookie string `json:"cookie"`
  135. Username string `json:"username"`
  136. Password string `json:"password"`
  137. Crawler bool `json:"crawler"`
  138. Disabled bool `json:"disabled"`
  139. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  140. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  141. FetchViaProxy bool `json:"fetch_via_proxy"`
  142. ScraperRules string `json:"scraper_rules"`
  143. RewriteRules string `json:"rewrite_rules"`
  144. BlocklistRules string `json:"blocklist_rules"`
  145. KeeplistRules string `json:"keeplist_rules"`
  146. HideGlobally bool `json:"hide_globally"`
  147. }
  148. // FeedModificationRequest represents the request to update a feed.
  149. type FeedModificationRequest struct {
  150. FeedURL *string `json:"feed_url"`
  151. SiteURL *string `json:"site_url"`
  152. Title *string `json:"title"`
  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. Crawler *bool `json:"crawler"`
  158. UserAgent *string `json:"user_agent"`
  159. Cookie *string `json:"cookie"`
  160. Username *string `json:"username"`
  161. Password *string `json:"password"`
  162. CategoryID *int64 `json:"category_id"`
  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. HideGlobally *bool `json:"hide_globally"`
  168. }
  169. // FeedIcon represents the feed icon.
  170. type FeedIcon struct {
  171. ID int64 `json:"id"`
  172. MimeType string `json:"mime_type"`
  173. Data string `json:"data"`
  174. }
  175. type FeedCounters struct {
  176. ReadCounters map[int64]int `json:"reads"`
  177. UnreadCounters map[int64]int `json:"unreads"`
  178. }
  179. // Feeds represents a list of feeds.
  180. type Feeds []*Feed
  181. // Entry represents a subscription item in the system.
  182. type Entry struct {
  183. ID int64 `json:"id"`
  184. UserID int64 `json:"user_id"`
  185. FeedID int64 `json:"feed_id"`
  186. Status string `json:"status"`
  187. Hash string `json:"hash"`
  188. Title string `json:"title"`
  189. URL string `json:"url"`
  190. CommentsURL string `json:"comments_url"`
  191. Date time.Time `json:"published_at"`
  192. CreatedAt time.Time `json:"created_at"`
  193. ChangedAt time.Time `json:"changed_at"`
  194. Content string `json:"content"`
  195. Author string `json:"author"`
  196. ShareCode string `json:"share_code"`
  197. Starred bool `json:"starred"`
  198. ReadingTime int `json:"reading_time"`
  199. Enclosures Enclosures `json:"enclosures,omitempty"`
  200. Feed *Feed `json:"feed,omitempty"`
  201. Tags []string `json:"tags"`
  202. }
  203. // Entries represents a list of entries.
  204. type Entries []*Entry
  205. // Enclosure represents an attachment.
  206. type Enclosure struct {
  207. ID int64 `json:"id"`
  208. UserID int64 `json:"user_id"`
  209. EntryID int64 `json:"entry_id"`
  210. URL string `json:"url"`
  211. MimeType string `json:"mime_type"`
  212. Size int `json:"size"`
  213. }
  214. // Enclosures represents a list of attachments.
  215. type Enclosures []*Enclosure
  216. const (
  217. FilterNotStarred = "0"
  218. FilterOnlyStarred = "1"
  219. )
  220. // Filter is used to filter entries.
  221. type Filter struct {
  222. Status string
  223. Offset int
  224. Limit int
  225. Order string
  226. Direction string
  227. Starred string
  228. Before int64
  229. After int64
  230. PublishedBefore int64
  231. PublishedAfter int64
  232. ChangedBefore int64
  233. ChangedAfter int64
  234. BeforeEntryID int64
  235. AfterEntryID int64
  236. Search string
  237. CategoryID int64
  238. FeedID int64
  239. Statuses []string
  240. }
  241. // EntryResultSet represents the response when fetching entries.
  242. type EntryResultSet struct {
  243. Total int `json:"total"`
  244. Entries Entries `json:"entries"`
  245. }