model.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. DoubleTap bool `json:"double_tap"`
  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. }
  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. DoubleTap *bool `json:"double_tap"`
  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. }
  76. // Users represents a list of users.
  77. type Users []User
  78. // Category represents a feed category.
  79. type Category struct {
  80. ID int64 `json:"id,omitempty"`
  81. Title string `json:"title,omitempty"`
  82. UserID int64 `json:"user_id,omitempty"`
  83. }
  84. func (c Category) String() string {
  85. return fmt.Sprintf("#%d %s", c.ID, c.Title)
  86. }
  87. // Categories represents a list of categories.
  88. type Categories []*Category
  89. // Subscription represents a feed subscription.
  90. type Subscription struct {
  91. Title string `json:"title"`
  92. URL string `json:"url"`
  93. Type string `json:"type"`
  94. }
  95. func (s Subscription) String() string {
  96. return fmt.Sprintf(`Title="%s", URL="%s", Type="%s"`, s.Title, s.URL, s.Type)
  97. }
  98. // Subscriptions represents a list of subscriptions.
  99. type Subscriptions []*Subscription
  100. // Feed represents a Miniflux feed.
  101. type Feed struct {
  102. ID int64 `json:"id"`
  103. UserID int64 `json:"user_id"`
  104. FeedURL string `json:"feed_url"`
  105. SiteURL string `json:"site_url"`
  106. Title string `json:"title"`
  107. CheckedAt time.Time `json:"checked_at,omitempty"`
  108. EtagHeader string `json:"etag_header,omitempty"`
  109. LastModifiedHeader string `json:"last_modified_header,omitempty"`
  110. ParsingErrorMsg string `json:"parsing_error_message,omitempty"`
  111. ParsingErrorCount int `json:"parsing_error_count,omitempty"`
  112. Disabled bool `json:"disabled"`
  113. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  114. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  115. FetchViaProxy bool `json:"fetch_via_proxy"`
  116. ScraperRules string `json:"scraper_rules"`
  117. RewriteRules string `json:"rewrite_rules"`
  118. BlocklistRules string `json:"blocklist_rules"`
  119. KeeplistRules string `json:"keeplist_rules"`
  120. Crawler bool `json:"crawler"`
  121. UserAgent string `json:"user_agent"`
  122. Cookie string `json:"cookie"`
  123. Username string `json:"username"`
  124. Password string `json:"password"`
  125. Category *Category `json:"category,omitempty"`
  126. HideGlobally bool `json:"hide_globally"`
  127. }
  128. // FeedCreationRequest represents the request to create a feed.
  129. type FeedCreationRequest struct {
  130. FeedURL string `json:"feed_url"`
  131. CategoryID int64 `json:"category_id"`
  132. UserAgent string `json:"user_agent"`
  133. Cookie string `json:"cookie"`
  134. Username string `json:"username"`
  135. Password string `json:"password"`
  136. Crawler bool `json:"crawler"`
  137. Disabled bool `json:"disabled"`
  138. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  139. AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
  140. FetchViaProxy bool `json:"fetch_via_proxy"`
  141. ScraperRules string `json:"scraper_rules"`
  142. RewriteRules string `json:"rewrite_rules"`
  143. BlocklistRules string `json:"blocklist_rules"`
  144. KeeplistRules string `json:"keeplist_rules"`
  145. HideGlobally bool `json:"hide_globally"`
  146. }
  147. // FeedModificationRequest represents the request to update a feed.
  148. type FeedModificationRequest struct {
  149. FeedURL *string `json:"feed_url"`
  150. SiteURL *string `json:"site_url"`
  151. Title *string `json:"title"`
  152. ScraperRules *string `json:"scraper_rules"`
  153. RewriteRules *string `json:"rewrite_rules"`
  154. BlocklistRules *string `json:"blocklist_rules"`
  155. KeeplistRules *string `json:"keeplist_rules"`
  156. Crawler *bool `json:"crawler"`
  157. UserAgent *string `json:"user_agent"`
  158. Cookie *string `json:"cookie"`
  159. Username *string `json:"username"`
  160. Password *string `json:"password"`
  161. CategoryID *int64 `json:"category_id"`
  162. Disabled *bool `json:"disabled"`
  163. IgnoreHTTPCache *bool `json:"ignore_http_cache"`
  164. AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"`
  165. FetchViaProxy *bool `json:"fetch_via_proxy"`
  166. HideGlobally *bool `json:"hide_globally"`
  167. }
  168. // FeedIcon represents the feed icon.
  169. type FeedIcon struct {
  170. ID int64 `json:"id"`
  171. MimeType string `json:"mime_type"`
  172. Data string `json:"data"`
  173. }
  174. type FeedCounters struct {
  175. ReadCounters map[int64]int `json:"reads"`
  176. UnreadCounters map[int64]int `json:"unreads"`
  177. }
  178. // Feeds represents a list of feeds.
  179. type Feeds []*Feed
  180. // Entry represents a subscription item in the system.
  181. type Entry struct {
  182. ID int64 `json:"id"`
  183. UserID int64 `json:"user_id"`
  184. FeedID int64 `json:"feed_id"`
  185. Status string `json:"status"`
  186. Hash string `json:"hash"`
  187. Title string `json:"title"`
  188. URL string `json:"url"`
  189. CommentsURL string `json:"comments_url"`
  190. Date time.Time `json:"published_at"`
  191. CreatedAt time.Time `json:"created_at"`
  192. ChangedAt time.Time `json:"changed_at"`
  193. Content string `json:"content"`
  194. Author string `json:"author"`
  195. ShareCode string `json:"share_code"`
  196. Starred bool `json:"starred"`
  197. ReadingTime int `json:"reading_time"`
  198. Enclosures Enclosures `json:"enclosures,omitempty"`
  199. Feed *Feed `json:"feed,omitempty"`
  200. Tags []string `json:"tags"`
  201. }
  202. // Entries represents a list of entries.
  203. type Entries []*Entry
  204. // Enclosure represents an attachment.
  205. type Enclosure struct {
  206. ID int64 `json:"id"`
  207. UserID int64 `json:"user_id"`
  208. EntryID int64 `json:"entry_id"`
  209. URL string `json:"url"`
  210. MimeType string `json:"mime_type"`
  211. Size int `json:"size"`
  212. }
  213. // Enclosures represents a list of attachments.
  214. type Enclosures []*Enclosure
  215. const (
  216. FilterNotStarred = "0"
  217. FilterOnlyStarred = "1"
  218. )
  219. // Filter is used to filter entries.
  220. type Filter struct {
  221. Status string
  222. Offset int
  223. Limit int
  224. Order string
  225. Direction string
  226. Starred string
  227. Before int64
  228. After int64
  229. BeforeEntryID int64
  230. AfterEntryID int64
  231. Search string
  232. CategoryID int64
  233. FeedID int64
  234. Statuses []string
  235. }
  236. // EntryResultSet represents the response when fetching entries.
  237. type EntryResultSet struct {
  238. Total int `json:"total"`
  239. Entries Entries `json:"entries"`
  240. }