Skip to content

Commit

Permalink
feat(route): 金十数据 主题文章 (DIYgod#12667)
Browse files Browse the repository at this point in the history
  • Loading branch information
miles170 authored Jun 15, 2023
1 parent e9885db commit f9a482d
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/finance.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ TokenInsight 官方亦有提供 RSS,可参考 <https://api.tokeninsight.com/re

<Route author="laampui" example="/jin10" path="/jin10/:important?" :paramsDesc="['只看重要,任意值开启,留空关闭']" radar="1"/>

### 主题文章

<Route author="miles170" example="/jin10/topic/396" path="/jin10/topic/:id" radar="1"/>

## 老虎社区

### 个人主页
Expand Down
1 change: 1 addition & 0 deletions lib/v2/jin10/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/:important?': ['laampui'],
'/topic/:id': ['miles170'],
};
8 changes: 8 additions & 0 deletions lib/v2/jin10/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ module.exports = {
target: '/jin10',
},
],
xnews: [
{
title: '主题文章',
docs: 'https://docs.rsshub.app/finance.html#jin-shi-shu-ju',
source: ['/topic/:id'],
target: '/jin10/topic/:id',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/jin10/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/:important?', require('./index'));
router.get('/topic/:id', require('./topic'));
};
50 changes: 50 additions & 0 deletions lib/v2/jin10/topic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const config = require('@/config').value;

module.exports = async (ctx) => {
const id = ctx.params.id;
const data = await ctx.cache.tryGet(
`jin10:topic:${id}`,
async () => {
const { data: response } = await got(`https://reference-api.jin10.com/topic/getById?id=${id}`, {
headers: {
'x-app-id': 'g93rhHb9DcDptyPb',
'x-version': '1.0.1',
},
});
return response.data;
},
config.cache.routeExpire,
false
);

const items = await Promise.all(
data.list.map((item) =>
ctx.cache.tryGet(`jin10:reference:${item.id}`, async () => {
const { data: response } = await got(`https://reference-api.jin10.com/reference/getOne?id=${item.id}&type=news`, {
headers: {
'x-app-id': 'g93rhHb9DcDptyPb',
'x-version': '1.0.1',
},
});

return {
title: item.title,
description: response.data.content,
author: item.author.nick,
pubDate: timezone(parseDate(item.display_datetime), 8),
link: `https://xnews.jin10.com/details/${item.id}`,
};
})
)
);

ctx.state.data = {
title: data.title,
link: `https://xnews.jin10.com/topic/${id}`,
description: data.introduction,
item: items,
};
};

0 comments on commit f9a482d

Please sign in to comment.