Skip to content

Commit

Permalink
feat: add param :limit? to set article numbers (#17755)
Browse files Browse the repository at this point in the history
* 24/11/28 fix: remove uncessary files

* 24/11/28 fix: return promise

* 24/11/28 refactor: return promises

* 24/11/28 refactor: remove await in the function

* 24/11/29 fix: pass Promises to items?

* 24/11/29 feature: page size 15 -> 30; add source authentication code

* feat: add param :limit?

* fix: change description

* 24/11/30 feat: use ctx.req.query('limit')

* Update lib/routes/foodtalks/index.ts

---------
  • Loading branch information
Geraldxm authored Nov 29, 2024
1 parent bc89b3d commit 6f55194
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/routes/foodtalks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ function processItems(list: any[], fullTextApi: string) {
item.description = response.data.content;
return item;
} catch (error) {
// Log the error for debugging, but don't rethrow to avoid halting the entire batch.
// Consider adding a fallback description or other handling here.
logger.error(`Error fetching full text for ${item.link}:`, error);
return item; // Return the original item, even without the description
return item;
}
})
)
);
}

async function handler() {
const url = 'https://api-we.foodtalks.cn/news/news/page?current=1&size=15&isLatest=1&language=ZH';
async function handler(ctx) {
const limit = ctx.req.query('limit') || 15;
const url = `https://api-we.foodtalks.cn/news/news/page?current=1&size=${limit}&isLatest=1&language=ZH`;
const response = await ofetch(url, {
headers: {
referrer: 'https://www.foodtalks.cn/',
Expand All @@ -64,15 +63,13 @@ async function handler() {
}));

const fullTextApi = 'https://api-we.foodtalks.cn/news/news/{id}?language=ZH';

// Assign the result of processItems to the items variable
const items = await processItems(list, fullTextApi);

return {
title: namespace.name,
description: namespace.description,
link: 'https://' + namespace.url,
item: items, // Use the processed items here
item: items,
image: 'https://www.foodtalks.cn/static/img/news-site-logo.7aaa5463.svg',
};
}

0 comments on commit 6f55194

Please sign in to comment.