feat: add route for hpoi user activity (#4190)

This commit is contained in:
Luyu Huang
2020-03-08 01:36:23 +08:00
committed by GitHub
parent 4039dee34e
commit c47e526887
3 changed files with 56 additions and 0 deletions

View File

@@ -139,6 +139,16 @@ pageClass: routes
</Route>
### 用户动态
<Route author="luyuhuang" path="/hpoi/user/:user_id/:caty" example="/hpoi/user/116297/buy" :paramsDesc="['用户ID', '类别, 见下表']">
| 想买的手办 | 预定的手办 | 已入的手办 |
| ---------- | ---------- | ---------- |
| want | preorder | buy |
</Route>
## say 花火
### 文章

View File

@@ -1507,6 +1507,7 @@ router.get('/guanchazhe/index/:type', require('./routes/guanchazhe/index'));
// Hpoi 手办维基
router.get('/hpoi/info/:type?', require('./routes/hpoi/info'));
router.get('/hpoi/:category/:words', require('./routes/hpoi'));
router.get('/hpoi/user/:user_id/:caty', require('./routes/hpoi/user'));
// 通用CurseForge
router.get('/curseforge/:gameid/:catagoryid/:projectid/files', require('./routes/curseforge/generalfiles'));

45
lib/routes/hpoi/user.js Normal file
View File

@@ -0,0 +1,45 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const root_url = 'https://www.hpoi.net';
const caties = {
want: '想买的手办',
preorder: '预定的手办',
buy: '已入的手办',
};
module.exports = async (ctx) => {
const { user_id, caty } = ctx.params;
let title = caties[caty];
if (!title) {
throw Error('Bad category. See <a href="https://docs.rsshub.app/anime.html#hpoi-shou-ban-wei-ji">https://docs.rsshub.app/anime.html#hpoi-shou-ban-wei-ji</a>');
}
const url = `${root_url}/user/${user_id}/hobby?order=actionDate&favState=${caty}&view=5&category=100&sortType=1`;
const response = await got({
method: 'get',
url: url,
});
const $ = cheerio.load(response.data);
const list = $('#content > div.action-box div.action-detail')
.map((_, item) => {
item = $(item);
const img = item.find('div.list-5-left > a > img').attr('src');
const a = item.find('div.list-5-right > a.action-title');
return {
title: a.text(),
link: a.attr('href'),
description: `<img src="${img}"><p>${a.text()}</p>`,
};
})
.get();
title = $('div.col-md-15.col-sm-15 > div:nth-child(2)').text() + title;
ctx.state.data = {
title: title,
link: url,
item: list,
};
};