rsshub 1.0.0-master.f7cdf8b → 1.0.0-master.f7f8b7a

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 (273) hide show
  1. package/README.md +3 -3
  2. package/lib/config.js +21 -8
  3. package/lib/middleware/cache/index.js +4 -3
  4. package/lib/middleware/cache/redis.js +3 -3
  5. package/lib/middleware/onerror.js +8 -0
  6. package/lib/middleware/template.js +79 -85
  7. package/lib/router.js +7 -7
  8. package/lib/routes/index.js +6 -13
  9. package/lib/utils/common-utils.js +2 -6
  10. package/lib/utils/render.js +2 -0
  11. package/lib/v2/1point3acres/maintainer.js +2 -2
  12. package/lib/v2/95mm/utils.js +3 -2
  13. package/lib/v2/aliyun/notice.js +1 -1
  14. package/lib/v2/amazon/maintainer.js +1 -1
  15. package/lib/v2/apnews/topics.js +1 -1
  16. package/lib/v2/arcteryx/maintainer.js +3 -3
  17. package/lib/v2/bangumi/maintainer.js +1 -0
  18. package/lib/v2/bangumi/radar.js +6 -0
  19. package/lib/v2/bangumi/router.js +1 -0
  20. package/lib/v2/bangumi/tv/user/wish.js +38 -0
  21. package/lib/v2/bellroy/maintainer.js +1 -1
  22. package/lib/v2/bilibili/cache.js +10 -7
  23. package/lib/v2/bilibili/maintainer.js +1 -0
  24. package/lib/v2/bilibili/platform.js +43 -0
  25. package/lib/v2/bilibili/radar.js +8 -0
  26. package/lib/v2/bilibili/router.js +1 -0
  27. package/lib/v2/bilibili/video.js +8 -1
  28. package/lib/v2/bossdesign/index.js +41 -0
  29. package/lib/v2/bossdesign/maintainer.js +3 -0
  30. package/lib/v2/bossdesign/radar.js +13 -0
  31. package/lib/v2/bossdesign/router.js +3 -0
  32. package/lib/v2/brave/latest.js +4 -2
  33. package/lib/v2/buaa/maintainer.js +4 -0
  34. package/lib/v2/buaa/news/index.js +46 -0
  35. package/lib/v2/buaa/radar.js +21 -0
  36. package/lib/v2/buaa/router.js +4 -0
  37. package/lib/v2/buaa/sme.js +59 -0
  38. package/lib/v2/cfachina/analygarden.js +60 -0
  39. package/lib/v2/cfachina/maintainer.js +3 -0
  40. package/lib/v2/cfachina/radar.js +13 -0
  41. package/lib/v2/cfachina/router.js +3 -0
  42. package/lib/v2/cna/maintainer.js +1 -0
  43. package/lib/v2/cna/radar.js +6 -0
  44. package/lib/v2/cna/router.js +1 -0
  45. package/lib/v2/cna/web/index.js +62 -0
  46. package/lib/v2/cste/radar.js +1 -1
  47. package/lib/v2/dahecube/radar.js +40 -4
  48. package/lib/v2/dongqiudi/utils.js +1 -1
  49. package/lib/v2/douban/maintainer.js +1 -0
  50. package/lib/v2/douban/other/discussion.js +58 -0
  51. package/lib/v2/douban/radar.js +8 -0
  52. package/lib/v2/douban/router.js +1 -0
  53. package/lib/v2/dut/defaults.js +4 -0
  54. package/lib/v2/dut/index.js +21 -9
  55. package/lib/v2/dut/maintainer.js +8 -7
  56. package/lib/v2/dut/radar.js +37 -29
  57. package/lib/v2/dut/shortcuts.js +5 -0
  58. package/lib/v2/egsea/flash.js +30 -0
  59. package/lib/v2/egsea/maintainer.js +3 -0
  60. package/lib/v2/egsea/radar.js +13 -0
  61. package/lib/v2/egsea/router.js +3 -0
  62. package/lib/v2/fisher-spb/news.js +1 -2
  63. package/lib/v2/fosshub/radar.js +1 -1
  64. package/lib/v2/fxiaoke/crm.js +63 -0
  65. package/lib/v2/fxiaoke/maintainer.js +3 -0
  66. package/lib/v2/fxiaoke/radar.js +37 -0
  67. package/lib/v2/fxiaoke/router.js +3 -0
  68. package/lib/v2/gdsrx/index.js +72 -0
  69. package/lib/v2/gdsrx/maintainer.js +3 -0
  70. package/lib/v2/gdsrx/radar.js +61 -0
  71. package/lib/v2/gdsrx/router.js +3 -0
  72. package/lib/v2/gogoanimehd/radar.js +1 -1
  73. package/lib/v2/gogoanimehd/recent-releases.js +1 -1
  74. package/lib/v2/google/alerts.js +33 -0
  75. package/lib/v2/google/maintainer.js +1 -0
  76. package/lib/v2/google/router.js +1 -0
  77. package/lib/v2/gov/maintainer.js +9 -2
  78. package/lib/v2/gov/moa/zdscxx.js +104 -0
  79. package/lib/v2/gov/mot/index.js +66 -0
  80. package/lib/v2/gov/nea/ghs.js +58 -0
  81. package/lib/v2/gov/nifdc/index.js +40 -33
  82. package/lib/v2/gov/radar.js +232 -4
  83. package/lib/v2/gov/router.js +10 -2
  84. package/lib/v2/gov/safe/business.js +8 -0
  85. package/lib/v2/gov/safe/complaint.js +8 -0
  86. package/lib/v2/gov/safe/templates/message.art +25 -0
  87. package/lib/v2/gov/safe/util.js +87 -0
  88. package/lib/v2/gov/zhengce/index.js +99 -0
  89. package/lib/v2/greasyfork/maintainer.js +1 -0
  90. package/lib/v2/greasyfork/router.js +1 -0
  91. package/lib/v2/greasyfork/scripts.js +25 -20
  92. package/lib/{routes/universities → v2}/harvard/health/blog.js +8 -7
  93. package/lib/v2/harvard/maintainer.js +3 -0
  94. package/lib/v2/harvard/radar.js +13 -0
  95. package/lib/v2/harvard/router.js +3 -0
  96. package/lib/v2/huxiu/briefColumn.js +13 -25
  97. package/lib/v2/huxiu/channel.js +28 -0
  98. package/lib/v2/huxiu/club.js +30 -0
  99. package/lib/v2/huxiu/collection.js +14 -26
  100. package/lib/v2/huxiu/maintainer.js +8 -5
  101. package/lib/v2/huxiu/member.js +27 -0
  102. package/lib/v2/huxiu/moment.js +11 -25
  103. package/lib/v2/huxiu/radar.js +24 -16
  104. package/lib/v2/huxiu/router.js +7 -4
  105. package/lib/v2/huxiu/search.js +16 -21
  106. package/lib/v2/huxiu/tag.js +13 -25
  107. package/lib/v2/huxiu/templates/description.art +46 -0
  108. package/lib/v2/huxiu/util.js +460 -0
  109. package/lib/v2/ifi-audio/maintainer.js +1 -1
  110. package/lib/v2/imiker/jinghua.js +87 -0
  111. package/lib/v2/imiker/maintainer.js +3 -0
  112. package/lib/v2/imiker/radar.js +13 -0
  113. package/lib/v2/imiker/router.js +3 -0
  114. package/lib/v2/imiker/templates/description.art +32 -0
  115. package/lib/v2/inoreader/maintainer.js +1 -1
  116. package/lib/v2/instagram/common-utils.js +7 -4
  117. package/lib/v2/instagram/templates/images.art +9 -2
  118. package/lib/v2/instagram/templates/video.art +4 -1
  119. package/lib/v2/instagram/web-api/index.js +30 -9
  120. package/lib/v2/instagram/web-api/utils.js +149 -25
  121. package/lib/v2/kemono/index.js +26 -2
  122. package/lib/v2/kemono/radar.js +1 -1
  123. package/lib/v2/kepu/live.js +89 -0
  124. package/lib/v2/kepu/maintainer.js +3 -0
  125. package/lib/v2/kepu/radar.js +13 -0
  126. package/lib/v2/kepu/router.js +3 -0
  127. package/lib/v2/kepu/templates/description.art +33 -0
  128. package/lib/v2/leetcode/maintainer.js +1 -1
  129. package/lib/v2/lightnovel/lightNovel.js +62 -0
  130. package/lib/v2/lightnovel/maintainer.js +3 -0
  131. package/lib/v2/lightnovel/radar.js +13 -0
  132. package/lib/v2/lightnovel/router.js +3 -0
  133. package/lib/v2/line/radar.js +1 -1
  134. package/lib/v2/liquipedia/cs_matches.js +52 -0
  135. package/lib/v2/liquipedia/dota2_matches.js +47 -0
  136. package/lib/v2/liquipedia/maintainer.js +4 -0
  137. package/lib/v2/liquipedia/radar.js +19 -0
  138. package/lib/v2/liquipedia/router.js +4 -0
  139. package/lib/v2/magazinelib/maintainer.js +1 -1
  140. package/lib/v2/mihoyo/radar.js +1 -1
  141. package/lib/v2/missav/maintainer.js +3 -0
  142. package/lib/v2/missav/new.js +36 -0
  143. package/lib/v2/missav/radar.js +13 -0
  144. package/lib/v2/missav/router.js +3 -0
  145. package/lib/v2/missav/templates/preview.art +3 -0
  146. package/lib/v2/modb/maintainer.js +3 -0
  147. package/lib/v2/modb/radar.js +13 -0
  148. package/lib/v2/modb/router.js +3 -0
  149. package/lib/v2/modb/topic.js +59 -0
  150. package/lib/v2/nature/cover.js +32 -42
  151. package/lib/v2/nature/highlight.js +2 -2
  152. package/lib/v2/nature/news-and-comment.js +2 -2
  153. package/lib/v2/nature/news.js +2 -2
  154. package/lib/v2/nature/research.js +2 -2
  155. package/lib/v2/nature/siteindex.js +5 -5
  156. package/lib/v2/nature/utils.js +124 -5
  157. package/lib/v2/ncu/jwc.js +33 -0
  158. package/lib/v2/ncu/maintainer.js +3 -0
  159. package/lib/v2/ncu/radar.js +13 -0
  160. package/lib/v2/ncu/router.js +3 -0
  161. package/lib/v2/nmtv/radar.js +1 -1
  162. package/lib/v2/oo-software/radar.js +1 -1
  163. package/lib/v2/patagonia/maintainer.js +1 -1
  164. package/lib/v2/phoronix/index.js +177 -48
  165. package/lib/v2/phoronix/maintainer.js +1 -1
  166. package/lib/v2/phoronix/radar.js +3 -3
  167. package/lib/v2/phoronix/router.js +1 -1
  168. package/lib/v2/picnob/maintainer.js +1 -1
  169. package/lib/v2/picnob/templates/desc.art +3 -3
  170. package/lib/v2/picnob/user.js +74 -37
  171. package/lib/v2/picnob/utils.js +24 -0
  172. package/lib/v2/qbitai/category.js +27 -0
  173. package/lib/v2/qbitai/maintainer.js +4 -0
  174. package/lib/v2/qbitai/radar.js +19 -0
  175. package/lib/v2/qbitai/router.js +4 -0
  176. package/lib/v2/qbitai/tag.js +27 -0
  177. package/lib/v2/questmobile/maintainer.js +3 -0
  178. package/lib/v2/questmobile/radar.js +18 -0
  179. package/lib/v2/questmobile/report.js +127 -0
  180. package/lib/v2/questmobile/router.js +3 -0
  181. package/lib/v2/questmobile/templates/description.art +17 -0
  182. package/lib/v2/readhub/daily.js +43 -0
  183. package/lib/v2/readhub/index.js +19 -72
  184. package/lib/v2/readhub/maintainer.js +1 -0
  185. package/lib/v2/readhub/radar.js +6 -0
  186. package/lib/v2/readhub/router.js +1 -0
  187. package/lib/v2/readhub/util.js +69 -0
  188. package/lib/v2/routledge/book-series.js +78 -0
  189. package/lib/v2/routledge/maintainer.js +3 -0
  190. package/lib/v2/routledge/radar.js +13 -0
  191. package/lib/v2/routledge/router.js +3 -0
  192. package/lib/v2/routledge/templates/description.art +7 -0
  193. package/lib/v2/showstart/artist.js +15 -0
  194. package/lib/v2/showstart/brand.js +15 -0
  195. package/lib/v2/showstart/const.js +4 -0
  196. package/lib/v2/showstart/event.js +18 -0
  197. package/lib/v2/showstart/maintainer.js +6 -0
  198. package/lib/v2/showstart/radar.js +40 -0
  199. package/lib/v2/showstart/router.js +6 -0
  200. package/lib/v2/showstart/search.js +51 -0
  201. package/lib/v2/showstart/service.js +166 -0
  202. package/lib/v2/showstart/utils.js +92 -0
  203. package/lib/v2/snowpeak/maintainer.js +1 -1
  204. package/lib/v2/sony/maintainer.js +1 -1
  205. package/lib/v2/sse/disclosure.js +4 -3
  206. package/lib/v2/sspu/jwc.js +44 -0
  207. package/lib/v2/sspu/maintainer.js +3 -0
  208. package/lib/v2/sspu/radar.js +13 -0
  209. package/lib/v2/sspu/router.js +3 -0
  210. package/lib/v2/techcrunch/maintainer.js +1 -1
  211. package/lib/v2/theatlantic/maintainer.js +1 -1
  212. package/lib/v2/thepaper/radar.js +2 -2
  213. package/lib/v2/threads/index.js +20 -150
  214. package/lib/v2/threads/utils.js +147 -0
  215. package/lib/v2/twitter/keyword.js +1 -3
  216. package/lib/v2/twitter/media.js +1 -5
  217. package/lib/v2/twitter/user.js +1 -3
  218. package/lib/v2/twitter/utils.js +5 -3
  219. package/lib/v2/twitter/web-api/constants.js +80 -68
  220. package/lib/v2/twitter/web-api/twitter-api.js +96 -103
  221. package/lib/v2/uniqlo/maintainer.js +3 -0
  222. package/lib/v2/uniqlo/new.js +62 -0
  223. package/lib/v2/uniqlo/radar.js +12 -0
  224. package/lib/v2/uniqlo/router.js +3 -0
  225. package/lib/v2/wechat/maintainer.js +1 -1
  226. package/lib/v2/weibo/maintainer.js +1 -1
  227. package/lib/v2/weibo/radar.js +1 -1
  228. package/lib/v2/weibo/router.js +1 -1
  229. package/lib/v2/weibo/search/hot.js +118 -7
  230. package/lib/v2/weibo/search/template/digest.art +17 -0
  231. package/lib/v2/xiaohongshu/util.js +17 -7
  232. package/lib/v2/xmnn/docs.js +0 -0
  233. package/lib/v2/xmnn/maintainer.js +1 -0
  234. package/lib/v2/xmnn/news.js +65 -0
  235. package/lib/v2/xmnn/radar.js +67 -1
  236. package/lib/v2/xmnn/router.js +1 -0
  237. package/lib/v2/xsijishe/maintainer.js +1 -0
  238. package/lib/v2/xsijishe/radar.js +12 -0
  239. package/lib/v2/xsijishe/rank.js +60 -0
  240. package/lib/v2/xsijishe/router.js +1 -0
  241. package/lib/v2/yahoo/maintainer.js +2 -0
  242. package/lib/v2/yahoo/news/tw/index.js +24 -0
  243. package/lib/v2/yahoo/news/tw/provider-helper.js +22 -0
  244. package/lib/v2/yahoo/news/tw/provider.js +24 -0
  245. package/lib/v2/yahoo/news/tw/utils.js +129 -0
  246. package/lib/v2/yahoo/radar.js +29 -1
  247. package/lib/v2/yahoo/router.js +4 -1
  248. package/lib/v2/yahoo/templates/youtube.art +1 -0
  249. package/lib/v2/yuque/book.js +6 -1
  250. package/lib/v2/yuque/utils.js +16 -0
  251. package/lib/v2/zagg/maintainer.js +1 -1
  252. package/lib/views/error.art +1 -1
  253. package/lib/views/rss3-ums.js +62 -0
  254. package/lib/views/welcome.art +1 -1
  255. package/package.json +45 -39
  256. package/lib/routes/egsea/flash.js +0 -40
  257. package/lib/routes/gov/moa/sjzxfb.js +0 -20
  258. package/lib/routes/liquipedia/dota2_matches.js +0 -50
  259. package/lib/routes/questmobile/report.js +0 -121
  260. package/lib/routes/uniqlo/stylingbook.js +0 -24
  261. package/lib/routes/universities/buaa/news/index.js +0 -66
  262. package/lib/routes/universities/buaa/utils.js +0 -57
  263. package/lib/v2/gov/zhengce/zuixin.js +0 -39
  264. package/lib/v2/huxiu/article.js +0 -33
  265. package/lib/v2/huxiu/author.js +0 -36
  266. package/lib/v2/huxiu/templates/brief.art +0 -22
  267. package/lib/v2/huxiu/templates/img.art +0 -3
  268. package/lib/v2/huxiu/templates/moment.art +0 -16
  269. package/lib/v2/huxiu/templates/video.art +0 -7
  270. package/lib/v2/huxiu/utils.js +0 -154
  271. package/lib/v2/twitter/web-api/twitter-got.js +0 -113
  272. /package/lib/{routes → v2}/gov/moa/moa.js +0 -0
  273. /package/lib/v2/yahoo/news/{index.js → us/index.js} +0 -0
@@ -1,22 +0,0 @@
1
- {{ if brief.preface }}{{@ brief.preface }}<br>{{ /if }}
2
-
3
- {{ if brief.audio_info }}
4
- <figure>
5
- <figcaption>{{ brief.audio_title }}</figcaption>
6
- <audio controls src="{{ brief.audio_info.audio_path }}"></audio>
7
- </figure>
8
- <br>
9
- {{ /if }}
10
-
11
- {{ if brief.part_list }}{{ each brief.part_list part }}
12
- {{ if part.title }}<h2>{{ part.title }}</h2>{{ /if }}
13
- {{ if part.content_info }}{{ each part.content_info content }}
14
- {{ if content.type === 'text' }}{{@ content.text }}{{ /if }}
15
- {{ if content.type === 'video' }}
16
- <video controls poster="{{ content.video.poster }}"><source src="{{ content.video.url }}" type="video/mp4"></video>
17
- {{ /if }}
18
- {{ if content.type === 'image'}}{{ /if }}
19
- {{ /each }}<br>{{ /if }}
20
- {{ /each }}{{ /if }}
21
-
22
- {{ if brief.peroration }}{{ brief.peroration }}{{ /if }}
@@ -1,3 +0,0 @@
1
- {{ if img }}
2
- <img src="{{ img }}">
3
- {{ /if }}
@@ -1,16 +0,0 @@
1
- {{@ description }}
2
- {{ if images }}
3
- {{ each images image }}
4
- <img src="{{ image.origin_pic }}" width="{{ image.origin_width }}" height="{{ image.origin_height }}">
5
- {{ /each }}
6
- {{ /if }}
7
- {{ if video }}
8
- <video width="{{ video.width }}" height="{{ video.height }}" poster="{{ video.cover_path }}" controls>
9
- <source src="{{ video.url }}" type="video/{{ video.format }}">
10
- </video>
11
- {{ /if }}
12
- {{ if comments }}
13
- {{ each comments.datalist comment }}
14
- <p>{{ comment.user_info.username }}: {{ comment.content }} ({{ comment.show_time }})</p>
15
- {{ /each }}
16
- {{ /if }}
@@ -1,7 +0,0 @@
1
- {{ if video_info }}
2
- <video controls poster="{{ video_info.cover }}" width="{{ video_info.width }}" height="{{ video_info.height }}">
3
- {{ if video_info.fhd_link }}<source src="{{ video_info.fhd_link }}" type="video/mp4">{{ /if }}
4
- {{ if video_info.hd_link }}<source src="{{ video_info.hd_link }}" type="video/mp4">{{ /if }}
5
- {{ if video_info.sd_link }}<source src="{{ video_info.sd_link }}" type="video/mp4">{{ /if }}
6
- </video>
7
- {{ /if }}
@@ -1,154 +0,0 @@
1
- const cheerio = require('cheerio');
2
- const { parseDate } = require('@/utils/parse-date');
3
- const got = require('@/utils/got');
4
- const { art } = require('@/utils/render');
5
- const path = require('path');
6
- const CryptoJS = require('crypto-js');
7
-
8
- const accountApi = 'https://account-api.huxiu.com';
9
- const articleApi = 'https://api-article.huxiu.com';
10
- const baseUrl = 'https://www.huxiu.com';
11
- const briefApi = 'https://api-brief.huxiu.com';
12
- const momentApi = 'https://moment-api.huxiu.com';
13
- const searchApi = 'https://search-api.huxiu.com';
14
-
15
- const ProcessFeed = (list, cache) =>
16
- Promise.all(
17
- list.map((item) =>
18
- cache.tryGet(item.link, async () => {
19
- const response = await got(item.link, {
20
- https: {
21
- rejectUnauthorized: false,
22
- },
23
- });
24
- const $ = cheerio.load(response.data);
25
- const initialState = parseInitialState($);
26
-
27
- if (item.link.startsWith(`${baseUrl}/article/`)) {
28
- fetchArticle(initialState, item);
29
- } else if (item.link.startsWith(`${baseUrl}/brief/`)) {
30
- fetchBrief(initialState, item);
31
- }
32
-
33
- return item;
34
- })
35
- )
36
- );
37
-
38
- const fetchArticle = (initialState, item) => {
39
- const { articleDetail } = initialState.articleDetail;
40
- const topImg = art(path.join(__dirname, 'templates/img.art'), {
41
- img: articleDetail.pic_path.split('?')[0],
42
- });
43
- let video = '';
44
- if (articleDetail.video_info) {
45
- video = art(path.join(__dirname, 'templates/video.art'), {
46
- video_info: articleDetail.video_info,
47
- });
48
- }
49
-
50
- const $ = cheerio.load(articleDetail.content, null, false);
51
-
52
- $('.text-big-title').each((_, e) => (e.tagName = 'h3'));
53
- fixImg($);
54
- removeExtraLinebreak($);
55
- // $('img.dialog_add_wxxy_qrcode_icon').remove();
56
-
57
- item.description = video + topImg + $.html();
58
- item.author = articleDetail.author;
59
- item.category = articleDetail.tags_info.map((tag) => tag.name);
60
- };
61
-
62
- const fetchBrief = (initialState, item) => {
63
- const { brief_detail } = initialState.briefStoreModule;
64
- const { brief_column } = brief_detail;
65
-
66
- const description = art(path.join(__dirname, 'templates/brief.art'), {
67
- brief: brief_detail.brief,
68
- });
69
-
70
- const $ = cheerio.load(description, null, false);
71
-
72
- $('button.black-dot').remove();
73
- fixImg($);
74
- removeExtraLinebreak($);
75
-
76
- item.description = $.html();
77
- item.author = brief_detail.brief.publisher_list.map((item) => item.username).join(', ');
78
- item.pubDate = parseDate(brief_column.update_time, 'X');
79
- };
80
-
81
- const parseInitialState = ($) =>
82
- JSON.parse(
83
- $('script')
84
- .text()
85
- .match(/window\.__INITIAL_STATE__=(\{.*?\});\(function\(\)/)[1]
86
- );
87
-
88
- const fixImg = ($) => {
89
- $('img.lazyImg, img.js-preview').each((_, e) => {
90
- if (e.attribs._src) {
91
- e.attribs.src = e.attribs._src.split('?')[0];
92
- delete e.attribs._src;
93
- }
94
- if (e.attribs.src.includes('?')) {
95
- e.attribs.src = e.attribs.src.split('?')[0];
96
- }
97
- if (e.attribs['data-w']) {
98
- e.attribs.width = e.attribs['data-w'];
99
- delete e.attribs['data-w'];
100
- }
101
- if (e.attribs['data-h']) {
102
- e.attribs.height = e.attribs['data-h'];
103
- delete e.attribs['data-h'];
104
- }
105
- });
106
- };
107
-
108
- const removeExtraLinebreak = ($) => {
109
- $('p').each((_, e) => {
110
- e = $(e);
111
- if (e.find('img').length === 0 && e.text().match(/^\s*$/)) {
112
- e.remove();
113
- }
114
- });
115
- };
116
-
117
- const generateNonce = () => {
118
- let nonce = '';
119
- const e = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
120
- const t = 16;
121
- for (let i = 0; i < t; i++) {
122
- nonce += e.charAt(Math.floor(Math.random() * e.length));
123
- }
124
- return nonce;
125
- };
126
-
127
- const generateSignature = () => {
128
- const timestamp = Math.round(new Date().getTime() / 1000).toString();
129
- // const appSecret = '4nHzGgGt7WX4zFTsTKocpxg4dzU6-wUi';
130
- const appSecret = 'hUzaVKtNfDE-6UiyaJdfsmjW-8dwoyVc'; // appid: 'hx_search'
131
- const nonce = generateNonce();
132
- const r = [appSecret, timestamp, nonce].sort();
133
- return {
134
- nonce,
135
- timestamp,
136
- signature: CryptoJS.SHA1(r[0] + r[1] + r[2]).toString(),
137
- };
138
- };
139
-
140
- module.exports = {
141
- accountApi,
142
- articleApi,
143
- baseUrl,
144
- briefApi,
145
- momentApi,
146
- searchApi,
147
- ProcessFeed,
148
- fetchArticle,
149
- fetchBrief,
150
- parseInitialState,
151
- fixImg,
152
- removeExtraLinebreak,
153
- generateSignature,
154
- };
@@ -1,113 +0,0 @@
1
- const { CookieJar, Cookie } = require('tough-cookie');
2
- const { promisify } = require('util');
3
- const queryString = require('query-string');
4
- const got = require('@/utils/got');
5
- const config = require('@/config').value;
6
- const constants = require('./constants');
7
-
8
- const tokens = config.twitter.authorization && config.twitter.authorization.length ? config.twitter.authorization : constants.tokens;
9
-
10
- // https://github.com/mikf/gallery-dl/blob/a53cfc845e12d9e98fefd07e43ebffaec488c18f/gallery_dl/extractor/twitter.py#L716-L726
11
- const headers = {
12
- authorization: undefined,
13
- 'x-guest-token': undefined,
14
- 'x-twitter-auth-type': undefined,
15
- 'x-twitter-client-language': 'en',
16
- 'x-twitter-active-user': 'yes',
17
- 'x-csrf-token': undefined,
18
- Referer: 'https://twitter.com/',
19
- };
20
-
21
- let cookieJar,
22
- setCookie,
23
- getCookies,
24
- tries = 0;
25
-
26
- const cookiedomain = 'twitter.com';
27
- const cookieurl = 'https://twitter.com';
28
-
29
- async function twitterGot(options) {
30
- const response = await got({
31
- ...options,
32
- headers: { ...headers, ...(options.headers || {}) },
33
- cookieJar,
34
- });
35
- // 更新csrfToken
36
- for (const c of await getCookies(cookieurl)) {
37
- if (c.key === 'ct0') {
38
- headers['x-csrf-token'] = c.value;
39
- }
40
- }
41
- return response;
42
- }
43
-
44
- async function resetSession() {
45
- cookieJar = new CookieJar();
46
- getCookies = promisify(cookieJar.getCookies.bind(cookieJar));
47
- setCookie = promisify(cookieJar.setCookie.bind(cookieJar));
48
- let response;
49
- // auth
50
- let token = tokens[tries++ % tokens.length];
51
- if (!token.startsWith('Bearer')) {
52
- headers.authorization = `Basic ${Buffer.from(token).toString('base64')}`;
53
- response = await twitterGot({
54
- url: 'https://api.twitter.com/oauth2/token',
55
- method: 'POST',
56
- searchParams: queryString.stringify({ grant_type: 'client_credentials' }),
57
- });
58
- token = `Bearer ${response.data.access_token}`;
59
- }
60
- headers.authorization = token;
61
- // 生成csrf-token
62
- const csrfToken = [...Array(16 * 2)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
63
- await setCookie(new Cookie({ key: 'ct0', value: csrfToken, domain: cookiedomain, secure: false }), cookieurl);
64
- headers['x-csrf-token'] = csrfToken;
65
- headers['x-guest-token'] = undefined;
66
- // 发起初始化请求
67
- response = await twitterGot({
68
- url: 'https://api.twitter.com/1.1/guest/activate.json',
69
- method: 'POST',
70
- });
71
- // 获取guest-token
72
- // TODO: OAuth2Session, 参见 https://github.com/DIYgod/RSSHub/pull/7739#discussionR655932602
73
- const guestToken = response.data.guest_token;
74
- headers['x-guest-token'] = guestToken;
75
- await setCookie(new Cookie({ key: 'gt', value: guestToken, domain: cookiedomain, secure: false }), cookieurl);
76
- // 发起第二个初始化请求, 获取_twitter_sess
77
- await twitterGot({
78
- url: 'https://twitter.com/i/js_inst',
79
- method: 'GET',
80
- searchParams: queryString.stringify({ c_name: 'ui_metrics' }),
81
- });
82
- return cookieJar;
83
- }
84
-
85
- const initSession = () => cookieJar || resetSession();
86
-
87
- async function twitterRequest(url, params, method) {
88
- await initSession();
89
- // 发起请求
90
- const request = () =>
91
- twitterGot({
92
- url,
93
- method,
94
- searchParams: queryString.stringify(params),
95
- });
96
- let response;
97
- try {
98
- response = await request();
99
- } catch (e) {
100
- if (e.response.status === 403 || (e.response.status === 404 && !e.response.data)) {
101
- await resetSession();
102
- response = await request();
103
- } else {
104
- throw e;
105
- }
106
- }
107
- if (response.data.errors) {
108
- throw Error('API reports error:\n' + response.data.errors.map((e) => `${e.code}: ${e.message}`).join('\n'));
109
- }
110
- return response.data;
111
- }
112
-
113
- module.exports = twitterRequest;
File without changes
File without changes