Skip to content

Commit

Permalink
fix: 微博超话数据解析错误 (#16709)
Browse files Browse the repository at this point in the history
* fix: 微博超话有效数据在最外层

* chore: any type

* chore: any type
  • Loading branch information
luke358 committed Sep 13, 2024
1 parent 8b8dc04 commit 810aae3
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions lib/routes/weibo/super-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand All @@ -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,
});
}

0 comments on commit 810aae3

Please sign in to comment.