types.nim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # SPDX-License-Identifier: AGPL-3.0-only
  2. import times, sequtils, options, tables
  3. import prefs_impl
  4. genPrefsType()
  5. type
  6. RateLimitError* = object of CatchableError
  7. InternalError* = object of CatchableError
  8. Api* {.pure.} = enum
  9. userShow
  10. photoRail
  11. timeline
  12. search
  13. tweet
  14. list
  15. listBySlug
  16. listMembers
  17. RateLimit* = object
  18. remaining*: int
  19. reset*: int
  20. Token* = ref object
  21. tok*: string
  22. init*: Time
  23. lastUse*: Time
  24. pending*: int
  25. apis*: Table[Api, RateLimit]
  26. Error* = enum
  27. null = 0
  28. noUserMatches = 17
  29. protectedUser = 22
  30. couldntAuth = 32
  31. doesntExist = 34
  32. userNotFound = 50
  33. suspended = 63
  34. rateLimited = 88
  35. invalidToken = 89
  36. listIdOrSlug = 112
  37. forbidden = 200
  38. badToken = 239
  39. noCsrf = 353
  40. Profile* = object
  41. id*: string
  42. username*: string
  43. fullname*: string
  44. lowername*: string
  45. location*: string
  46. website*: string
  47. bio*: string
  48. userpic*: string
  49. banner*: string
  50. following*: string
  51. followers*: string
  52. tweets*: string
  53. likes*: string
  54. media*: string
  55. verified*: bool
  56. protected*: bool
  57. suspended*: bool
  58. joinDate*: DateTime
  59. VideoType* = enum
  60. m3u8 = "application/x-mpegURL"
  61. mp4 = "video/mp4"
  62. vmap = "video/vmap"
  63. VideoVariant* = object
  64. videoType*: VideoType
  65. url*: string
  66. bitrate*: int
  67. Video* = object
  68. videoId*: string
  69. durationMs*: int
  70. url*: string
  71. thumb*: string
  72. views*: string
  73. available*: bool
  74. reason*: string
  75. title*: string
  76. description*: string
  77. playbackType*: VideoType
  78. variants*: seq[VideoVariant]
  79. QueryKind* = enum
  80. posts, replies, media, users, tweets, userList
  81. Query* = object
  82. kind*: QueryKind
  83. text*: string
  84. filters*: seq[string]
  85. includes*: seq[string]
  86. excludes*: seq[string]
  87. fromUser*: seq[string]
  88. since*: string
  89. until*: string
  90. near*: string
  91. sep*: string
  92. Gif* = object
  93. url*: string
  94. thumb*: string
  95. GalleryPhoto* = object
  96. url*: string
  97. tweetId*: string
  98. color*: string
  99. PhotoRail* = seq[GalleryPhoto]
  100. Poll* = object
  101. options*: seq[string]
  102. values*: seq[int]
  103. votes*: int
  104. leader*: int
  105. status*: string
  106. CardKind* = enum
  107. amplify = "amplify"
  108. app = "app"
  109. appPlayer = "appplayer"
  110. player = "player"
  111. summary = "summary"
  112. summaryLarge = "summary_large_image"
  113. promoWebsite = "promo_website"
  114. promoVideo = "promo_video_website"
  115. promoVideoConvo = "promo_video_convo"
  116. promoImageConvo = "promo_image_convo"
  117. promoImageApp = "promo_image_app"
  118. storeLink = "direct_store_link_app"
  119. liveEvent = "live_event"
  120. broadcast = "broadcast"
  121. periscope = "periscope_broadcast"
  122. unified = "unified_card"
  123. moment = "moment"
  124. messageMe = "message_me"
  125. videoDirectMessage = "video_direct_message"
  126. imageDirectMessage = "image_direct_message"
  127. audiospace = "audiospace"
  128. newsletterPublication = "newsletter_publication"
  129. unknown
  130. Card* = object
  131. kind*: CardKind
  132. id*: string
  133. query*: string
  134. url*: string
  135. title*: string
  136. dest*: string
  137. text*: string
  138. image*: string
  139. video*: Option[Video]
  140. TweetStats* = object
  141. replies*: int
  142. retweets*: int
  143. likes*: int
  144. quotes*: int
  145. Tweet* = ref object
  146. id*: int64
  147. threadId*: int64
  148. replyId*: int64
  149. profile*: Profile
  150. text*: string
  151. time*: DateTime
  152. reply*: seq[string]
  153. pinned*: bool
  154. hasThread*: bool
  155. available*: bool
  156. tombstone*: string
  157. location*: string
  158. stats*: TweetStats
  159. retweet*: Option[Tweet]
  160. attribution*: Option[Profile]
  161. mediaTags*: seq[Profile]
  162. quote*: Option[Tweet]
  163. card*: Option[Card]
  164. poll*: Option[Poll]
  165. gif*: Option[Gif]
  166. video*: Option[Video]
  167. photos*: seq[string]
  168. Result*[T] = object
  169. content*: seq[T]
  170. top*, bottom*: string
  171. beginning*: bool
  172. query*: Query
  173. Chain* = object
  174. content*: seq[Tweet]
  175. more*: int64
  176. cursor*: string
  177. Conversation* = ref object
  178. tweet*: Tweet
  179. before*: Chain
  180. after*: Chain
  181. replies*: Result[Chain]
  182. Timeline* = Result[Tweet]
  183. List* = object
  184. id*: string
  185. name*: string
  186. userId*: string
  187. username*: string
  188. description*: string
  189. members*: int
  190. banner*: string
  191. GlobalObjects* = ref object
  192. tweets*: Table[string, Tweet]
  193. users*: Table[string, Profile]
  194. Config* = ref object
  195. address*: string
  196. port*: int
  197. useHttps*: bool
  198. httpMaxConns*: int
  199. title*: string
  200. hostname*: string
  201. staticDir*: string
  202. hmacKey*: string
  203. base64Media*: bool
  204. minTokens*: int
  205. enableRss*: bool
  206. enableDebug*: bool
  207. proxy*: string
  208. proxyAuth*: string
  209. rssCacheTime*: int
  210. listCacheTime*: int
  211. redisHost*: string
  212. redisPort*: int
  213. redisConns*: int
  214. redisMaxConns*: int
  215. redisPassword*: string
  216. Rss* = object
  217. feed*, cursor*: string
  218. proc contains*(thread: Chain; tweet: Tweet): bool =
  219. thread.content.anyIt(it.id == tweet.id)