Files
RSSHub/lib/v2/huxiu/channel.js
T
Ethan Shen 804a4abbf3 feat(route): add 虎嗅频道 & 源流 (#13945)
* feat(route): add 虎嗅频道 & 源流

* fix: limit to 20

* docs: remove rssbud
2023-12-05 00:38:27 +08:00

29 lines
857 B
JavaScript

const got = require('@/utils/got');
const { rootUrl, apiArticleRootUrl, processItems, fetchData } = require('./util');
module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;
const apiUrl = new URL(`web/${id ? 'channel' : 'article'}/articleList`, apiArticleRootUrl).href;
const currentUrl = new URL(id ? `channel/${id}.html` : 'article', rootUrl).href;
const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
channel_id: id,
pagesize: limit,
},
});
const items = await processItems(response.data?.dataList ?? response.data.datalist, limit, ctx.cache.tryGet);
const data = await fetchData(currentUrl);
ctx.state.data = {
item: items,
...data,
};
};