model.go 8.4 KB

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