mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-16 11:37:44 +08:00
* style: prefer object shorthand syntax * refactor: prefer Array#map over Array#forEach * style: prefer arrow callback * chore(eslint): update rules * style: auto fix by eslint
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
// pixiv fanbox, maybe blocked by upstream
|
|
|
|
// params:
|
|
// user?: fanbox domain name
|
|
|
|
const got = require('@/utils/got');
|
|
|
|
const conv_item = require('./conv');
|
|
const get_header = require('./header');
|
|
|
|
module.exports = async (ctx) => {
|
|
const user = ctx.params.user || 'official'; // if no user specified, just go to official page
|
|
const box_url = `https://${user}.fanbox.cc`;
|
|
|
|
// get user info
|
|
let title = `${user}'s fanbox`;
|
|
let descr = title;
|
|
|
|
try {
|
|
const user_api = `https://api.fanbox.cc/creator.get?creatorId=${user}`;
|
|
const resp_u = await got(user_api, { headers: get_header() });
|
|
title = `${resp_u.data.body.user.name}'s fanbox`;
|
|
descr = resp_u.data.description;
|
|
} catch (_) {
|
|
_;
|
|
}
|
|
|
|
// get user posts
|
|
const posts_api = `https://api.fanbox.cc/post.listCreator?creatorId=${user}&limit=20`;
|
|
const response = await got(posts_api, { headers: get_header() });
|
|
|
|
// render posts
|
|
const items = await Promise.all(response.data.body.items.map((i) => conv_item(i)));
|
|
|
|
// return rss feed
|
|
ctx.state.data = {
|
|
title,
|
|
link: box_url,
|
|
description: descr,
|
|
item: items,
|
|
};
|
|
};
|