model.go 8.8 KB

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