forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 金十数据 主题文章 (DIYgod#12667)
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
'/:important?': ['laampui'], | ||
'/topic/:id': ['miles170'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |