@ttkit/daily-hot-api 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) hide show
  1. package/.env.example +77 -0
  2. package/LICENSE +21 -0
  3. package/README.md +315 -2
  4. package/bin/daily-hot-api.js +25 -0
  5. package/dist/app.controller.d.ts +41 -0
  6. package/dist/app.controller.js +91 -0
  7. package/dist/app.controller.js.map +1 -0
  8. package/dist/app.module.d.ts +4 -0
  9. package/dist/app.module.js +44 -0
  10. package/dist/app.module.js.map +1 -0
  11. package/dist/app.service.d.ts +19 -0
  12. package/dist/app.service.js +57 -0
  13. package/dist/app.service.js.map +1 -0
  14. package/dist/cache/cache.module.d.ts +2 -0
  15. package/dist/cache/cache.module.js +52 -0
  16. package/dist/cache/cache.module.js.map +1 -0
  17. package/dist/cache/cache.service.d.ts +26 -0
  18. package/dist/cache/cache.service.js +163 -0
  19. package/dist/cache/cache.service.js.map +1 -0
  20. package/dist/cli/args.d.ts +24 -0
  21. package/dist/cli/args.js +261 -0
  22. package/dist/cli/args.js.map +1 -0
  23. package/dist/cli/commands/logs.d.ts +3 -0
  24. package/dist/cli/commands/logs.js +55 -0
  25. package/dist/cli/commands/logs.js.map +1 -0
  26. package/dist/cli/commands/restart.d.ts +3 -0
  27. package/dist/cli/commands/restart.js +62 -0
  28. package/dist/cli/commands/restart.js.map +1 -0
  29. package/dist/cli/commands/start.d.ts +3 -0
  30. package/dist/cli/commands/start.js +280 -0
  31. package/dist/cli/commands/start.js.map +1 -0
  32. package/dist/cli/commands/status.d.ts +3 -0
  33. package/dist/cli/commands/status.js +78 -0
  34. package/dist/cli/commands/status.js.map +1 -0
  35. package/dist/cli/commands/stop.d.ts +12 -0
  36. package/dist/cli/commands/stop.js +135 -0
  37. package/dist/cli/commands/stop.js.map +1 -0
  38. package/dist/cli/context.d.ts +4 -0
  39. package/dist/cli/context.js +3 -0
  40. package/dist/cli/context.js.map +1 -0
  41. package/dist/cli/env.d.ts +2 -0
  42. package/dist/cli/env.js +80 -0
  43. package/dist/cli/env.js.map +1 -0
  44. package/dist/cli/errors.d.ts +14 -0
  45. package/dist/cli/errors.js +25 -0
  46. package/dist/cli/errors.js.map +1 -0
  47. package/dist/cli/health.d.ts +2 -0
  48. package/dist/cli/health.js +44 -0
  49. package/dist/cli/health.js.map +1 -0
  50. package/dist/cli/help.d.ts +3 -0
  51. package/dist/cli/help.js +158 -0
  52. package/dist/cli/help.js.map +1 -0
  53. package/dist/cli/index.d.ts +2 -0
  54. package/dist/cli/index.js +94 -0
  55. package/dist/cli/index.js.map +1 -0
  56. package/dist/cli/log-file.d.ts +8 -0
  57. package/dist/cli/log-file.js +58 -0
  58. package/dist/cli/log-file.js.map +1 -0
  59. package/dist/cli/output.d.ts +7 -0
  60. package/dist/cli/output.js +46 -0
  61. package/dist/cli/output.js.map +1 -0
  62. package/dist/cli/paths.d.ts +33 -0
  63. package/dist/cli/paths.js +76 -0
  64. package/dist/cli/paths.js.map +1 -0
  65. package/dist/cli/run-state.d.ts +25 -0
  66. package/dist/cli/run-state.js +159 -0
  67. package/dist/cli/run-state.js.map +1 -0
  68. package/dist/common/middlewares/logger.middleware.d.ts +7 -0
  69. package/dist/common/middlewares/logger.middleware.js +29 -0
  70. package/dist/common/middlewares/logger.middleware.js.map +1 -0
  71. package/dist/config/config.module.d.ts +2 -0
  72. package/dist/config/config.module.js +47 -0
  73. package/dist/config/config.module.js.map +1 -0
  74. package/dist/config/configuration.d.ts +3 -0
  75. package/dist/config/configuration.js +5 -0
  76. package/dist/config/configuration.js.map +1 -0
  77. package/dist/config/validation.schema.d.ts +114 -0
  78. package/dist/config/validation.schema.js +69 -0
  79. package/dist/config/validation.schema.js.map +1 -0
  80. package/dist/daily-brief/clients/ai-analysis.client.d.ts +20 -0
  81. package/dist/daily-brief/clients/ai-analysis.client.js +217 -0
  82. package/dist/daily-brief/clients/ai-analysis.client.js.map +1 -0
  83. package/dist/daily-brief/clients/brief-search.service.d.ts +11 -0
  84. package/dist/daily-brief/clients/brief-search.service.js +52 -0
  85. package/dist/daily-brief/clients/brief-search.service.js.map +1 -0
  86. package/dist/daily-brief/clients/deepseek-search.client.d.ts +11 -0
  87. package/dist/daily-brief/clients/deepseek-search.client.js +70 -0
  88. package/dist/daily-brief/clients/deepseek-search.client.js.map +1 -0
  89. package/dist/daily-brief/clients/tavily-search.client.d.ts +11 -0
  90. package/dist/daily-brief/clients/tavily-search.client.js +72 -0
  91. package/dist/daily-brief/clients/tavily-search.client.js.map +1 -0
  92. package/dist/daily-brief/daily-brief.config.d.ts +31 -0
  93. package/dist/daily-brief/daily-brief.config.js +108 -0
  94. package/dist/daily-brief/daily-brief.config.js.map +1 -0
  95. package/dist/daily-brief/daily-brief.controller.d.ts +72 -0
  96. package/dist/daily-brief/daily-brief.controller.js +169 -0
  97. package/dist/daily-brief/daily-brief.controller.js.map +1 -0
  98. package/dist/daily-brief/daily-brief.module.d.ts +2 -0
  99. package/dist/daily-brief/daily-brief.module.js +49 -0
  100. package/dist/daily-brief/daily-brief.module.js.map +1 -0
  101. package/dist/daily-brief/daily-brief.scheduler.d.ts +30 -0
  102. package/dist/daily-brief/daily-brief.scheduler.js +113 -0
  103. package/dist/daily-brief/daily-brief.scheduler.js.map +1 -0
  104. package/dist/daily-brief/daily-brief.service.d.ts +101 -0
  105. package/dist/daily-brief/daily-brief.service.js +412 -0
  106. package/dist/daily-brief/daily-brief.service.js.map +1 -0
  107. package/dist/daily-brief/dto/brief-date-param.dto.d.ts +3 -0
  108. package/dist/daily-brief/dto/brief-date-param.dto.js +23 -0
  109. package/dist/daily-brief/dto/brief-date-param.dto.js.map +1 -0
  110. package/dist/daily-brief/dto/generate-brief.dto.d.ts +6 -0
  111. package/dist/daily-brief/dto/generate-brief.dto.js +39 -0
  112. package/dist/daily-brief/dto/generate-brief.dto.js.map +1 -0
  113. package/dist/daily-brief/dto/list-briefs-query.dto.d.ts +6 -0
  114. package/dist/daily-brief/dto/list-briefs-query.dto.js +42 -0
  115. package/dist/daily-brief/dto/list-briefs-query.dto.js.map +1 -0
  116. package/dist/daily-brief/dto/stock-ranking-query.dto.d.ts +6 -0
  117. package/dist/daily-brief/dto/stock-ranking-query.dto.js +46 -0
  118. package/dist/daily-brief/dto/stock-ranking-query.dto.js.map +1 -0
  119. package/dist/daily-brief/interfaces/daily-brief.interface.d.ts +59 -0
  120. package/dist/daily-brief/interfaces/daily-brief.interface.js +3 -0
  121. package/dist/daily-brief/interfaces/daily-brief.interface.js.map +1 -0
  122. package/dist/daily-brief/interfaces/search-provider.interface.d.ts +11 -0
  123. package/dist/daily-brief/interfaces/search-provider.interface.js +3 -0
  124. package/dist/daily-brief/interfaces/search-provider.interface.js.map +1 -0
  125. package/dist/daily-brief/utils/brief-date.d.ts +2 -0
  126. package/dist/daily-brief/utils/brief-date.js +16 -0
  127. package/dist/daily-brief/utils/brief-date.js.map +1 -0
  128. package/dist/daily-brief/utils/concurrency.d.ts +1 -0
  129. package/dist/daily-brief/utils/concurrency.js +20 -0
  130. package/dist/daily-brief/utils/concurrency.js.map +1 -0
  131. package/dist/database/database.module.d.ts +2 -0
  132. package/dist/database/database.module.js +57 -0
  133. package/dist/database/database.module.js.map +1 -0
  134. package/dist/database/repositories/daily-brief.repository.d.ts +96 -0
  135. package/dist/database/repositories/daily-brief.repository.js +457 -0
  136. package/dist/database/repositories/daily-brief.repository.js.map +1 -0
  137. package/dist/database/repositories/hot-item.repository.d.ts +52 -0
  138. package/dist/database/repositories/hot-item.repository.js +255 -0
  139. package/dist/database/repositories/hot-item.repository.js.map +1 -0
  140. package/dist/database/repositories/source-config.repository.d.ts +15 -0
  141. package/dist/database/repositories/source-config.repository.js +77 -0
  142. package/dist/database/repositories/source-config.repository.js.map +1 -0
  143. package/dist/database/schemas/daily-brief.schema.d.ts +30 -0
  144. package/dist/database/schemas/daily-brief.schema.js +103 -0
  145. package/dist/database/schemas/daily-brief.schema.js.map +1 -0
  146. package/dist/database/schemas/hot-item.schema.d.ts +20 -0
  147. package/dist/database/schemas/hot-item.schema.js +72 -0
  148. package/dist/database/schemas/hot-item.schema.js.map +1 -0
  149. package/dist/database/schemas/source-config.schema.d.ts +15 -0
  150. package/dist/database/schemas/source-config.schema.js +47 -0
  151. package/dist/database/schemas/source-config.schema.js.map +1 -0
  152. package/dist/history/dto/history-response.dto.d.ts +17 -0
  153. package/dist/history/dto/history-response.dto.js +13 -0
  154. package/dist/history/dto/history-response.dto.js.map +1 -0
  155. package/dist/history/dto/search-history.dto.d.ts +10 -0
  156. package/dist/history/dto/search-history.dto.js +72 -0
  157. package/dist/history/dto/search-history.dto.js.map +1 -0
  158. package/dist/history/history.controller.d.ts +13 -0
  159. package/dist/history/history.controller.js +92 -0
  160. package/dist/history/history.controller.js.map +1 -0
  161. package/dist/history/history.module.d.ts +2 -0
  162. package/dist/history/history.module.js +25 -0
  163. package/dist/history/history.module.js.map +1 -0
  164. package/dist/history/history.service.d.ts +15 -0
  165. package/dist/history/history.service.js +68 -0
  166. package/dist/history/history.service.js.map +1 -0
  167. package/dist/host-lists/decorators/hot-source.decorator.d.ts +9 -0
  168. package/dist/host-lists/decorators/hot-source.decorator.js +11 -0
  169. package/dist/host-lists/decorators/hot-source.decorator.js.map +1 -0
  170. package/dist/host-lists/dto/hot-list.dto.d.ts +14 -0
  171. package/dist/host-lists/dto/hot-list.dto.js +94 -0
  172. package/dist/host-lists/dto/hot-list.dto.js.map +1 -0
  173. package/dist/host-lists/hot-lists.controller.d.ts +39 -0
  174. package/dist/host-lists/hot-lists.controller.js +87 -0
  175. package/dist/host-lists/hot-lists.controller.js.map +1 -0
  176. package/dist/host-lists/hot-lists.module.d.ts +2 -0
  177. package/dist/host-lists/hot-lists.module.js +36 -0
  178. package/dist/host-lists/hot-lists.module.js.map +1 -0
  179. package/dist/host-lists/hot-lists.service.d.ts +21 -0
  180. package/dist/host-lists/hot-lists.service.js +115 -0
  181. package/dist/host-lists/hot-lists.service.js.map +1 -0
  182. package/dist/host-lists/interfaces/hot-list-source.interface.d.ts +5 -0
  183. package/dist/host-lists/interfaces/hot-list-source.interface.js +3 -0
  184. package/dist/host-lists/interfaces/hot-list-source.interface.js.map +1 -0
  185. package/dist/host-lists/interfaces/hot-list.interface.d.ts +31 -0
  186. package/dist/host-lists/interfaces/hot-list.interface.js +3 -0
  187. package/dist/host-lists/interfaces/hot-list.interface.js.map +1 -0
  188. package/dist/host-lists/interfaces/router-data.interface.d.ts +19 -0
  189. package/dist/host-lists/interfaces/router-data.interface.js +3 -0
  190. package/dist/host-lists/interfaces/router-data.interface.js.map +1 -0
  191. package/dist/host-lists/sources/36kr.source.d.ts +9 -0
  192. package/dist/host-lists/sources/36kr.source.js +89 -0
  193. package/dist/host-lists/sources/36kr.source.js.map +1 -0
  194. package/dist/host-lists/sources/51cto.source.d.ts +11 -0
  195. package/dist/host-lists/sources/51cto.source.js +71 -0
  196. package/dist/host-lists/sources/51cto.source.js.map +1 -0
  197. package/dist/host-lists/sources/52pojie.source.d.ts +9 -0
  198. package/dist/host-lists/sources/52pojie.source.js +109 -0
  199. package/dist/host-lists/sources/52pojie.source.js.map +1 -0
  200. package/dist/host-lists/sources/acfun.source.d.ts +9 -0
  201. package/dist/host-lists/sources/acfun.source.js +90 -0
  202. package/dist/host-lists/sources/acfun.source.js.map +1 -0
  203. package/dist/host-lists/sources/baidu.source.d.ts +9 -0
  204. package/dist/host-lists/sources/baidu.source.js +85 -0
  205. package/dist/host-lists/sources/baidu.source.js.map +1 -0
  206. package/dist/host-lists/sources/bilibili.source.d.ts +14 -0
  207. package/dist/host-lists/sources/bilibili.source.js +188 -0
  208. package/dist/host-lists/sources/bilibili.source.js.map +1 -0
  209. package/dist/host-lists/sources/caixin.source.d.ts +9 -0
  210. package/dist/host-lists/sources/caixin.source.js +102 -0
  211. package/dist/host-lists/sources/caixin.source.js.map +1 -0
  212. package/dist/host-lists/sources/cls.source.d.ts +9 -0
  213. package/dist/host-lists/sources/cls.source.js +62 -0
  214. package/dist/host-lists/sources/cls.source.js.map +1 -0
  215. package/dist/host-lists/sources/coolapk.source.d.ts +9 -0
  216. package/dist/host-lists/sources/coolapk.source.js +57 -0
  217. package/dist/host-lists/sources/coolapk.source.js.map +1 -0
  218. package/dist/host-lists/sources/csdn.source.d.ts +9 -0
  219. package/dist/host-lists/sources/csdn.source.js +59 -0
  220. package/dist/host-lists/sources/csdn.source.js.map +1 -0
  221. package/dist/host-lists/sources/dgtle.source.d.ts +9 -0
  222. package/dist/host-lists/sources/dgtle.source.js +57 -0
  223. package/dist/host-lists/sources/dgtle.source.js.map +1 -0
  224. package/dist/host-lists/sources/douban-group.source.d.ts +11 -0
  225. package/dist/host-lists/sources/douban-group.source.js +100 -0
  226. package/dist/host-lists/sources/douban-group.source.js.map +1 -0
  227. package/dist/host-lists/sources/douban-movie.source.d.ts +10 -0
  228. package/dist/host-lists/sources/douban-movie.source.js +103 -0
  229. package/dist/host-lists/sources/douban-movie.source.js.map +1 -0
  230. package/dist/host-lists/sources/douyin.d.ts +16 -0
  231. package/dist/host-lists/sources/douyin.js +215 -0
  232. package/dist/host-lists/sources/douyin.js.map +1 -0
  233. package/dist/host-lists/sources/eastmoney-stock.source.d.ts +11 -0
  234. package/dist/host-lists/sources/eastmoney-stock.source.js +151 -0
  235. package/dist/host-lists/sources/eastmoney-stock.source.js.map +1 -0
  236. package/dist/host-lists/sources/eastmoney.source.d.ts +9 -0
  237. package/dist/host-lists/sources/eastmoney.source.js +86 -0
  238. package/dist/host-lists/sources/eastmoney.source.js.map +1 -0
  239. package/dist/host-lists/sources/geekpark.source.d.ts +9 -0
  240. package/dist/host-lists/sources/geekpark.source.js +60 -0
  241. package/dist/host-lists/sources/geekpark.source.js.map +1 -0
  242. package/dist/host-lists/sources/gelonghui.source.d.ts +9 -0
  243. package/dist/host-lists/sources/gelonghui.source.js +139 -0
  244. package/dist/host-lists/sources/gelonghui.source.js.map +1 -0
  245. package/dist/host-lists/sources/github.source.d.ts +12 -0
  246. package/dist/host-lists/sources/github.source.js +171 -0
  247. package/dist/host-lists/sources/github.source.js.map +1 -0
  248. package/dist/host-lists/sources/guokr.source.d.ts +11 -0
  249. package/dist/host-lists/sources/guokr.source.js +98 -0
  250. package/dist/host-lists/sources/guokr.source.js.map +1 -0
  251. package/dist/host-lists/sources/hackernews.source.d.ts +11 -0
  252. package/dist/host-lists/sources/hackernews.source.js +121 -0
  253. package/dist/host-lists/sources/hackernews.source.js.map +1 -0
  254. package/dist/host-lists/sources/hellogithub.source.d.ts +11 -0
  255. package/dist/host-lists/sources/hellogithub.source.js +98 -0
  256. package/dist/host-lists/sources/hellogithub.source.js.map +1 -0
  257. package/dist/host-lists/sources/history.source.d.ts +11 -0
  258. package/dist/host-lists/sources/history.source.js +92 -0
  259. package/dist/host-lists/sources/history.source.js.map +1 -0
  260. package/dist/host-lists/sources/honkai.source.d.ts +9 -0
  261. package/dist/host-lists/sources/honkai.source.js +72 -0
  262. package/dist/host-lists/sources/honkai.source.js.map +1 -0
  263. package/dist/host-lists/sources/hostloc.source.d.ts +9 -0
  264. package/dist/host-lists/sources/hostloc.source.js +75 -0
  265. package/dist/host-lists/sources/hostloc.source.js.map +1 -0
  266. package/dist/host-lists/sources/hupu.source.d.ts +9 -0
  267. package/dist/host-lists/sources/hupu.source.js +73 -0
  268. package/dist/host-lists/sources/hupu.source.js.map +1 -0
  269. package/dist/host-lists/sources/huxiu.source.d.ts +9 -0
  270. package/dist/host-lists/sources/huxiu.source.js +153 -0
  271. package/dist/host-lists/sources/huxiu.source.js.map +1 -0
  272. package/dist/host-lists/sources/ifanr.source.d.ts +9 -0
  273. package/dist/host-lists/sources/ifanr.source.js +57 -0
  274. package/dist/host-lists/sources/ifanr.source.js.map +1 -0
  275. package/dist/host-lists/sources/index.d.ts +2 -0
  276. package/dist/host-lists/sources/index.js +134 -0
  277. package/dist/host-lists/sources/index.js.map +1 -0
  278. package/dist/host-lists/sources/ithome-xijiayi.source.d.ts +9 -0
  279. package/dist/host-lists/sources/ithome-xijiayi.source.js +75 -0
  280. package/dist/host-lists/sources/ithome-xijiayi.source.js.map +1 -0
  281. package/dist/host-lists/sources/ithome.source.d.ts +9 -0
  282. package/dist/host-lists/sources/ithome.source.js +71 -0
  283. package/dist/host-lists/sources/ithome.source.js.map +1 -0
  284. package/dist/host-lists/sources/jd.source.d.ts +9 -0
  285. package/dist/host-lists/sources/jd.source.js +82 -0
  286. package/dist/host-lists/sources/jd.source.js.map +1 -0
  287. package/dist/host-lists/sources/jianshu.source.d.ts +9 -0
  288. package/dist/host-lists/sources/jianshu.source.js +72 -0
  289. package/dist/host-lists/sources/jianshu.source.js.map +1 -0
  290. package/dist/host-lists/sources/jin10.source.d.ts +9 -0
  291. package/dist/host-lists/sources/jin10.source.js +63 -0
  292. package/dist/host-lists/sources/jin10.source.js.map +1 -0
  293. package/dist/host-lists/sources/juejin.source.d.ts +10 -0
  294. package/dist/host-lists/sources/juejin.source.js +81 -0
  295. package/dist/host-lists/sources/juejin.source.js.map +1 -0
  296. package/dist/host-lists/sources/kuaishou.source.d.ts +13 -0
  297. package/dist/host-lists/sources/kuaishou.source.js +179 -0
  298. package/dist/host-lists/sources/kuaishou.source.js.map +1 -0
  299. package/dist/host-lists/sources/linuxdo.source.d.ts +9 -0
  300. package/dist/host-lists/sources/linuxdo.source.js +62 -0
  301. package/dist/host-lists/sources/linuxdo.source.js.map +1 -0
  302. package/dist/host-lists/sources/lol.source.d.ts +9 -0
  303. package/dist/host-lists/sources/lol.source.js +58 -0
  304. package/dist/host-lists/sources/lol.source.js.map +1 -0
  305. package/dist/host-lists/sources/miyoushe.source.d.ts +9 -0
  306. package/dist/host-lists/sources/miyoushe.source.js +88 -0
  307. package/dist/host-lists/sources/miyoushe.source.js.map +1 -0
  308. package/dist/host-lists/sources/netease-news.source.d.ts +9 -0
  309. package/dist/host-lists/sources/netease-news.source.js +56 -0
  310. package/dist/host-lists/sources/netease-news.source.js.map +1 -0
  311. package/dist/host-lists/sources/ngabbs.source.d.ts +9 -0
  312. package/dist/host-lists/sources/ngabbs.source.js +70 -0
  313. package/dist/host-lists/sources/ngabbs.source.js.map +1 -0
  314. package/dist/host-lists/sources/nodeseek.source.d.ts +9 -0
  315. package/dist/host-lists/sources/nodeseek.source.js +62 -0
  316. package/dist/host-lists/sources/nodeseek.source.js.map +1 -0
  317. package/dist/host-lists/sources/nytimes.source.d.ts +9 -0
  318. package/dist/host-lists/sources/nytimes.source.js +77 -0
  319. package/dist/host-lists/sources/nytimes.source.js.map +1 -0
  320. package/dist/host-lists/sources/producthunt.source.d.ts +9 -0
  321. package/dist/host-lists/sources/producthunt.source.js +75 -0
  322. package/dist/host-lists/sources/producthunt.source.js.map +1 -0
  323. package/dist/host-lists/sources/qq-news.source.d.ts +9 -0
  324. package/dist/host-lists/sources/qq-news.source.js +53 -0
  325. package/dist/host-lists/sources/qq-news.source.js.map +1 -0
  326. package/dist/host-lists/sources/sina-news.source.d.ts +9 -0
  327. package/dist/host-lists/sources/sina-news.source.js +98 -0
  328. package/dist/host-lists/sources/sina-news.source.js.map +1 -0
  329. package/dist/host-lists/sources/sina.source.d.ts +9 -0
  330. package/dist/host-lists/sources/sina.source.js +78 -0
  331. package/dist/host-lists/sources/sina.source.js.map +1 -0
  332. package/dist/host-lists/sources/smzdm.source.d.ts +9 -0
  333. package/dist/host-lists/sources/smzdm.source.js +71 -0
  334. package/dist/host-lists/sources/smzdm.source.js.map +1 -0
  335. package/dist/host-lists/sources/sspai.source.d.ts +9 -0
  336. package/dist/host-lists/sources/sspai.source.js +69 -0
  337. package/dist/host-lists/sources/sspai.source.js.map +1 -0
  338. package/dist/host-lists/sources/starrail.source.d.ts +9 -0
  339. package/dist/host-lists/sources/starrail.source.js +72 -0
  340. package/dist/host-lists/sources/starrail.source.js.map +1 -0
  341. package/dist/host-lists/sources/taobao.source.d.ts +10 -0
  342. package/dist/host-lists/sources/taobao.source.js +169 -0
  343. package/dist/host-lists/sources/taobao.source.js.map +1 -0
  344. package/dist/host-lists/sources/thepaper.source.d.ts +9 -0
  345. package/dist/host-lists/sources/thepaper.source.js +56 -0
  346. package/dist/host-lists/sources/thepaper.source.js.map +1 -0
  347. package/dist/host-lists/sources/tieba.source.d.ts +9 -0
  348. package/dist/host-lists/sources/tieba.source.js +58 -0
  349. package/dist/host-lists/sources/tieba.source.js.map +1 -0
  350. package/dist/host-lists/sources/tonghuashun.source.d.ts +9 -0
  351. package/dist/host-lists/sources/tonghuashun.source.js +112 -0
  352. package/dist/host-lists/sources/tonghuashun.source.js.map +1 -0
  353. package/dist/host-lists/sources/toutiao.source.d.ts +9 -0
  354. package/dist/host-lists/sources/toutiao.source.js +56 -0
  355. package/dist/host-lists/sources/toutiao.source.js.map +1 -0
  356. package/dist/host-lists/sources/v2ex.source.d.ts +9 -0
  357. package/dist/host-lists/sources/v2ex.source.js +67 -0
  358. package/dist/host-lists/sources/v2ex.source.js.map +1 -0
  359. package/dist/host-lists/sources/wallstreet.source.d.ts +9 -0
  360. package/dist/host-lists/sources/wallstreet.source.js +59 -0
  361. package/dist/host-lists/sources/wallstreet.source.js.map +1 -0
  362. package/dist/host-lists/sources/weatheralarm.source.d.ts +9 -0
  363. package/dist/host-lists/sources/weatheralarm.source.js +68 -0
  364. package/dist/host-lists/sources/weatheralarm.source.js.map +1 -0
  365. package/dist/host-lists/sources/weibo.source.d.ts +15 -0
  366. package/dist/host-lists/sources/weibo.source.js +180 -0
  367. package/dist/host-lists/sources/weibo.source.js.map +1 -0
  368. package/dist/host-lists/sources/weread.source.d.ts +9 -0
  369. package/dist/host-lists/sources/weread.source.js +82 -0
  370. package/dist/host-lists/sources/weread.source.js.map +1 -0
  371. package/dist/host-lists/sources/xinyu.source.d.ts +9 -0
  372. package/dist/host-lists/sources/xinyu.source.js +151 -0
  373. package/dist/host-lists/sources/xinyu.source.js.map +1 -0
  374. package/dist/host-lists/sources/yicai.source.d.ts +9 -0
  375. package/dist/host-lists/sources/yicai.source.js +113 -0
  376. package/dist/host-lists/sources/yicai.source.js.map +1 -0
  377. package/dist/host-lists/sources/yystv.source.d.ts +9 -0
  378. package/dist/host-lists/sources/yystv.source.js +57 -0
  379. package/dist/host-lists/sources/yystv.source.js.map +1 -0
  380. package/dist/host-lists/sources/zhihu-daily.source.d.ts +9 -0
  381. package/dist/host-lists/sources/zhihu-daily.source.js +60 -0
  382. package/dist/host-lists/sources/zhihu-daily.source.js.map +1 -0
  383. package/dist/host-lists/sources/zhihu.source.d.ts +12 -0
  384. package/dist/host-lists/sources/zhihu.source.js +195 -0
  385. package/dist/host-lists/sources/zhihu.source.js.map +1 -0
  386. package/dist/http/http.module.d.ts +2 -0
  387. package/dist/http/http.module.js +30 -0
  388. package/dist/http/http.module.js.map +1 -0
  389. package/dist/http/http.service.d.ts +53 -0
  390. package/dist/http/http.service.js +277 -0
  391. package/dist/http/http.service.js.map +1 -0
  392. package/dist/main.d.ts +3 -0
  393. package/dist/main.js +70 -0
  394. package/dist/main.js.map +1 -0
  395. package/dist/rss/rss.module.d.ts +2 -0
  396. package/dist/rss/rss.module.js +21 -0
  397. package/dist/rss/rss.module.js.map +1 -0
  398. package/dist/rss/rss.service.d.ts +5 -0
  399. package/dist/rss/rss.service.js +55 -0
  400. package/dist/rss/rss.service.js.map +1 -0
  401. package/dist/scheduler/dto/trigger-fetch.dto.d.ts +3 -0
  402. package/dist/scheduler/dto/trigger-fetch.dto.js +22 -0
  403. package/dist/scheduler/dto/trigger-fetch.dto.js.map +1 -0
  404. package/dist/scheduler/dto/update-source-config.dto.d.ts +4 -0
  405. package/dist/scheduler/dto/update-source-config.dto.js +29 -0
  406. package/dist/scheduler/dto/update-source-config.dto.js.map +1 -0
  407. package/dist/scheduler/scheduler.controller.d.ts +52 -0
  408. package/dist/scheduler/scheduler.controller.js +132 -0
  409. package/dist/scheduler/scheduler.controller.js.map +1 -0
  410. package/dist/scheduler/scheduler.module.d.ts +2 -0
  411. package/dist/scheduler/scheduler.module.js +34 -0
  412. package/dist/scheduler/scheduler.module.js.map +1 -0
  413. package/dist/scheduler/scheduler.service.d.ts +54 -0
  414. package/dist/scheduler/scheduler.service.js +238 -0
  415. package/dist/scheduler/scheduler.service.js.map +1 -0
  416. package/dist/scheduler/tasks/fetch-hot-data.task.d.ts +34 -0
  417. package/dist/scheduler/tasks/fetch-hot-data.task.js +175 -0
  418. package/dist/scheduler/tasks/fetch-hot-data.task.js.map +1 -0
  419. package/dist/token/coolapk.d.ts +11 -0
  420. package/dist/token/coolapk.js +40 -0
  421. package/dist/token/coolapk.js.map +1 -0
  422. package/dist/token/token.module.d.ts +2 -0
  423. package/dist/token/token.module.js +23 -0
  424. package/dist/token/token.module.js.map +1 -0
  425. package/dist/token/token.service.d.ts +19 -0
  426. package/dist/token/token.service.js +115 -0
  427. package/dist/token/token.service.js.map +1 -0
  428. package/dist/token/tools.d.ts +1 -0
  429. package/dist/token/tools.js +15 -0
  430. package/dist/token/tools.js.map +1 -0
  431. package/dist/token/weread.d.ts +2 -0
  432. package/dist/token/weread.js +55 -0
  433. package/dist/token/weread.js.map +1 -0
  434. package/dist/utils/getNum.d.ts +1 -0
  435. package/dist/utils/getNum.js +20 -0
  436. package/dist/utils/getNum.js.map +1 -0
  437. package/dist/utils/getTime.d.ts +11 -0
  438. package/dist/utils/getTime.js +134 -0
  439. package/dist/utils/getTime.js.map +1 -0
  440. package/dist/utils/headers.d.ts +16 -0
  441. package/dist/utils/headers.js +20 -0
  442. package/dist/utils/headers.js.map +1 -0
  443. package/dist/utils/index.d.ts +1 -0
  444. package/dist/utils/index.js +12 -0
  445. package/dist/utils/index.js.map +1 -0
  446. package/dist/utils/parseRSS.d.ts +11 -0
  447. package/dist/utils/parseRSS.js +47 -0
  448. package/dist/utils/parseRSS.js.map +1 -0
  449. package/package.json +148 -4
  450. package/views/home.hbs +65 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yystv.source.js","sourceRoot":"","sources":["../../../src/host-lists/sources/yystv.source.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6EAA+D;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qCAE0C,gCAAiB;GADhD,WAAW,CA6BvB"}
@@ -0,0 +1,9 @@
1
+ import { HotListSource } from '../interfaces/hot-list-source.interface';
2
+ import { HotListGetListResponse } from '../interfaces/hot-list.interface';
3
+ import { HttpClientService } from '../../http/http.service';
4
+ import { GetListOptions } from './source.types';
5
+ export declare class ZhihuDailySource implements HotListSource {
6
+ private readonly httpService;
7
+ constructor(httpService: HttpClientService);
8
+ getList(options?: GetListOptions, noCache?: boolean): Promise<HotListGetListResponse>;
9
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ZhihuDailySource = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const hot_source_decorator_1 = require("../decorators/hot-source.decorator");
15
+ const http_service_1 = require("../../http/http.service");
16
+ let ZhihuDailySource = class ZhihuDailySource {
17
+ constructor(httpService) {
18
+ this.httpService = httpService;
19
+ }
20
+ async getList(options = {}, noCache) {
21
+ const url = 'https://daily.zhihu.com/api/4/news/latest';
22
+ const result = await this.httpService.get({
23
+ url,
24
+ noCache: noCache ?? options.noCache,
25
+ headers: {
26
+ Referer: 'https://daily.zhihu.com/api/4/news/latest',
27
+ Host: 'daily.zhihu.com',
28
+ },
29
+ });
30
+ const list = (result?.data?.stories || []).filter((el) => el.type === 0);
31
+ const data = list.map((v) => ({
32
+ id: v.id,
33
+ title: v.title,
34
+ cover: v.images?.[0] ?? undefined,
35
+ author: v.hint,
36
+ hot: undefined,
37
+ timestamp: undefined,
38
+ url: v.url,
39
+ mobileUrl: v.url,
40
+ }));
41
+ return {
42
+ data,
43
+ fromCache: result.fromCache,
44
+ updateTime: result.updateTime,
45
+ };
46
+ }
47
+ };
48
+ exports.ZhihuDailySource = ZhihuDailySource;
49
+ exports.ZhihuDailySource = ZhihuDailySource = __decorate([
50
+ (0, common_1.Injectable)(),
51
+ (0, hot_source_decorator_1.HotSource)({
52
+ name: 'zhihu-daily',
53
+ title: '知乎日报',
54
+ type: '推荐榜',
55
+ link: 'https://daily.zhihu.com/',
56
+ description: '每天三次,每次七分钟',
57
+ }),
58
+ __metadata("design:paramtypes", [http_service_1.HttpClientService])
59
+ ], ZhihuDailySource);
60
+ //# sourceMappingURL=zhihu-daily.source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zhihu-daily.source.js","sourceRoot":"","sources":["../../../src/host-lists/sources/zhihu-daily.source.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6EAA+D;AAM/D,0DAA4D;AAWrD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,WAA8B;QAA9B,gBAAW,GAAX,WAAW,CAAmB;IAAG,CAAC;IAE/D,KAAK,CAAC,OAAO,CACX,UAA0B,EAAE,EAC5B,OAAiB;QAEjB,MAAM,GAAG,GAAG,2CAA2C,CAAC;QACxD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,CAEtC;YACD,GAAG;YACH,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,OAAO;YACnC,OAAO,EAAE;gBACP,OAAO,EAAE,2CAA2C;gBACpD,IAAI,EAAE,iBAAiB;aACxB;SACF,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;QACzE,MAAM,IAAI,GAAkB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC3C,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS;YACjC,MAAM,EAAE,CAAC,CAAC,IAAI;YACd,GAAG,EAAE,SAAS;YACd,SAAS,EAAE,SAAS;YACpB,GAAG,EAAE,CAAC,CAAC,GAAG;YACV,SAAS,EAAE,CAAC,CAAC,GAAG;SACjB,CAAC,CAAC,CAAC;QACJ,OAAO;YACL,IAAI;YACJ,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC;CACF,CAAA;AAnCY,4CAAgB;2BAAhB,gBAAgB;IAR5B,IAAA,mBAAU,GAAE;IACZ,IAAA,gCAAS,EAAC;QACT,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,MAAM;QACb,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,0BAA0B;QAChC,WAAW,EAAE,YAAY;KAC1B,CAAC;qCAE0C,gCAAiB;GADhD,gBAAgB,CAmC5B"}
@@ -0,0 +1,12 @@
1
+ import { HotListSource } from '../interfaces/hot-list-source.interface';
2
+ import { HotListGetListResponse } from '../interfaces/hot-list.interface';
3
+ import { HttpClientService } from '../../http/http.service';
4
+ import { GetListOptions } from './source.types';
5
+ export declare class ZhihuSource implements HotListSource {
6
+ private readonly httpService;
7
+ private readonly logger;
8
+ constructor(httpService: HttpClientService);
9
+ getList(options: GetListOptions, noCache?: boolean): Promise<HotListGetListResponse>;
10
+ private fetchFromAPI;
11
+ private fetchFromFallbackAPI;
12
+ }
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var ZhihuSource_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ZhihuSource = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const hot_source_decorator_1 = require("../decorators/hot-source.decorator");
16
+ const http_service_1 = require("../../http/http.service");
17
+ const utils_1 = require("../../utils");
18
+ let ZhihuSource = ZhihuSource_1 = class ZhihuSource {
19
+ constructor(httpService) {
20
+ this.httpService = httpService;
21
+ this.logger = new common_1.Logger(ZhihuSource_1.name);
22
+ }
23
+ async getList(options, noCache) {
24
+ try {
25
+ const result = await this.fetchFromAPI(noCache ?? false);
26
+ return {
27
+ data: result.data,
28
+ params: {
29
+ type: {
30
+ name: '热搜类别',
31
+ type: {},
32
+ },
33
+ },
34
+ fromCache: result.fromCache,
35
+ updateTime: result.updateTime,
36
+ };
37
+ }
38
+ catch (error) {
39
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
40
+ this.logger.error(`Failed to get list from API: ${errorMessage}`);
41
+ try {
42
+ const result = await this.fetchFromFallbackAPI(noCache ?? false);
43
+ return {
44
+ data: result.data,
45
+ params: {
46
+ type: {
47
+ name: '热搜类别',
48
+ type: {},
49
+ },
50
+ },
51
+ fromCache: result.fromCache,
52
+ updateTime: result.updateTime,
53
+ };
54
+ }
55
+ catch (fallbackError) {
56
+ const fallbackErrorMessage = fallbackError instanceof Error
57
+ ? fallbackError.message
58
+ : 'Unknown error';
59
+ this.logger.error(`Failed to get list from fallback API: ${fallbackErrorMessage}`);
60
+ return {
61
+ data: [],
62
+ params: {
63
+ type: {
64
+ name: '热搜类别',
65
+ type: {},
66
+ },
67
+ },
68
+ fromCache: false,
69
+ updateTime: 0,
70
+ };
71
+ }
72
+ }
73
+ }
74
+ async fetchFromAPI(noCache) {
75
+ const url = 'https://api.zhihu.com/topstory/hot-list';
76
+ const headers = {
77
+ Accept: 'application/json, text/plain, */*',
78
+ 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
79
+ Connection: 'keep-alive',
80
+ Referer: 'https://www.zhihu.com/hot',
81
+ Origin: 'https://www.zhihu.com',
82
+ 'Sec-Fetch-Dest': 'empty',
83
+ 'Sec-Fetch-Mode': 'cors',
84
+ 'Sec-Fetch-Site': 'same-site',
85
+ 'Sec-Ch-Ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
86
+ 'Sec-Ch-Ua-Mobile': '?0',
87
+ 'Sec-Ch-Ua-Platform': '"macOS"',
88
+ 'X-Requested-With': 'XMLHttpRequest',
89
+ 'X-UDID': (0, utils_1.generateRandomId)(32),
90
+ 'X-API-VERSION': '3.0.53',
91
+ };
92
+ const response = await this.httpService.get({
93
+ url,
94
+ headers,
95
+ params: {
96
+ limit: '50',
97
+ reverse_order: '0',
98
+ _t: Date.now().toString(),
99
+ },
100
+ noCache,
101
+ });
102
+ const apiData = response.data?.data || [];
103
+ const list = apiData
104
+ .map((v) => {
105
+ const data = v.target;
106
+ if (!data)
107
+ return null;
108
+ const q_id = v?.card_id?.split('_')?.[1] || data?.id || '';
109
+ return {
110
+ id: data.id || '',
111
+ title: data.title || '',
112
+ desc: data.excerpt || '',
113
+ cover: v.children?.[0]?.thumbnail || '',
114
+ timestamp: Date.now(),
115
+ hot: v.detail_text
116
+ ? parseFloat(v.detail_text.split(' ')[0]) * 10000
117
+ : 0,
118
+ url: `https://www.zhihu.com/question/${q_id}`,
119
+ mobileUrl: `https://www.zhihu.com/question/${q_id}`,
120
+ };
121
+ })
122
+ .filter((item) => item !== null);
123
+ return {
124
+ data: list,
125
+ fromCache: response.fromCache,
126
+ updateTime: response.updateTime,
127
+ };
128
+ }
129
+ async fetchFromFallbackAPI(noCache) {
130
+ const url = 'https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total';
131
+ const headers = {
132
+ Accept: 'application/json, text/plain, */*',
133
+ 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
134
+ Connection: 'keep-alive',
135
+ Referer: 'https://www.zhihu.com/hot',
136
+ Origin: 'https://www.zhihu.com',
137
+ 'Sec-Fetch-Dest': 'empty',
138
+ 'Sec-Fetch-Mode': 'cors',
139
+ 'Sec-Fetch-Site': 'same-site',
140
+ 'Sec-Ch-Ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
141
+ 'Sec-Ch-Ua-Mobile': '?0',
142
+ 'Sec-Ch-Ua-Platform': '"macOS"',
143
+ 'X-Requested-With': 'XMLHttpRequest',
144
+ 'X-UDID': (0, utils_1.generateRandomId)(32),
145
+ 'X-API-VERSION': '3.0.53',
146
+ };
147
+ const response = await this.httpService.get({
148
+ url,
149
+ headers,
150
+ params: {
151
+ limit: '50',
152
+ desktop: 'true',
153
+ _t: Date.now().toString(),
154
+ },
155
+ noCache,
156
+ });
157
+ const apiData = response.data?.data || [];
158
+ const list = apiData
159
+ .map((v) => {
160
+ const data = v.target;
161
+ if (!data)
162
+ return null;
163
+ const q_id = v?.card_id?.split('_')?.[1] || data?.id || '';
164
+ return {
165
+ id: data.id || '',
166
+ title: data.title || '',
167
+ desc: data.excerpt || '',
168
+ cover: v.children?.[0]?.thumbnail || '',
169
+ timestamp: Date.now(),
170
+ hot: v.detail_text
171
+ ? parseFloat(v.detail_text.split(' ')[0]) * 10000
172
+ : 0,
173
+ url: `https://www.zhihu.com/question/${q_id}`,
174
+ mobileUrl: `https://www.zhihu.com/question/${q_id}`,
175
+ };
176
+ })
177
+ .filter((item) => item !== null);
178
+ return {
179
+ data: list,
180
+ fromCache: response.fromCache,
181
+ updateTime: response.updateTime,
182
+ };
183
+ }
184
+ };
185
+ exports.ZhihuSource = ZhihuSource;
186
+ exports.ZhihuSource = ZhihuSource = ZhihuSource_1 = __decorate([
187
+ (0, common_1.Injectable)(),
188
+ (0, hot_source_decorator_1.HotSource)({
189
+ name: 'zhihu',
190
+ title: '知乎',
191
+ link: 'https://www.zhihu.com/hot',
192
+ }),
193
+ __metadata("design:paramtypes", [http_service_1.HttpClientService])
194
+ ], ZhihuSource);
195
+ //# sourceMappingURL=zhihu.source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zhihu.source.js","sourceRoot":"","sources":["../../../src/host-lists/sources/zhihu.source.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6EAA+D;AAM/D,0DAA4D;AAE5D,uCAA6C;AA+BtC,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAGtB,YAA6B,WAA8B;QAA9B,gBAAW,GAAX,WAAW,CAAmB;QAF1C,WAAM,GAAG,IAAI,eAAM,CAAC,aAAW,CAAC,IAAI,CAAC,CAAC;IAEO,CAAC;IAE/D,KAAK,CAAC,OAAO,CACX,OAAuB,EACvB,OAAiB;QAEjB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;YACzD,OAAO;gBACL,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,MAAM,EAAE;oBACN,IAAI,EAAE;wBACJ,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,EAAE;qBACT;iBACF;gBACD,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B,CAAC;QAC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ACF,CAAA;AAvMY,kCAAW;sBAAX,WAAW;IANvB,IAAA,mBAAU,GAAE;IACZ,IAAA,gCAAS,EAAC;QACT,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,2BAA2B;KAClC,CAAC;qCAI0C,gCAAiB;GAHhD,WAAW,CAuMvB"}
@@ -0,0 +1,2 @@
1
+ export declare class HttpClientModule {
2
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.HttpClientModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const axios_1 = require("@nestjs/axios");
12
+ const http_service_1 = require("./http.service");
13
+ const cache_module_1 = require("../cache/cache.module");
14
+ let HttpClientModule = class HttpClientModule {
15
+ };
16
+ exports.HttpClientModule = HttpClientModule;
17
+ exports.HttpClientModule = HttpClientModule = __decorate([
18
+ (0, common_1.Module)({
19
+ imports: [
20
+ axios_1.HttpModule.register({
21
+ timeout: 6000,
22
+ maxRedirects: 5,
23
+ }),
24
+ cache_module_1.CacheModule,
25
+ ],
26
+ providers: [http_service_1.HttpClientService],
27
+ exports: [http_service_1.HttpClientService],
28
+ })
29
+ ], HttpClientModule);
30
+ //# sourceMappingURL=http.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.module.js","sourceRoot":"","sources":["../../src/http/http.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yCAA2C;AAC3C,iDAAmD;AACnD,wDAAoD;AAa7C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAX5B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,kBAAU,CAAC,QAAQ,CAAC;gBAClB,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,CAAC;aAChB,CAAC;YACF,0BAAW;SACZ;QACD,SAAS,EAAE,CAAC,gCAAiB,CAAC;QAC9B,OAAO,EAAE,CAAC,gCAAiB,CAAC;KAC7B,CAAC;GACW,gBAAgB,CAAG"}
@@ -0,0 +1,53 @@
1
+ import { HttpService } from '@nestjs/axios';
2
+ import { CacheData, CacheService } from '../cache/cache.service';
3
+ import { ConfigService } from '@nestjs/config';
4
+ type ResponseData<T> = {
5
+ fromCache: boolean;
6
+ } & CacheData<T>;
7
+ export declare class HttpRequestError extends Error {
8
+ readonly url: string;
9
+ readonly status?: number | undefined;
10
+ constructor(message: string, url: string, status?: number | undefined);
11
+ }
12
+ export declare class HttpTimeoutError extends HttpRequestError {
13
+ constructor(url: string);
14
+ }
15
+ export declare class HttpNetworkError extends HttpRequestError {
16
+ constructor(url: string);
17
+ }
18
+ export interface BaseHttpRequestOptions {
19
+ url: string;
20
+ headers?: Record<string, string>;
21
+ noCache?: boolean;
22
+ ttl?: number;
23
+ timeout?: number;
24
+ retries?: number;
25
+ }
26
+ export interface HttpGetOptions extends BaseHttpRequestOptions {
27
+ params?: Record<string | number, string | number | boolean | undefined>;
28
+ responseType?: 'json' | 'text' | 'arraybuffer' | 'blob' | 'document' | 'stream';
29
+ }
30
+ export interface HttpPostOptions extends BaseHttpRequestOptions {
31
+ data?: Record<string, unknown>;
32
+ }
33
+ export declare class HttpClientService {
34
+ private readonly httpService;
35
+ private readonly cacheService;
36
+ private readonly configService;
37
+ private readonly logger;
38
+ private readonly inFlight;
39
+ constructor(httpService: HttpService, cacheService: CacheService, configService: ConfigService);
40
+ private stableSerialize;
41
+ private isVolatileKey;
42
+ private stableHeaders;
43
+ private stableData;
44
+ private cacheKey;
45
+ private singleFlight;
46
+ private retryDelay;
47
+ invalidateGet(options: HttpGetOptions): Promise<void>;
48
+ private getRandomUserAgent;
49
+ get<T = unknown>(options: HttpGetOptions): Promise<ResponseData<T>>;
50
+ post<T = unknown>(options: HttpPostOptions): Promise<ResponseData<T>>;
51
+ private handleHttpError;
52
+ }
53
+ export {};
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var HttpClientService_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.HttpClientService = exports.HttpNetworkError = exports.HttpTimeoutError = exports.HttpRequestError = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const axios_1 = require("@nestjs/axios");
16
+ const cache_service_1 = require("../cache/cache.service");
17
+ const rxjs_1 = require("rxjs");
18
+ const axios_2 = require("axios");
19
+ const crypto_1 = require("crypto");
20
+ const config_1 = require("@nestjs/config");
21
+ const VOLATILE_REQUEST_KEYS = new Set([
22
+ '_',
23
+ '_signature',
24
+ '_t',
25
+ 'mstoken',
26
+ 'nonce',
27
+ 'sign',
28
+ 'signature',
29
+ 'timestamp',
30
+ 'token',
31
+ 'w_rid',
32
+ 'wts',
33
+ ]);
34
+ const VOLATILE_HEADER_KEYS = new Set(['cookie', 'user-agent', 'x-udid']);
35
+ class HttpRequestError extends Error {
36
+ constructor(message, url, status) {
37
+ super(message);
38
+ this.url = url;
39
+ this.status = status;
40
+ this.name = 'HttpRequestError';
41
+ }
42
+ }
43
+ exports.HttpRequestError = HttpRequestError;
44
+ class HttpTimeoutError extends HttpRequestError {
45
+ constructor(url) {
46
+ super(`Request timeout for ${url}`, url, 408);
47
+ this.name = 'HttpTimeoutError';
48
+ }
49
+ }
50
+ exports.HttpTimeoutError = HttpTimeoutError;
51
+ class HttpNetworkError extends HttpRequestError {
52
+ constructor(url) {
53
+ super(`Network error for ${url}`, url);
54
+ this.name = 'HttpNetworkError';
55
+ }
56
+ }
57
+ exports.HttpNetworkError = HttpNetworkError;
58
+ let HttpClientService = HttpClientService_1 = class HttpClientService {
59
+ constructor(httpService, cacheService, configService) {
60
+ this.httpService = httpService;
61
+ this.cacheService = cacheService;
62
+ this.configService = configService;
63
+ this.logger = new common_1.Logger(HttpClientService_1.name);
64
+ this.inFlight = new Map();
65
+ }
66
+ stableSerialize(value) {
67
+ if (Array.isArray(value)) {
68
+ return `[${value.map((item) => this.stableSerialize(item)).join(',')}]`;
69
+ }
70
+ if (value && typeof value === 'object') {
71
+ return `{${Object.entries(value)
72
+ .sort(([a], [b]) => a.localeCompare(b))
73
+ .map(([key, item]) => `${JSON.stringify(key)}:${this.stableSerialize(item)}`)
74
+ .join(',')}}`;
75
+ }
76
+ return JSON.stringify(value) ?? 'null';
77
+ }
78
+ isVolatileKey(key) {
79
+ return VOLATILE_REQUEST_KEYS.has(key.toLowerCase());
80
+ }
81
+ stableHeaders(headers) {
82
+ return Object.fromEntries(Object.entries(headers ?? {})
83
+ .map(([key, value]) => [key.toLowerCase(), value])
84
+ .filter(([key]) => !VOLATILE_HEADER_KEYS.has(key)));
85
+ }
86
+ stableData(data) {
87
+ if (!data)
88
+ return undefined;
89
+ return Object.fromEntries(Object.entries(data).filter(([key]) => !this.isVolatileKey(key)));
90
+ }
91
+ cacheKey(method, options) {
92
+ const query = [];
93
+ let url = options.url;
94
+ try {
95
+ const parsed = new URL(options.url);
96
+ for (const [key, value] of parsed.searchParams) {
97
+ if (!this.isVolatileKey(key))
98
+ query.push([key, value]);
99
+ }
100
+ url = `${parsed.origin}${parsed.pathname}`;
101
+ }
102
+ catch {
103
+ }
104
+ const params = 'params' in options ? options.params : undefined;
105
+ for (const [key, value] of Object.entries(params ?? {})) {
106
+ if (!this.isVolatileKey(key))
107
+ query.push([key, value]);
108
+ }
109
+ const request = {
110
+ method,
111
+ url,
112
+ query: query.sort(([a], [b]) => a.localeCompare(b)),
113
+ headers: this.stableHeaders(options.headers),
114
+ data: 'data' in options ? this.stableData(options.data) : undefined,
115
+ responseType: 'responseType' in options ? options.responseType : undefined,
116
+ };
117
+ return `http:${(0, crypto_1.createHash)('sha256').update(this.stableSerialize(request)).digest('hex')}`;
118
+ }
119
+ async singleFlight(key, fetcher) {
120
+ const current = this.inFlight.get(key);
121
+ if (current !== undefined)
122
+ return current;
123
+ const pending = fetcher();
124
+ this.inFlight.set(key, pending);
125
+ try {
126
+ return await pending;
127
+ }
128
+ finally {
129
+ if (this.inFlight.get(key) === pending)
130
+ this.inFlight.delete(key);
131
+ }
132
+ }
133
+ retryDelay(error, attempt) {
134
+ const status = error instanceof axios_2.AxiosError ? error.response?.status : undefined;
135
+ const retryable = error instanceof axios_2.AxiosError &&
136
+ (error.code === 'ECONNABORTED' ||
137
+ !error.response ||
138
+ status === 429 ||
139
+ (status !== undefined && status >= 500));
140
+ if (!retryable)
141
+ return (0, rxjs_1.throwError)(() => error);
142
+ return (0, rxjs_1.timer)(Math.min(2000, 250 * 2 ** (attempt - 1)) + Math.random() * 100);
143
+ }
144
+ async invalidateGet(options) {
145
+ await this.cacheService.del(this.cacheKey('GET', options));
146
+ }
147
+ getRandomUserAgent() {
148
+ const userAgents = [
149
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
150
+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Safari/605.1.15',
151
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0',
152
+ 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/96.0.4664.53 Mobile/15E148 Safari/604.1',
153
+ 'Mozilla/5.0 (Linux; Android 12; SM-G991B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Mobile Safari/537.36',
154
+ 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',
155
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edge/96.0.1054.43 Safari/537.36',
156
+ ];
157
+ return userAgents[Math.floor(Math.random() * userAgents.length)];
158
+ }
159
+ async get(options) {
160
+ const { url, headers = {}, params, noCache, ttl, timeout = this.configService.getOrThrow('REQUEST_TIMEOUT'), retries = 2, responseType = 'json', } = options;
161
+ const cacheKey = this.cacheKey('GET', options);
162
+ if (!noCache) {
163
+ const cachedData = await this.cacheService.get(cacheKey);
164
+ if (cachedData) {
165
+ this.logger.log(`📦 [Redis] Using cached data for ${cacheKey}`);
166
+ return {
167
+ ...cachedData,
168
+ fromCache: true,
169
+ };
170
+ }
171
+ }
172
+ const requestHeaders = { ...headers };
173
+ if (!requestHeaders['User-Agent']) {
174
+ requestHeaders['User-Agent'] = this.getRandomUserAgent();
175
+ }
176
+ return this.singleFlight(cacheKey, async () => {
177
+ try {
178
+ const response = await (0, rxjs_1.firstValueFrom)(this.httpService
179
+ .get(url, {
180
+ headers: requestHeaders,
181
+ params,
182
+ timeout,
183
+ responseType,
184
+ })
185
+ .pipe((0, rxjs_1.retry)({
186
+ count: retries,
187
+ delay: (error, attempt) => this.retryDelay(error, attempt),
188
+ }), (0, rxjs_1.catchError)((error) => {
189
+ throw this.handleHttpError(error, url);
190
+ })));
191
+ const cacheData = {
192
+ data: response.data,
193
+ updateTime: new Date().toISOString(),
194
+ fromCache: false,
195
+ };
196
+ this.logger.log(`🔄 [API] Fetching fresh data for ${cacheKey}`);
197
+ await this.cacheService.set(cacheKey, cacheData, ttl);
198
+ return cacheData;
199
+ }
200
+ catch (error) {
201
+ this.logger.error(`❌ [API] Error fetching data for ${cacheKey}: ${error instanceof Error ? error.message : String(error)}`);
202
+ throw error;
203
+ }
204
+ });
205
+ }
206
+ async post(options) {
207
+ const { url, headers = {}, data = {}, noCache, ttl, timeout = this.configService.getOrThrow('REQUEST_TIMEOUT'), retries = 2, } = options;
208
+ const cacheKey = this.cacheKey('POST', options);
209
+ if (!noCache) {
210
+ const cachedData = await this.cacheService.get(cacheKey);
211
+ if (cachedData) {
212
+ this.logger.log(`📦 [Redis] Using cached data for ${cacheKey}`);
213
+ return {
214
+ ...cachedData,
215
+ fromCache: true,
216
+ };
217
+ }
218
+ }
219
+ const requestHeaders = { ...headers };
220
+ if (!requestHeaders['User-Agent']) {
221
+ requestHeaders['User-Agent'] = this.getRandomUserAgent();
222
+ }
223
+ return this.singleFlight(cacheKey, async () => {
224
+ try {
225
+ const response = await (0, rxjs_1.firstValueFrom)(this.httpService
226
+ .post(url, data, {
227
+ headers: requestHeaders,
228
+ timeout,
229
+ })
230
+ .pipe((0, rxjs_1.retry)({
231
+ count: retries,
232
+ delay: (error, attempt) => this.retryDelay(error, attempt),
233
+ }), (0, rxjs_1.catchError)((error) => {
234
+ throw this.handleHttpError(error, url);
235
+ })));
236
+ const cacheData = {
237
+ data: response.data,
238
+ updateTime: new Date().toISOString(),
239
+ fromCache: false,
240
+ };
241
+ this.logger.log(`🔄 [API] Fetching fresh data for ${cacheKey}`);
242
+ await this.cacheService.set(cacheKey, cacheData, ttl);
243
+ return cacheData;
244
+ }
245
+ catch (error) {
246
+ this.logger.error(`❌ [API] Error posting data for ${cacheKey}: ${error instanceof Error ? error.message : String(error)}`);
247
+ throw error;
248
+ }
249
+ });
250
+ }
251
+ handleHttpError(error, url) {
252
+ let upstream = 'upstream';
253
+ try {
254
+ upstream = new URL(url).origin;
255
+ }
256
+ catch {
257
+ }
258
+ if (error instanceof axios_2.AxiosError) {
259
+ if (error.code === 'ECONNABORTED') {
260
+ return new HttpTimeoutError(upstream);
261
+ }
262
+ if (error.response) {
263
+ return new HttpRequestError(`HTTP ${error.response.status}: ${error.response.statusText}`, upstream, error.response.status);
264
+ }
265
+ return new HttpNetworkError(upstream);
266
+ }
267
+ return new HttpRequestError(`Unexpected HTTP client error from ${upstream}`, upstream);
268
+ }
269
+ };
270
+ exports.HttpClientService = HttpClientService;
271
+ exports.HttpClientService = HttpClientService = HttpClientService_1 = __decorate([
272
+ (0, common_1.Injectable)(),
273
+ __metadata("design:paramtypes", [axios_1.HttpService,
274
+ cache_service_1.CacheService,
275
+ config_1.ConfigService])
276
+ ], HttpClientService);
277
+ //# sourceMappingURL=http.service.js.map