types.nim 4.7 KB

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