mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-05 12:21:31 +08:00
* fix(route): 修复 newrank 列举公众号文章的 URL; 增加缺少的 n-token 参数; 文档中说明必须自建 * fix(route): newrank: code review update * feat(route): 获取 newrank 得出的微信公众号链接的全文 * refactor: migrate to v2 ---------
66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
const got = require('@/utils/got');
|
|
const { finishArticleItem } = require('@/utils/wechat-mp');
|
|
const cheerio = require('cheerio');
|
|
const utils = require('./utils');
|
|
const config = require('@/config').value;
|
|
|
|
module.exports = async (ctx) => {
|
|
if (!config.newrank || !config.newrank.cookie) {
|
|
throw Error('newrank RSS is disabled due to the lack of <a href="https://docs.rsshub.app/install/#pei-zhi-bu-fen-rss-mo-kuai-pei-zhi">relevant config</a>');
|
|
}
|
|
const uid = ctx.params.wxid;
|
|
const nonce = utils.random_nonce(9);
|
|
const { data: summaryHTML } = await got({
|
|
method: 'get',
|
|
url: `https://www.newrank.cn/new/readDetial?account=${uid}`,
|
|
headers: {
|
|
Connection: 'keep-alive',
|
|
Cookie: config.newrank.cookie,
|
|
},
|
|
});
|
|
const summary$ = cheerio.load(summaryHTML);
|
|
const mainsrc = summary$('script')
|
|
.toArray()
|
|
.find((item) => (item.attribs.src || '').startsWith('/new/static/js/main.')).attribs.src;
|
|
const { data: mainScript } = await got({
|
|
method: 'get',
|
|
url: `https://www.newrank.cn${mainsrc}`,
|
|
});
|
|
const N_TOKEN_match = mainScript.match(/"N-Token":"([^"]+)/);
|
|
if (!N_TOKEN_match) {
|
|
throw Error('Cannot find n-token');
|
|
}
|
|
const N_TOKEN = N_TOKEN_match[1];
|
|
const response = await got({
|
|
method: 'post',
|
|
url: 'https://gw.newrank.cn/api/wechat/xdnphb/detail/v1/rank/article/lists',
|
|
headers: {
|
|
Connection: 'keep-alive',
|
|
Cookie: config.newrank.cookie,
|
|
'n-token': N_TOKEN,
|
|
},
|
|
form: {
|
|
account: uid,
|
|
nonce,
|
|
xyz: utils.decrypt_wechat_detail_xyz(uid, nonce),
|
|
},
|
|
});
|
|
const name = response.data.value.user.name;
|
|
const realTimeArticles = utils.flatten(response.data.value.realTimeArticles);
|
|
const articles = utils.flatten(response.data.value.articles);
|
|
const newArticles = realTimeArticles.concat(articles);
|
|
const items = newArticles.map((item) => ({
|
|
title: item.title,
|
|
description: '',
|
|
link: item.url,
|
|
pubDate: item.publicTime,
|
|
}));
|
|
await Promise.all(items.map((item) => finishArticleItem(ctx, item)));
|
|
|
|
ctx.state.data = {
|
|
title: name + ' - 微信公众号',
|
|
link: `https://www.newrank.cn/new/readDetial?account=${uid}`,
|
|
item: items,
|
|
};
|
|
};
|