-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fantia users' recent posts (#6244)
- Loading branch information
Ethan Shen
authored
Nov 29, 2020
1 parent
83ea0a8
commit 2d50896
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
2d50896
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: