Skip to content

Commit

Permalink
feat: add fantia users' recent posts (#6244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Shen authored Nov 29, 2020
1 parent 83ea0a8 commit 2d50896
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/picture.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ pageClass: routes

</Route>

## Fantia

### 用户投稿

<Route author="nczitzk" example="/fantia/user/3498" path="/fantia/user/:id" :paramsDesc="['用户 id,可在用户页 URL 中找到']" />

## GirlImg

### album
Expand Down
3 changes: 3 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
40 changes: 40 additions & 0 deletions lib/routes/fantia/user.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

1 comment on commit 2d50896

@vercel
Copy link

@vercel vercel bot commented on 2d50896 Nov 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.