fix(route/yahoo): allow unlisted provider

This commit is contained in:
Tony 2023-12-07 23:42:31 +00:00 committed by GitHub
parent d7f4dbbe3f
commit ec6df29727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 7 deletions

View File

@ -9,19 +9,15 @@ module.exports = async (ctx) => {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;
const providerList = await getProviderList(region, ctx.cache.tryGet);
const provider = providerList.find((p) => p.key === providerId);
if (!provider) {
throw Error(`Unknown providerId: ${providerId}
Please double check the <a href="${ctx.origin}/yahoo/news/providers/${region}">provider list</a>.`);
}
const response = await getArchive(region, limit, null, provider.key);
const response = await getArchive(region, limit, null, providerId);
const list = parseList(region, response);
const items = await Promise.all(list.map((item) => parseItem(item, ctx.cache.tryGet)));
ctx.state.data = {
title: `Yahoo 新聞 - ${provider.title}`,
link: provider.link,
title: `Yahoo 新聞 - ${provider?.title ?? ''}`,
link: provider?.link ?? `https://${region}.news.yahoo.com`,
image: 'https://s.yimg.com/cv/apiv2/social/images/yahoo_default_logo-1200x1200.png',
item: items,
};