feat: optimize hpoi user

This commit is contained in:
DIYgod
2020-03-08 03:00:15 +08:00
parent 225e2b39bc
commit fdbfc89cc0
2 changed files with 19 additions and 17 deletions

View File

@@ -141,11 +141,11 @@ pageClass: routes
### 用户动态 ### 用户动态
<Route author="luyuhuang" path="/hpoi/user/:user_id/:caty" example="/hpoi/user/116297/buy" :paramsDesc="['用户ID', '类别, 见下表']"> <Route author="luyuhuang DIYgod" path="/hpoi/user/:user_id/:caty" example="/hpoi/user/116297/buy" :paramsDesc="['用户ID', '类别, 见下表']">
| 想买的手办 | 预定的手办 | 已入的手办 | | 想买 | 预定 | 已入 | 关注 | 有过 |
| ---------- | ---------- | ---------- | | ---- | -------- | ---- | ---- | ------ |
| want | preorder | buy | | want | preorder | buy | care | resell |
</Route> </Route>

View File

@@ -2,20 +2,11 @@ const got = require('@/utils/got');
const cheerio = require('cheerio'); const cheerio = require('cheerio');
const root_url = 'https://www.hpoi.net'; const root_url = 'https://www.hpoi.net';
const caties = {
want: '想买的手办',
preorder: '预定的手办',
buy: '已入的手办',
};
module.exports = async (ctx) => { module.exports = async (ctx) => {
const { user_id, caty } = ctx.params; 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 url = `${root_url}/user/${user_id}/hobby?order=actionDate&favState=${caty}&view=5&category=100&sortType=2`;
const response = await got({ const response = await got({
method: 'get', method: 'get',
url: url, url: url,
@@ -29,13 +20,24 @@ module.exports = async (ctx) => {
const a = item.find('div.list-5-right > a.action-title'); const a = item.find('div.list-5-right > a.action-title');
return { return {
title: a.text(), title: a.text(),
link: a.attr('href'), link: 'https://www.hpoi.net/' + a.attr('href'),
description: `<img src="${img}"><p>${a.text()}</p>`, description: `<img src="${img}"><br>制作:${item
.find('.badge')
.eq(0)
.text()}<br>发售:${item
.find('.badge')
.eq(1)
.text()}`,
}; };
}) })
.get(); .get();
title = $('div.col-md-15.col-sm-15 > div:nth-child(2)').text() + title; const title =
$('div.col-md-15.col-sm-15 > div:nth-child(2)').text() +
$('.navbar-nav .active')
.eq(0)
.text() +
'的手办';
ctx.state.data = { ctx.state.data = {
title: title, title: title,