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/nytimes): enhance full text fetch #17292

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions lib/routes/nytimes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function handler(ctx) {
const browser = await puppeteer();
const feed = await parser.parseURL(rssUrl);
const items = await Promise.all(
feed.items.splice(0, 10).map(async (item) => {
feed.items.splice(0, 3).map(async (item) => {
let link = item.link;

let response,
Expand Down Expand Up @@ -118,8 +118,9 @@ async function handler(ctx) {
if ($('.dual-btn').length > 0) {
hasEnVersion = true;
link = $('.dual-btn a').last().attr().href;

response = await utils.PuppeterGetter(ctx, browser, link);
if (link !== '') {
response = await utils.PuppeterGetter(ctx, browser, link);
}
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/routes/nytimes/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (request) => {
request.resourceType() === 'document' ? request.continue() : request.abort();
});
await page.goto(link, {
waitUntil: 'domcontentloaded',
if (request.url().includes('https://www.nytimes.com/svc/onsite-messaging/query') || request.url().includes('https://meter-svc.nytimes.com/meter.js')) {

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'
https://www.nytimes.com/svc/onsite-messaging/query
' can be anywhere in the URL, and arbitrary hosts may come before or after it.
request.abort();
return;
}
request.continue();
// request.resourceType() === 'document' ? request.continue() : request.abort();
});
await page.goto(link);
await page.waitForSelector('[data-testid=optimistic-truncator-message]', { hidden: true, timeout: 0 });
const response = await page.evaluate(() => document.querySelector('body').innerHTML);
return response;
});
Expand Down