Skip to content
Open
Changes from all commits
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
62 changes: 30 additions & 32 deletions lib/routes/reuters/common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type { Route } from '@/types';
import { ViewType } from '@/types';
import cache from '@/utils/cache';
import { PRESETS } from '@/utils/header-generator';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';

Expand Down Expand Up @@ -194,12 +195,6 @@

const section_id = `/${category}/${topic ? `${topic}/` : ''}`;

const browserHeaders = {
Accept: 'application/json, text/plain, */*',
'Accept-Language': 'en-US,en;q=0.9',
Referer: 'https://www.reuters.com/',
};

try {
const { title, description, rootUrl, response } = await (async () => {
if (MUST_FETCH_BY_TOPICS.has(category)) {
Expand All @@ -213,7 +208,7 @@
website: 'reuters',
}),
},
headers: browserHeaders,
headerGeneratorOptions: PRESETS.MODERN_WINDOWS,
});

return {
Expand All @@ -222,30 +217,33 @@
rootUrl,
response,
};
}
const rootUrl = 'https://www.reuters.com/pf/api/v3/content/fetch/articles-by-section-alias-or-id-v1';
const response = await ofetch(rootUrl, {
query: {
query: JSON.stringify({
offset: 0,
size: limit,
section_id,
website: 'reuters',
...(useSophi && {
fetch_type: 'sophi',
sophi_page: '*',
sophi_widget: 'topic',
} else {

Check failure

Code scanning / oxlint

unicorn-js(no-useless-else) Error

Unexpected else after a statement that exits.
const rootUrl = 'https://www.reuters.com/pf/api/v3/content/fetch/articles-by-section-alias-or-id-v1';
const response = await ofetch(rootUrl, {
query: {
query: JSON.stringify({
offset: 0,
size: limit,
section_id,
website: 'reuters',
...(useSophi

Check failure

Code scanning / oxlint

unicorn-js(consistent-conditional-object-spread) Error

Prefer logical conditional object spreads.
? {
fetch_type: 'sophi',
sophi_page: '*',
sophi_widget: 'topic',
}
: {}),
}),
}),
},
headers: browserHeaders,
});
return {
title: response.result.section.title,
description: response.result.section.section_about,
rootUrl,
response,
};
},
headerGeneratorOptions: PRESETS.MODERN_WINDOWS_FIREFOX,
});
return {
title: response.result.section.title,
description: response.result.section.section_about,
rootUrl,
response,
};
}
})();

let items = response.result.articles.map((e) => ({
Expand All @@ -266,7 +264,7 @@
ctx.req.query('fulltext') === 'true'
? cache.tryGet(item.link, async () => {
const detailResponse = await ofetch(item.link, {
headers: browserHeaders,
headerGeneratorOptions: PRESETS.MODERN_WINDOWS,
});
const content = load(detailResponse.data);

Expand Down Expand Up @@ -334,7 +332,7 @@
const arcUrl = topic ? `https://www.reuters.com/arc/outboundfeeds/v4/mobile/section${section_id}?outputType=json` : `https://www.reuters.com/arc/outboundfeeds/v4/mobile/section/${category}/?outputType=json`;

const arcResponse = await ofetch(arcUrl, {
headers: browserHeaders,
headerGeneratorOptions: PRESETS.MODERN_WINDOWS,
});
if (arcResponse.wireitems?.length) {
const items = arcResponse.wireitems
Expand Down