Files
RSSHub/lib/routes/infoq/topic.js
2019-06-04 18:28:06 +08:00

48 lines
1.1 KiB
JavaScript

const got = require('@/utils/got');
const utils = require('./utils');
module.exports = async (ctx) => {
const paramId = parseInt(ctx.params.id);
const apiUrl = 'https://www.infoq.cn/public/v1/article/getList';
const infoUrl = 'https://www.infoq.cn/public/v1/topic/getInfo';
const pageUrl = `https://www.infoq.cn/topic/${paramId}`;
const info = await got({
method: 'post',
url: infoUrl,
headers: {
Referer: pageUrl,
},
json: true,
data: {
id: paramId,
},
});
const topicName = info.data.data.name;
const type = info.data.data.type;
const resp = await got({
method: 'post',
url: apiUrl,
headers: {
Referer: pageUrl,
},
json: true,
data: {
size: 5,
type: type,
id: paramId,
},
});
const data = resp.data.data;
const items = await utils.ProcessFeed(data, ctx.cache);
ctx.state.data = {
title: `InfoQ话题 - ${topicName}`,
link: pageUrl,
description: `InfoQ话题 - ${topicName}`,
item: items,
};
};