mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 14:07:54 +08:00
* feat: 新增站酷推荐 * feat: 新增站酷作品总榜单 * 站酷推荐 reverse * feat: 新增站酷用户作品页 * 调整格式化格式
This commit is contained in:
59
lib/routes/zcool/user.js
Normal file
59
lib/routes/zcool/user.js
Normal file
@@ -0,0 +1,59 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const uname = ctx.params.uname;
|
||||
|
||||
const url = 'https://' + uname + '.zcool.com.cn';
|
||||
const response = await got({ method: 'get', url });
|
||||
const $ = cheerio.load(response.data);
|
||||
const author = $('.people-nick-name')
|
||||
.text()
|
||||
.trim();
|
||||
|
||||
const list = $('.work-list-box > .card-box')
|
||||
.map((i, e) => {
|
||||
const element = $(e);
|
||||
const title = element
|
||||
.find('.card-info-title')
|
||||
.find('a')
|
||||
.attr('title')
|
||||
.trim();
|
||||
const link = element
|
||||
.find('.card-info-title')
|
||||
.find('a')
|
||||
.attr('href')
|
||||
.trim();
|
||||
return {
|
||||
title: title,
|
||||
description: '',
|
||||
link: link,
|
||||
author: author,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const result = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const link = item.link;
|
||||
|
||||
const cache = await ctx.cache.get(link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const itemReponse = await got.get(link);
|
||||
const itemElement = cheerio.load(itemReponse.data);
|
||||
item.description = itemElement('.work-content-wrap').html();
|
||||
|
||||
ctx.cache.set(link, JSON.stringify(item));
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '站酷 - ' + author,
|
||||
link: url,
|
||||
item: result.reverse(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user