Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): fix images not displaying in msn news full text #18017

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/routes/msn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cache from '@/utils/cache';
import { load } from 'cheerio';

const apiKey = '0QfOX3Vn51YCzitbLaRkTTBadtWpgTN8NZLW0C1SEM';
const fetchedArticleContentHtmlImgRegex = /<img data-reference="image" data-document-id="cms\/api\/amp\/image\/([A-Za-z0-9]+)">/;

export const route: Route = {
path: '/:market/:name/:id',
Expand Down Expand Up @@ -54,10 +55,11 @@ export const route: Route = {
let articleId = parsedArticleUrl?.pathname.split('/').pop();
if (articleId?.startsWith('ar-')) {
articleId = articleId.substring(3);
const fetchedArticleContentHtml = (await cache.tryGet(articleId, async () => {
let fetchedArticleContentHtml = (await cache.tryGet(articleId, async () => {
KTachibanaM marked this conversation as resolved.
Show resolved Hide resolved
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
})) as string;
fetchedArticleContentHtml = fetchedArticleContentHtml.replace(fetchedArticleContentHtmlImgRegex, '<img src="https://img-s-msn-com.akamaized.net/tenant/amp/entityid/$1.img">');
articleContentHtml = fetchedArticleContentHtml;
KTachibanaM marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading