feat: add fantia users' recent posts (#6244)
This commit is contained in:
parent
83ea0a8b6a
commit
2d508960bf
|
|
@ -74,6 +74,12 @@ pageClass: routes
|
|||
|
||||
</Route>
|
||||
|
||||
## Fantia
|
||||
|
||||
### 用户投稿
|
||||
|
||||
<Route author="nczitzk" example="/fantia/user/3498" path="/fantia/user/:id" :paramsDesc="['用户 id,可在用户页 URL 中找到']" />
|
||||
|
||||
## GirlImg
|
||||
|
||||
### album
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue