feat: add fantia users' recent posts (#6244)

This commit is contained in:
Ethan Shen 2020-11-30 03:17:37 +08:00 committed by GitHub
parent 83ea0a8b6a
commit 2d508960bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 0 deletions

View File

@ -74,6 +74,12 @@ pageClass: routes
</Route>
## Fantia
### 用户投稿
<Route author="nczitzk" example="/fantia/user/3498" path="/fantia/user/:id" :paramsDesc="['用户 id可在用户页 URL 中找到']" />
## GirlImg
### album

View File

@ -3512,6 +3512,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
// Fantia
router.get('/fantia/user/:id', require('./routes/fantia/user'));
// i-Cable
router.get('/icable/:category/:option?', require('./routes/icable/category'));

40
lib/routes/fantia/user.js Normal file
View File

@ -0,0 +1,40 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const rootUrl = 'https://fantia.jp';
const userUrl = `${rootUrl}/api/v1/fanclubs/${ctx.params.id}`;
const response = await got({
method: 'get',
url: userUrl,
});
const list = response.data.fanclub.recent_posts.map((item) => ({
title: item.title,
link: `${rootUrl}/api/v1/posts/${item.id}`,
description: `<p>${item.comment}</p>`,
pubDate: new Date(item.posted_at).toUTCString(),
}));
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const contentResponse = await got({
method: 'get',
url: item.link,
});
item.link = item.link.replace('api/v1/', '');
item.description += `<img src="${contentResponse.data.post.thumb.large}">`;
return item;
})
)
);
ctx.state.data = {
title: `Fantia - ${response.data.fanclub.fanclub_name_with_creator_name}`,
link: `${rootUrl}/fanclubs/${ctx.params.id}`,
item: items,
};
};