-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): Support xsijishe rank (#14006)
* 支持司机社论坛 rss * rename sjs to xsijishe * Update docs/bbs.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update docs/bbs.md Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/xsijishe/forum.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/xsijishe/forum.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/xsijishe/forum.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * Update lib/v2/xsijishe/radar.js Co-authored-by: Tony <TonyRL@users.noreply.github.com> * support xsijishe rank * support xsijishe rank ---------
- Loading branch information
Jack Bryant
authored
Dec 10, 2023
1 parent
1f41a94
commit 8b10f38
Showing
5 changed files
with
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
'/forum/:fid': ['akynazh'], | ||
'/rank/:type': ['akynazh'], | ||
}; |
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,60 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const baseUrl = 'https://xsijishe.com'; | ||
|
||
module.exports = async (ctx) => { | ||
const rankType = ctx.params.type; | ||
let title; | ||
let rankId; | ||
if (rankType === 'weekly') { | ||
title = '司机社综合周排行榜'; | ||
rankId = 'nex_recons_demens'; | ||
} else if (rankType === 'monthly') { | ||
title = '司机社综合月排行榜'; | ||
rankId = 'nex_recons_demens1'; | ||
} else { | ||
throw Error('Invalid rank type'); | ||
} | ||
const url = `${baseUrl}/portal.php`; | ||
const resp = await got(url); | ||
const $ = cheerio.load(resp.data); | ||
let items = $(`#${rankId} dd`) | ||
.toArray() | ||
.map((item) => { | ||
item = $(item); | ||
const title = item.find('h5').text().trim(); | ||
const link = item.find('a').attr('href'); | ||
return { | ||
title, | ||
link: `${baseUrl}/${link}`, | ||
}; | ||
}); | ||
items = await Promise.all( | ||
items.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const resp = await got(item.link); | ||
const $ = cheerio.load(resp.data); | ||
const firstViewBox = $('.t_f').first(); | ||
|
||
firstViewBox.find('img').each((_, img) => { | ||
img = $(img); | ||
if (img.attr('zoomfile')) { | ||
img.attr('src', img.attr('zoomfile')); | ||
img.removeAttr('zoomfile'); | ||
img.removeAttr('file'); | ||
} | ||
img.removeAttr('onmouseover'); | ||
}); | ||
|
||
item.description = firstViewBox.html(); | ||
return item; | ||
}) | ||
) | ||
); | ||
ctx.state.data = { | ||
title, | ||
link: url, | ||
description: title, | ||
item: items, | ||
}; | ||
}; |
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('/forum/:fid', require('./forum')); | ||
router.get('/rank/:type', require('./rank')); | ||
}; |
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