fix(route): xueqiu token url (#17225)

This commit is contained in:
Tony
2024-10-21 23:59:08 +08:00
committed by GitHub
parent ec16c68c93
commit e845943158
6 changed files with 26 additions and 22 deletions
+3 -3
View File
@@ -3,11 +3,11 @@ import cache from '@/utils/cache';
import { config } from '@/config';
import { getAcwScV2ByArg1 } from '@/routes/5eplay/utils';
export const parseToken = () =>
export const parseToken = (link: string) =>
cache.tryGet(
'xueqiu:token',
async () => {
const r = await ofetch('https://xueqiu.com');
const r = await ofetch(link);
let acw_sc__v2 = '';
const matches = r.match(/var arg1='(.*?)';/);
@@ -15,7 +15,7 @@ export const parseToken = () =>
acw_sc__v2 = getAcwScV2ByArg1(matches[1]);
}
const acw_sc__v2_cookie = `acw_sc__v2=${acw_sc__v2}`;
const res = await ofetch.raw('https://xueqiu.com', {
const res = await ofetch.raw(link, {
headers: {
Cookie: acw_sc__v2_cookie,
},
+6 -4
View File
@@ -30,7 +30,9 @@ export const route: Route = {
async function handler(ctx) {
const id = ctx.req.param('id');
const token = await parseToken();
const link = `https://xueqiu.com/u/${id}`;
const token = await parseToken(link);
const res2 = await got({
method: 'get',
url: 'https://xueqiu.com/favorites.json',
@@ -39,7 +41,7 @@ async function handler(ctx) {
}),
headers: {
Cookie: token,
Referer: `https://xueqiu.com/u/${id}`,
Referer: link,
},
});
const data = res2.data.list;
@@ -52,13 +54,13 @@ async function handler(ctx) {
},
headers: {
Cookie: token,
Referer: `https://xueqiu.com/u/${id}`,
Referer: link,
},
});
return {
title: `${screen_name} 的雪球收藏动态`,
link: `https://xueqiu.com/u/${id}`,
link,
description: `${screen_name} 的雪球收藏动态`,
item: data.map((item) => ({
title: item.title,
+6 -6
View File
@@ -30,7 +30,7 @@ export const route: Route = {
};
async function handler() {
const token = await parseToken();
const token = await parseToken('https://xueqiu.com');
const res2 = await got({
method: 'get',
url: 'https://xueqiu.com/statuses/hots.json',
@@ -44,20 +44,20 @@ async function handler() {
}),
headers: {
Cookie: token,
Referer: `https://xueqiu.com/`,
Referer: 'https://xueqiu.com/',
},
});
const data = res2.data;
return {
title: `热帖 - 雪球`,
link: `https://xueqiu.com/`,
description: `雪球热门帖子`,
title: '热帖 - 雪球',
link: 'https://xueqiu.com/',
description: '雪球热门帖子',
item: data.map((item) => {
const description = item.text;
return {
title: item.title ?? sanitizeHtml(description, { allowedTags: [], allowedAttributes: {} }),
description: item.text,
description,
pubDate: parseDate(item.created_at),
link: `https://xueqiu.com${item.target}`,
author: item.user.screen_name,
+5 -4
View File
@@ -46,12 +46,13 @@ async function handler(ctx) {
};
const source = typename[type];
const link = `https://xueqiu.com/S/${id}`;
const res1 = await got({
method: 'get',
url: `https://xueqiu.com/S/${id}`,
url: link,
});
const token = await parseToken();
const token = await parseToken(link);
const $ = load(res1.data); // 使用 cheerio 加载返回的 HTML
const stock_name = $('.stock-name').text().split('(')[0];
@@ -73,14 +74,14 @@ async function handler(ctx) {
}),
headers: {
Cookie: token,
Referer: `https://xueqiu.com/u/${id}`,
Referer: link,
},
});
const data = res2.data.list;
return {
title: `${id} ${stock_name} - ${source}`,
link: `https://xueqiu.com/S/${id}`,
link,
description: `${stock_name} - ${source}`,
item: data.map((item) => ({
title: item.title || sanitizeHtml(item.description, { allowedTags: [], allowedAttributes: {} }),
+1 -1
View File
@@ -36,7 +36,7 @@ async function handler(ctx) {
const currentUrl = `${rootUrl}/today`;
const apiUrl = `${rootUrl}/statuses/hot/listV2.json?since_id=-1&size=${size}`;
const token = await parseToken();
const token = await parseToken(currentUrl);
const response = await got({
method: 'get',
url: apiUrl,
+5 -4
View File
@@ -48,7 +48,8 @@ async function handler(ctx) {
11: '交易',
};
const token = await parseToken();
const link = `${rootUrl}/u/${id}`;
const token = await parseToken(link);
const res2 = await got({
method: 'get',
url: `${rootUrl}/v4/statuses/user_timeline.json`,
@@ -59,7 +60,7 @@ async function handler(ctx) {
}),
headers: {
Cookie: token,
Referer: `${rootUrl}/u/${id}`,
Referer: link,
},
});
const data = res2.data.statuses.filter((s) => s.mark !== 1); // 去除置顶动态
@@ -71,7 +72,7 @@ async function handler(ctx) {
method: 'get',
url: rootUrl + item.target,
headers: {
Referer: `${rootUrl}/u/${id}`,
Referer: link,
Cookie: token,
},
});
@@ -94,7 +95,7 @@ async function handler(ctx) {
return {
title: `${data[0].user.screen_name} 的雪球${typename[type]}动态`,
link: `${rootUrl}/u/${id}`,
link,
description: `${data[0].user.screen_name} 的雪球${typename[type]}动态`,
item: items,
};