fix(route): change iresearch's API URL and refactor to V2 (#9019)

* Fix(route): change iresearch's API URL and refactor to V2

* Fix(route): add tryGet and timezone
This commit is contained in:
Fatpandac
2022-02-08 20:20:54 +08:00
committed by GitHub
parent 2f7c282d3c
commit 7bcb65ea25
8 changed files with 85 additions and 67 deletions
+1 -1
View File
@@ -326,7 +326,7 @@ type 为 all 时,category 参数不支持 cost 和 free
### 产业研究报告
<Route author="brilon" example="/iresearch/report" path="/iresearch/report"/>
<Route author="brilon Fatpandac" example="/iresearch/report" path="/iresearch/report"/>
## 爱 Q 生活网
-3
View File
@@ -1546,9 +1546,6 @@ router.get('/infoq/topic/:id', lazyloadRouteHandler('./routes/infoq/topic'));
// checkee
router.get('/checkee/:dispdate', lazyloadRouteHandler('./routes/checkee/index'));
// 艾瑞
router.get('/iresearch/report', lazyloadRouteHandler('./routes/iresearch/report'));
// ZAKER migrated to v2
// router.get('/zaker/:type/:id', lazyloadRouteHandler('./routes/zaker/source'));
// router.get('/zaker/focusread', lazyloadRouteHandler('./routes/zaker/focusread'));
-63
View File
@@ -1,63 +0,0 @@
const got = require('@/utils/got');
const date = require('@/utils/date');
async function processReport(item, ctx) {
const apiUrl = `http://www.iresearch.com.cn/Detail/reportM?id=${item.NewsId}&isfree=0`;
const pageUrl = 'http://www.iresearch.com.cn/m/report.shtml';
const cache = await ctx.cache.get(apiUrl);
if (cache) {
return cache;
}
const response = await got({
method: 'get',
url: apiUrl,
headers: {
Referer: pageUrl,
'Content-Type': 'application/json',
},
});
const data = response.data.List[0];
let description = data.Content + '<br>';
const reportId = data.id;
for (let i = 1; i <= data.PagesCount; i++) {
description += `<img src="http://report.iresearch.cn/rimgs/${reportId}/${i}.jpg" rel="no-referrer"><br>`;
}
ctx.cache.set(apiUrl, description);
return description;
}
module.exports = async (ctx) => {
const apiUrl = 'http://www.iresearch.com.cn/products/GetReportList?classId=&fee=0&date=&lastId=&pageSize=6';
const pageUrl = 'http://www.iresearch.com.cn/m/report.shtml';
const resp = await got({
method: 'get',
url: apiUrl,
headers: {
Referer: pageUrl,
'Content-Type': 'application/json',
},
});
const list = resp.data.List;
const items = await Promise.all(
list.map(async (item) => {
const other = await processReport(item, ctx);
return {
title: item.Title,
description: other,
pubDate: date(item.Uptime),
link: item.VisitUrl,
};
})
);
ctx.state.data = {
title: '艾瑞产业研究报告',
link: pageUrl,
description: '艾瑞产业研究报告',
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/report': ['brilon', 'Fatpandac'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'iresearch.com.cn': {
_name: '艾瑞',
www: [
{
title: '研究报告',
docs: 'https://docs.rsshub.app/journal.html#ieee-xplore',
source: ['/report.shtml'],
target: '/iresearch/report',
},
],
},
};
+60
View File
@@ -0,0 +1,60 @@
const got = require('@/utils/got');
const { art } = require('@/utils/render');
const path = require('path');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
function processReport(item, ctx) {
const apiUrl = `https://www.iresearch.com.cn/api/Detail/reportM?id=${item.NewsId}&isfree=0`;
const pageUrl = 'https://www.iresearch.com.cn/m/report.shtml';
const description = ctx.cache.tryGet(apiUrl, async () => {
const response = await got({
method: 'get',
url: apiUrl,
headers: {
Referer: pageUrl,
'Content-Type': 'application/json',
},
});
const data = response.data.List[0];
return art(path.join(__dirname, 'templates/report.art'), {
data,
});
});
return description;
}
module.exports = async (ctx) => {
const limit = isNaN(parseInt(ctx.query.limit)) ? 20 : parseInt(ctx.query.limit);
const apiUrl = `https://www.iresearch.com.cn/api/products/GetReportList?fee=0&date=&lastId=&pageSize=${limit}`;
const pageUrl = 'https://www.iresearch.com.cn/m/report.shtml';
const resp = await got({
method: 'get',
url: apiUrl,
headers: {
Referer: pageUrl,
'Content-Type': 'application/json',
},
});
const list = resp.data.List;
const items = await Promise.all(
list.map(async (item) => ({
title: item.Title,
description: await processReport(item, ctx),
pubDate: timezone(parseDate(item.Uptime), +8),
link: item.VisitUrl,
}))
);
ctx.state.data = {
title: '艾瑞产业研究报告',
link: pageUrl,
description: '艾瑞产业研究报告',
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/report', require('./report'));
};
+5
View File
@@ -0,0 +1,5 @@
{{@ data.Content }}
<% for (let i = 1; i <= data.PagesCount; i++){ %>
<img src="http://pic.iresearch.cn/rimgs/{{ data.id }}/{{ i }}.jpg" rel="no-referrer">
<% } %>