model.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package client // import "miniflux.app/client"
  5. import (
  6. "fmt"
  7. "time"
  8. )
  9. // Entry statuses.
  10. const (
  11. EntryStatusUnread = "unread"
  12. EntryStatusRead = "read"
  13. EntryStatusRemoved = "removed"
  14. )
  15. // User represents a user in the system.
  16. type User struct {
  17. ID int64 `json:"id"`
  18. Username string `json:"username"`
  19. Password string `json:"password,omitempty"`
  20. IsAdmin bool `json:"is_admin"`
  21. Theme string `json:"theme"`
  22. Language string `json:"language"`
  23. Timezone string `json:"timezone"`
  24. EntryDirection string `json:"entry_sorting_direction"`
  25. EntryOrder string `json:"entry_sorting_order"`
  26. Stylesheet string `json:"stylesheet"`
  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. 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. CategoriesSortOrder string `json:"categories_sort_order"`
  39. }
  40. func (u User) String() string {
  41. return fmt.Sprintf("#%d - %s (admin=%v)", u.ID, u.Username, u.IsAdmin)
  42. }
  43. // UserCreationRequest represents the request to create a user.
  44. type UserCreationRequest struct {
  45. Username string `json:"username"`
  46. Password string `json:"password"`
  47. IsAdmin bool `json:"is_admin"`
  48. GoogleID string `json:"google_id"`
  49. OpenIDConnectID string `json:"openid_connect_id"`
  50. }
  51. // UserModificationRequest represents the request to update a user.
  52. type UserModificationRequest struct {
  53. Username *string `json:"username"`
  54. Password *string `json:"password"`
  55. IsAdmin *bool `json:"is_admin"`
  56. Theme *string `json:"theme"`
  57. Language *string `json:"language"`
  58. Timezone *string `json:"timezone"`
  59. EntryDirection *string `json:"entry_sorting_direction"`
  60. EntryOrder *string `json:"entry_sorting_order"`
  61. Stylesheet *string `json:"stylesheet"`
  62. GoogleID *string `json:"google_id"`
  63. OpenIDConnectID *string `json:"openid_connect_id"`
  64. EntriesPerPage *int `json:"entries_per_page"`
  65. KeyboardShortcuts *bool `json:"keyboard_shortcuts"`
  66. ShowReadingTime *bool `json:"show_reading_time"`
  67. EntrySwipe *bool `json:"entry_swipe"`
  68. DisplayMode *string `json:"display_mode"`
  69. DefaultReadingSpeed *int `json:"default_reading_speed"`
  70. CJKReadingSpeed *int `json:"cjk_reading_speed"`
  71. DefaultHomePage *string `json:"default_home_page"`
  72. CategoriesSortOrder *string `json:"categories_sort_order"`
  73. }
  74. // Users represents a list of users.
  75. type Users []User
  76. // Category represents a feed category.
  77. type Category struct {
  78. ID int64 `json:"id,omitempty"`
  79. Title string `json:"title,omitempty"`
  80. UserID int64 `json:"user_id,omitempty"`
  81. }
  82. func (c Category) String() string {
  83. return fmt.Sprintf("#%d %s", c.ID, c.Title)
  84. }
  85. // Categories represents a list of categories.
  86. type Categories []*Category
  87. // Subscription represents a feed subscription.
  88. type Subscription struct {
  89. Title string `json:"title"`
  90. URL string `json:"url"`
  91. Type string `json:"type"`
  92. }
  93. func (s Subscription) String() string {
  94. return fmt.Sprintf(`Title="%s", URL="%s", Type="%s"`, s.Title, s.URL, s.Type)
  95. }
  96. // Subscriptions represents a list of subscriptions.
  97. type Subscriptions []*Subscription
  98. // Feed represents a Miniflux feed.
  99. type Feed struct {
  100. ID int64 `json:"id"`
  101. UserID int64 `json:"user_id"`
  102. FeedURL string `json:"feed_url"`
  103. SiteURL string `json:"site_url"`
  104. Title string `json:"title"`
  105. CheckedAt time.Time `json:"checked_at,omitempty"`
  106. EtagHeader string `json:"etag_header,omitempty"`
  107. LastModifiedHeader string `json:"last_modified_header,omitempty"`
  108. ParsingErrorMsg string `json:"parsing_error_message,omitempty"`
  109. ParsingErrorCount int `json:"parsing_error_count,omitempty"`
  110. Disabled bool `json:"disabled"`
  111. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  112. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  113. FetchViaProxy bool `json:"fetch_via_proxy"`
  114. ScraperRules string `json:"scraper_rules"`
  115. RewriteRules string `json:"rewrite_rules"`
  116. BlocklistRules string `json:"blocklist_rules"`
  117. KeeplistRules string `json:"keeplist_rules"`
  118. Crawler bool `json:"crawler"`
  119. UserAgent string `json:"user_agent"`
  120. Cookie string `json:"cookie"`
  121. Username string `json:"username"`
  122. Password string `json:"password"`
  123. Category *Category `json:"category,omitempty"`
  124. HideGlobally bool `json:"hide_globally"`
  125. }
  126. // FeedCreationRequest represents the request to create a feed.
  127. type FeedCreationRequest struct {
  128. FeedURL string `json:"feed_url"`
  129. CategoryID int64 `json:"category_id"`
  130. UserAgent string `json:"user_agent"`
  131. Cookie string `json:"cookie"`
  132. Username string `json:"username"`
  133. Password string `json:"password"`
  134. Crawler bool `json:"crawler"`
  135. Disabled bool `json:"disabled"`
  136. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  137. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  138. FetchViaProxy bool `json:"fetch_via_proxy"`
  139. ScraperRules string `json:"scraper_rules"`
  140. RewriteRules string `json:"rewrite_rules"`
  141. BlocklistRules string `json:"blocklist_rules"`
  142. KeeplistRules string `json:"keeplist_rules"`
  143. HideGlobally bool `json:"hide_globally"`
  144. }
  145. // FeedModificationRequest represents the request to update a feed.
  146. type FeedModificationRequest struct {
  147. FeedURL *string `json:"feed_url"`
  148. SiteURL *string `json:"site_url"`
  149. Title *string `json:"title"`
  150. ScraperRules *string `json:"scraper_rules"`
  151. RewriteRules *string `json:"rewrite_rules"`
  152. BlocklistRules *string `json:"blocklist_rules"`
  153. KeeplistRules *string `json:"keeplist_rules"`
  154. Crawler *bool `json:"crawler"`
  155. UserAgent *string `json:"user_agent"`
  156. Cookie *string `json:"cookie"`
  157. Username *string `json:"username"`
  158. Password *string `json:"password"`
  159. CategoryID *int64 `json:"category_id"`
  160. Disabled *bool `json:"disabled"`
  161. IgnoreHTTPCache *bool `json:"ignore_http_cache"`
  162. AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"`
  163. FetchViaProxy *bool `json:"fetch_via_proxy"`
  164. HideGlobally *bool `json:"hide_globally"`
  165. }
  166. // FeedIcon represents the feed icon.
  167. type FeedIcon struct {
  168. ID int64 `json:"id"`
  169. MimeType string `json:"mime_type"`
  170. Data string `json:"data"`
  171. }
  172. type FeedCounters struct {
  173. ReadCounters map[int64]int `json:"reads"`
  174. UnreadCounters map[int64]int `json:"unreads"`
  175. }
  176. // Feeds represents a list of feeds.
  177. type Feeds []*Feed
  178. // Entry represents a subscription item in the system.
  179. type Entry struct {
  180. ID int64 `json:"id"`
  181. UserID int64 `json:"user_id"`
  182. FeedID int64 `json:"feed_id"`
  183. Status string `json:"status"`
  184. Hash string `json:"hash"`
  185. Title string `json:"title"`
  186. URL string `json:"url"`
  187. CommentsURL string `json:"comments_url"`
  188. Date time.Time `json:"published_at"`
  189. CreatedAt time.Time `json:"created_at"`
  190. ChangedAt time.Time `json:"changed_at"`
  191. Content string `json:"content"`
  192. Author string `json:"author"`
  193. ShareCode string `json:"share_code"`
  194. Starred bool `json:"starred"`
  195. ReadingTime int `json:"reading_time"`
  196. Enclosures Enclosures `json:"enclosures,omitempty"`
  197. Feed *Feed `json:"feed,omitempty"`
  198. }
  199. // Entries represents a list of entries.
  200. type Entries []*Entry
  201. // Enclosure represents an attachment.
  202. type Enclosure struct {
  203. ID int64 `json:"id"`
  204. UserID int64 `json:"user_id"`
  205. EntryID int64 `json:"entry_id"`
  206. URL string `json:"url"`
  207. MimeType string `json:"mime_type"`
  208. Size int `json:"size"`
  209. }
  210. // Enclosures represents a list of attachments.
  211. type Enclosures []*Enclosure
  212. const (
  213. FilterNotStarred = "0"
  214. FilterOnlyStarred = "1"
  215. )
  216. // Filter is used to filter entries.
  217. type Filter struct {
  218. Status string
  219. Offset int
  220. Limit int
  221. Order string
  222. Direction string
  223. Starred string
  224. Before int64
  225. After int64
  226. BeforeEntryID int64
  227. AfterEntryID int64
  228. Search string
  229. CategoryID int64
  230. FeedID int64
  231. Statuses []string
  232. }
  233. // EntryResultSet represents the response when fetching entries.
  234. type EntryResultSet struct {
  235. Total int `json:"total"`
  236. Entries Entries `json:"entries"`
  237. }