model.go 9.3 KB

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