mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-08-31 01:01:11 +08:00
fix(route): 修复infoq recommend接口获取代码片段源数据为空会导致报错的边界错误 (#10358)
* fix(route): 修复infoq recommend接口获取代码片段源数据为空会导致报错的边界错误 * refactor: migrate to v2
This commit is contained in:
+1
-1
@@ -659,7 +659,7 @@ Tag
|
||||
|
||||
### 话题
|
||||
|
||||
<Route author="brilon" example="/infoq/topic/1" path="/infoq/topic/:id" :paramsDesc="['话题id,可在[InfoQ全部话题](https://www.infoq.cn/topics)页面找到URL里的话题id']" />
|
||||
<Route author="brilon" example="/infoq/topic/1" path="/infoq/topic/:id" :paramsDesc="['话题id,可在 [InfoQ全部话题](https://www.infoq.cn/topics) 页面找到URL里的话题id']" />
|
||||
|
||||
## IT 之家
|
||||
|
||||
|
||||
+2
-2
@@ -1466,8 +1466,8 @@ router.get('/zucc/cssearch/latest/:webVpn/:key', lazyloadRouteHandler('./routes/
|
||||
router.get('/ccnu/career', lazyloadRouteHandler('./routes/universities/ccnu/career'));
|
||||
|
||||
// Infoq
|
||||
router.get('/infoq/recommend', lazyloadRouteHandler('./routes/infoq/recommend'));
|
||||
router.get('/infoq/topic/:id', lazyloadRouteHandler('./routes/infoq/topic'));
|
||||
// router.get('/infoq/recommend', lazyloadRouteHandler('./routes/infoq/recommend'));
|
||||
// router.get('/infoq/topic/:id', lazyloadRouteHandler('./routes/infoq/topic'));
|
||||
|
||||
// checkee
|
||||
router.get('/checkee/:dispdate', lazyloadRouteHandler('./routes/checkee/index'));
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
'/recommend': ['brilon'],
|
||||
'/topic/:id': ['brilon'],
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
module.exports = {
|
||||
'infoq.cn': {
|
||||
_name: 'InfoQ 中文',
|
||||
'.': [
|
||||
{
|
||||
title: '推荐',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#infoq-zhong-wen',
|
||||
source: ['/'],
|
||||
target: '/infoq/recommend',
|
||||
},
|
||||
{
|
||||
title: '话题',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#infoq-zhong-wen',
|
||||
source: ['/topic/:id'],
|
||||
target: '/infoq/topic/:id',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -5,14 +5,12 @@ module.exports = async (ctx) => {
|
||||
const apiUrl = 'https://www.infoq.cn/public/v1/my/recommond';
|
||||
const pageUrl = 'https://www.infoq.cn';
|
||||
|
||||
const resp = await got({
|
||||
method: 'post',
|
||||
url: apiUrl,
|
||||
const resp = await got.post(apiUrl, {
|
||||
headers: {
|
||||
Referer: pageUrl,
|
||||
},
|
||||
json: {
|
||||
size: 5,
|
||||
size: ctx.query.limit ? Number(ctx.query.limit) : 30,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -20,9 +18,8 @@ module.exports = async (ctx) => {
|
||||
const items = await utils.ProcessFeed(data, ctx.cache);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'InfoQ推荐',
|
||||
title: 'InfoQ 推荐',
|
||||
link: pageUrl,
|
||||
description: 'InfoQ推荐',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/recommend', require('./recommend'));
|
||||
router.get('/topic/:id', require('./topic'));
|
||||
};
|
||||
@@ -2,32 +2,28 @@ const got = require('@/utils/got');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const paramId = parseInt(ctx.params.id);
|
||||
const paramId = 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,
|
||||
const infoBody = isNaN(paramId) ? { alias: paramId } : { id: parseInt(paramId) };
|
||||
|
||||
const info = await got.post(infoUrl, {
|
||||
headers: {
|
||||
Referer: pageUrl,
|
||||
},
|
||||
json: {
|
||||
id: paramId,
|
||||
},
|
||||
json: infoBody,
|
||||
});
|
||||
const topicName = info.data.data.name;
|
||||
const type = info.data.data.type;
|
||||
|
||||
const resp = await got({
|
||||
method: 'post',
|
||||
url: apiUrl,
|
||||
const resp = await got.post(apiUrl, {
|
||||
headers: {
|
||||
Referer: pageUrl,
|
||||
},
|
||||
json: {
|
||||
size: 5,
|
||||
size: ctx.query.limit ? Number(ctx.query.limit) : 30,
|
||||
type,
|
||||
id: paramId,
|
||||
},
|
||||
@@ -37,9 +33,10 @@ module.exports = async (ctx) => {
|
||||
const items = await utils.ProcessFeed(data, ctx.cache);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `InfoQ话题 - ${topicName}`,
|
||||
title: `InfoQ 话题 - ${topicName}`,
|
||||
description: info.data.data.desc,
|
||||
image: info.data.data.cover,
|
||||
link: pageUrl,
|
||||
description: `InfoQ话题 - ${topicName}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const ProcessFeed = async (list, cache) => {
|
||||
const detailUrl = 'https://www.infoq.cn/public/v1/article/getDetail';
|
||||
@@ -8,9 +9,7 @@ const ProcessFeed = async (list, cache) => {
|
||||
const uuid = e.uuid;
|
||||
const single = await cache.tryGet(uuid, async () => {
|
||||
const link = `https://www.infoq.cn/article/${uuid}`;
|
||||
const resp = await got({
|
||||
method: 'post',
|
||||
url: detailUrl,
|
||||
const resp = await got.post(detailUrl, {
|
||||
headers: {
|
||||
Referer: link,
|
||||
},
|
||||
@@ -21,19 +20,19 @@ const ProcessFeed = async (list, cache) => {
|
||||
|
||||
const data = resp.data.data;
|
||||
const author = data.author ? data.author.map((p) => p.nickname).join(',') : data.no_author;
|
||||
const pubDate = new Date();
|
||||
pubDate.setTime(data.publish_time);
|
||||
const category = e.topic.map((t) => t.name).concat(e.label.map((l) => l.name));
|
||||
|
||||
return {
|
||||
title: data.article_title,
|
||||
description: parseContent(data.content),
|
||||
pubDate,
|
||||
pubDate: parseDate(e.publish_time, 'x'),
|
||||
category,
|
||||
author,
|
||||
link,
|
||||
};
|
||||
});
|
||||
|
||||
return Promise.resolve(single);
|
||||
return single;
|
||||
})
|
||||
);
|
||||
|
||||
@@ -67,9 +66,13 @@ const parseToSimpleTexts = (content) =>
|
||||
return `<img src="${img}"></img>`;
|
||||
},
|
||||
codeblock: () => {
|
||||
const lang = i.attrs.lang;
|
||||
const code = parseToSimpleText(i.content);
|
||||
return `<code lang="${lang}">${code}</code>`;
|
||||
if (i.content) {
|
||||
const lang = i.attrs.lang;
|
||||
const code = parseToSimpleText(i.content);
|
||||
return `<code lang="${lang}">${code}</code>`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
},
|
||||
link: () => {
|
||||
const href = i.attrs.href;
|
||||
Reference in New Issue
Block a user