From 810aae3997d9d130a786ee77b218479746bba5e2 Mon Sep 17 00:00:00 2001 From: Luke Zhu Date: Fri, 13 Sep 2024 22:13:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BE=AE=E5=8D=9A=E8=B6=85=E8=AF=9D?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90=E9=94=99=E8=AF=AF=20(#1670?= =?UTF-8?q?9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 微博超话有效数据在最外层 * chore: any type * chore: any type --- lib/routes/weibo/super-index.ts | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/routes/weibo/super-index.ts b/lib/routes/weibo/super-index.ts index f4da6960f39cd..c414d9ce5c494 100644 --- a/lib/routes/weibo/super-index.ts +++ b/lib/routes/weibo/super-index.ts @@ -37,11 +37,15 @@ export const route: Route = { | feed | 最新评论 |`, }; +interface Card { + card_group?: Card[]; +} + async function handler(ctx) { const id = ctx.req.param('id'); const type = ctx.req.param('type') ?? 'feed'; - const containerData = await cache.tryGet( + const containerData = (await cache.tryGet( `weibo:super_index:container:${id}:${type}`, async () => { const _r = await got('https://m.weibo.cn/api/container/getIndex', { @@ -61,27 +65,35 @@ async function handler(ctx) { }, config.cache.routeExpire, false - ); + )) as { + cards?: Card[]; + pageInfo?: { + page_title: string; + }; + }; const resultItems = []; - for (const card of containerData.cards) { + function handleCard(ctx, card, resultItems) { + if (card.card_type === '9' && 'mblog' in card) { + const formatExtended = weiboUtils.formatExtended(ctx, card.mblog, undefined); + resultItems.push(formatExtended); + } + } + for (const card of containerData?.cards ?? []) { + handleCard(ctx, card, resultItems); if (!('card_group' in card)) { continue; } - for (const mblogCard of card.card_group) { - if (mblogCard.card_type === '9' && 'mblog' in mblogCard) { - const mblog = mblogCard.mblog; - const formatExtended = weiboUtils.formatExtended(ctx, mblog); - resultItems.push(formatExtended); - } + for (const mblogCard of card.card_group!) { + handleCard(ctx, mblogCard, resultItems); } } return weiboUtils.sinaimgTvax({ - title: `微博超话 - ${containerData.pageInfo.page_title}`, + title: `微博超话 - ${containerData?.pageInfo?.page_title}`, link: `https://weibo.com/p/${id}/super_index`, - description: `#${containerData.pageInfo.page_title}# 的超话`, + description: `#${containerData?.pageInfo?.page_title}# 的超话`, item: resultItems, }); }