feat(route): Update wmpvp news description (#14848)

This commit is contained in:
tssujt 2024-03-19 15:58:45 +08:00 committed by GitHub
parent eaf6fffb3d
commit 5ef9ae6c73
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 14 deletions

View File

@ -1,4 +1,5 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
@ -37,21 +38,28 @@ async function handler(ctx) {
});
const data = response.data.result.filter((item) => item.news !== undefined);
const items = data.map((item) => {
const entity = item.news;
const newsId = entity.newsId;
const newsLink = `https://news.wmpvp.com/news.html?id=${newsId}&gameTypeStr=${type}`;
const items = await Promise.all(
data.map((item) => {
const entity = item.news;
const newsId = entity.newsId;
const newsLink = `https://news.wmpvp.com/news.html?id=${newsId}&gameTypeStr=${type}`;
// 最终需要返回的对象
return {
title: entity.title,
pubDate: parseDate(entity.publishTime),
link: newsLink,
guid: newsLink,
description: entity.summary,
author: entity.author,
};
});
return cache.tryGet(newsLink, async () => {
const detailResponse = await got({
method: 'get',
url: `https://appactivity.wmpvp.com/steamcn/app/news/getAppNewsById?gameType=${type}&newsId=${newsId}`,
});
return {
title: entity.title,
pubDate: parseDate(entity.publishTime),
link: newsLink,
guid: newsLink,
author: entity.author,
description: detailResponse.data.result.news.content,
};
});
})
);
return {
title: `完美世界电竞 - ${TYPE_MAP[type]} 资讯`,