fix: 微博超话数据解析错误 (#16709)

* fix: 微博超话有效数据在最外层

* chore: any type

* chore: any type
This commit is contained in:
Luke Zhu 2024-09-13 22:13:09 +08:00 committed by GitHub
parent 8b8dc04eb1
commit 810aae3997
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 11 deletions

View File

@ -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,
});
}