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): add CBNData消费站看点 (DIYgod#7810)
Co-authored-by: NeverBehave <[email protected]>
- Loading branch information
1 parent
3396d0a
commit adcf6ea
Showing
3 changed files
with
68 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
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,53 @@ | ||
const got = require('@/utils/got'); | ||
|
||
module.exports = async (ctx) => { | ||
const category = ctx.params.category || ''; | ||
|
||
const rootUrl = 'https://www.cbndata.com'; | ||
const apiUrl = `${rootUrl}/api/v3/informations?page=1&per_page=10${category ? `&tag_id=${category}` : ''}`; | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: apiUrl, | ||
}); | ||
|
||
const list = response.data.data.map((item) => ({ | ||
title: item.id, | ||
link: `${rootUrl}/api/v3/informations/show?id=${item.id}`, | ||
pubDate: Date.parse(item.date), | ||
})); | ||
|
||
const items = await Promise.all( | ||
list.map( | ||
async (item) => | ||
await ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
|
||
item.link = `${rootUrl}/information/${item.title}`; | ||
|
||
item.title = detailResponse.data.data.title; | ||
item.author = detailResponse.data.data.author; | ||
item.description = detailResponse.data.data.content; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
let title = '看点'; | ||
|
||
for (const tag of response.data.home_tags) { | ||
if (tag.id.toString() === category) { | ||
title = tag.name; | ||
break; | ||
} | ||
} | ||
ctx.state.data = { | ||
title: `${title} - CBNData消费站`, | ||
link: `${rootUrl}/information${category ? `?tag_id=${category}` : ''}`, | ||
item: items, | ||
}; | ||
}; |