core.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. FetchViaProxy bool `json:"fetch_via_proxy"`
  101. ScraperRules string `json:"scraper_rules"`
  102. RewriteRules string `json:"rewrite_rules"`
  103. BlocklistRules string `json:"blocklist_rules"`
  104. KeeplistRules string `json:"keeplist_rules"`
  105. Crawler bool `json:"crawler"`
  106. UserAgent string `json:"user_agent"`
  107. Username string `json:"username"`
  108. Password string `json:"password"`
  109. Category *Category `json:"category,omitempty"`
  110. }
  111. // FeedCreationRequest represents the request to create a feed.
  112. type FeedCreationRequest struct {
  113. FeedURL string `json:"feed_url"`
  114. CategoryID int64 `json:"category_id"`
  115. UserAgent string `json:"user_agent"`
  116. Username string `json:"username"`
  117. Password string `json:"password"`
  118. Crawler bool `json:"crawler"`
  119. Disabled bool `json:"disabled"`
  120. IgnoreHTTPCache bool `json:"ignore_http_cache"`
  121. FetchViaProxy bool `json:"fetch_via_proxy"`
  122. ScraperRules string `json:"scraper_rules"`
  123. RewriteRules string `json:"rewrite_rules"`
  124. BlocklistRules string `json:"blocklist_rules"`
  125. KeeplistRules string `json:"keeplist_rules"`
  126. }
  127. // FeedModificationRequest represents the request to update a feed.
  128. type FeedModificationRequest struct {
  129. FeedURL *string `json:"feed_url"`
  130. SiteURL *string `json:"site_url"`
  131. Title *string `json:"title"`
  132. ScraperRules *string `json:"scraper_rules"`
  133. RewriteRules *string `json:"rewrite_rules"`
  134. BlocklistRules *string `json:"blocklist_rules"`
  135. KeeplistRules *string `json:"keeplist_rules"`
  136. Crawler *bool `json:"crawler"`
  137. UserAgent *string `json:"user_agent"`
  138. Username *string `json:"username"`
  139. Password *string `json:"password"`
  140. CategoryID *int64 `json:"category_id"`
  141. Disabled *bool `json:"disabled"`
  142. IgnoreHTTPCache *bool `json:"ignore_http_cache"`
  143. FetchViaProxy *bool `json:"fetch_via_proxy"`
  144. }
  145. // FeedIcon represents the feed icon.
  146. type FeedIcon struct {
  147. ID int64 `json:"id"`
  148. MimeType string `json:"mime_type"`
  149. Data string `json:"data"`
  150. }
  151. // Feeds represents a list of feeds.
  152. type Feeds []*Feed
  153. // Entry represents a subscription item in the system.
  154. type Entry struct {
  155. ID int64 `json:"id"`
  156. UserID int64 `json:"user_id"`
  157. FeedID int64 `json:"feed_id"`
  158. Status string `json:"status"`
  159. Hash string `json:"hash"`
  160. Title string `json:"title"`
  161. URL string `json:"url"`
  162. Date time.Time `json:"published_at"`
  163. CreatedAt time.Time `json:"created_at"`
  164. Content string `json:"content"`
  165. Author string `json:"author"`
  166. ShareCode string `json:"share_code"`
  167. Starred bool `json:"starred"`
  168. ReadingTime int `json:"reading_time"`
  169. Enclosures Enclosures `json:"enclosures,omitempty"`
  170. Feed *Feed `json:"feed,omitempty"`
  171. }
  172. // Entries represents a list of entries.
  173. type Entries []*Entry
  174. // Enclosure represents an attachment.
  175. type Enclosure struct {
  176. ID int64 `json:"id"`
  177. UserID int64 `json:"user_id"`
  178. EntryID int64 `json:"entry_id"`
  179. URL string `json:"url"`
  180. MimeType string `json:"mime_type"`
  181. Size int `json:"size"`
  182. }
  183. // Enclosures represents a list of attachments.
  184. type Enclosures []*Enclosure
  185. // Filter is used to filter entries.
  186. type Filter struct {
  187. Status string
  188. Offset int
  189. Limit int
  190. Order string
  191. Direction string
  192. Starred bool
  193. Before int64
  194. After int64
  195. BeforeEntryID int64
  196. AfterEntryID int64
  197. Search string
  198. CategoryID int64
  199. FeedID int64
  200. Statuses []string
  201. }
  202. // EntryResultSet represents the response when fetching entries.
  203. type EntryResultSet struct {
  204. Total int `json:"total"`
  205. Entries Entries `json:"entries"`
  206. }