diff --git a/lib/routes/msn/index.ts b/lib/routes/msn/index.ts index 93236eb490e812..5ca954bbeb7fcc 100644 --- a/lib/routes/msn/index.ts +++ b/lib/routes/msn/index.ts @@ -1,6 +1,7 @@ import { Route } from '@/types'; import ofetch from '@/utils/ofetch'; import { parseDate } from '@/utils/parse-date'; +import cache from '@/utils/cache'; import { load } from 'cheerio'; const apiKey = '0QfOX3Vn51YCzitbLaRkTTBadtWpgTN8NZLW0C1SEM'; @@ -44,13 +45,34 @@ export const route: Route = { const requestMuid = parsedSettings.fd_muid; const jsonData = await ofetch(`https://assets.msn.com/service/news/feed/pages/providerfullpage?market=${market}&query=newest&CommunityProfileId=${truncatedId}&apikey=${apiKey}&user=m-${requestMuid}`); - const items = jsonData.sections[0].cards.map((card) => ({ - title: card.title, - link: card.url, - description: card.abstract, - pubDate: parseDate(card.publishedDateTime), - category: [card.category], - })); + const items = await Promise.all( + jsonData.sections[0].cards.map(async (card) => { + let articleContentHtml = ''; + + const articleUrl = card.url; + const parsedArticleUrl = URL.parse(articleUrl); + let articleId = parsedArticleUrl?.pathname.split('/').pop(); + if (articleId?.startsWith('ar-')) { + articleId = articleId.substring(3); + const fetchedArticleContentHtml = (await cache.tryGet(articleId, async () => { + const articleData = await ofetch(`https://assets.msn.com/content/view/v2/Detail/${market}/${articleId}`); + return articleData.body; + })) as string; // cache article content for 3 months + articleContentHtml = fetchedArticleContentHtml; + } + + return { + title: card.title, + link: articleUrl, + description: card.abstract, + content: { + html: articleContentHtml, + }, + pubDate: parseDate(card.publishedDateTime), + category: [card.category], + }; + }) + ); const channelLink = `https://www.msn.com/${market}/channel/source/${name}/${id}`; return {