From e2d6718fa2193b43a78d584922a2188c4230c7c1 Mon Sep 17 00:00:00 2001 From: sirius60111 Date: Sun, 14 Apr 2024 19:24:28 +0800 Subject: [PATCH] fix(route): xueqiu user-stock (#15226) --- lib/routes/xueqiu/user-stock.ts | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/routes/xueqiu/user-stock.ts b/lib/routes/xueqiu/user-stock.ts index 87aa20a0f..02e6490b3 100644 --- a/lib/routes/xueqiu/user-stock.ts +++ b/lib/routes/xueqiu/user-stock.ts @@ -1,6 +1,5 @@ import { Route } from '@/types'; -import got from '@/utils/got'; -import queryString from 'query-string'; +import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; export const route: Route = { @@ -29,34 +28,32 @@ export const route: Route = { async function handler(ctx) { const id = ctx.req.param('id'); - const res1 = await got({ - method: 'get', - url: 'https://xueqiu.com/', - }); - const token = res1.headers['set-cookie'].find((s) => s.startsWith('xq_a_token=')).split(';')[0]; + const { headers } = await ofetch.raw('https://xueqiu.com/'); + const token = headers + ?.getSetCookie() + .find((s) => s.startsWith('xq_a_token=')) + ?.split(';')[0] as string; - const res2 = await got({ - method: 'get', - url: `https://stock.xueqiu.com/v5/stock/portfolio/stock/list.json?category=1&size=1000&uid=${id}`, + const { + data: { stocks: data }, + } = await ofetch(`https://stock.xueqiu.com/v5/stock/portfolio/stock/list.json?category=1&size=1000&uid=${id}`, { headers: { Cookie: token, Referer: `https://xueqiu.com/u/${id}`, }, }); - const data = res2.data.data.stocks; - const res3 = await got({ - method: 'get', - url: 'https://xueqiu.com/statuses/original/show.json', - searchParams: queryString.stringify({ + const { + user: { screen_name }, + } = await ofetch('https://xueqiu.com/statuses/original/show.json', { + query: { user_id: id, - }), + }, headers: { Cookie: token, Referer: `https://xueqiu.com/u/${id}`, }, }); - const screen_name = res3.data.user.screen_name; return { title: `${screen_name} 的雪球自选动态`,