fix(route): support full text (#12346)
This commit is contained in:
parent
4324159cba
commit
ffe7305fa2
|
|
@ -2,6 +2,8 @@ const got = require('@/utils/got');
|
|||
const queryString = require('query-string');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const rootUrl = 'https://xueqiu.com';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const type = ctx.params.type || 10;
|
||||
|
|
@ -17,13 +19,13 @@ module.exports = async (ctx) => {
|
|||
|
||||
const res1 = await got({
|
||||
method: 'get',
|
||||
url: 'https://xueqiu.com/',
|
||||
url: rootUrl,
|
||||
});
|
||||
const token = res1.headers['set-cookie'].find((s) => s.startsWith('xq_a_token=')).split(';')[0];
|
||||
|
||||
const res2 = await got({
|
||||
method: 'get',
|
||||
url: 'https://xueqiu.com/v4/statuses/user_timeline.json',
|
||||
url: `${rootUrl}/v4/statuses/user_timeline.json`,
|
||||
searchParams: queryString.stringify({
|
||||
user_id: id,
|
||||
type,
|
||||
|
|
@ -31,24 +33,43 @@ module.exports = async (ctx) => {
|
|||
}),
|
||||
headers: {
|
||||
Cookie: token,
|
||||
Referer: `https://xueqiu.com/u/${id}`,
|
||||
Referer: `${rootUrl}/u/${id}`,
|
||||
},
|
||||
});
|
||||
const data = res2.data.statuses.filter((s) => s.mark !== 1); // 去除置顶动态
|
||||
|
||||
const items = await Promise.all(
|
||||
data.map((item) =>
|
||||
ctx.cache.tryGet(item.target, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: rootUrl + item.target,
|
||||
headers: {
|
||||
Referer: `${rootUrl}/u/${id}`,
|
||||
Cookie: token,
|
||||
},
|
||||
});
|
||||
|
||||
const data = JSON.parse(detailResponse.data.match(/SNOWMAN_STATUS = (.*?});/)[1]);
|
||||
item.text = data.text;
|
||||
|
||||
const retweetedStatus = item.retweeted_status ? `<blockquote>${item.retweeted_status.user.screen_name}: ${item.retweeted_status.description}</blockquote>` : '';
|
||||
const description = item.description + retweetedStatus;
|
||||
|
||||
return {
|
||||
title: item.title ? item.title : description.replace(/<[^>]+>/g, ''),
|
||||
description: item.text ? item.text + retweetedStatus : description,
|
||||
pubDate: parseDate(item.created_at),
|
||||
link: rootUrl + item.target,
|
||||
};
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data[0].user.screen_name} 的雪球${typename[type]}动态`,
|
||||
link: `https://xueqiu.com/u/${id}`,
|
||||
link: `${rootUrl}/u/${id}`,
|
||||
description: `${data[0].user.screen_name} 的雪球${typename[type]}动态`,
|
||||
item: data.map((item) => {
|
||||
const retweetedStatus = item.retweeted_status ? `<blockquote>${item.retweeted_status.user.screen_name}: ${item.retweeted_status.description}</blockquote>` : '';
|
||||
const description = item.description + retweetedStatus;
|
||||
return {
|
||||
title: item.title ? item.title : description.replace(/<[^>]+>/g, ''),
|
||||
description: item.text ? item.text + retweetedStatus : description,
|
||||
pubDate: parseDate(item.created_at),
|
||||
link: `https://xueqiu.com${item.target}`,
|
||||
};
|
||||
}),
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue