diff --git a/docs/picture.md b/docs/picture.md index a5d076e7f..365b8b1a4 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -74,6 +74,12 @@ pageClass: routes +## Fantia + +### 用户投稿 + + + ## GirlImg ### album diff --git a/lib/router.js b/lib/router.js index 0af265567..c502af2c7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/fantia/user.js b/lib/routes/fantia/user.js new file mode 100644 index 000000000..3e6d7e237 --- /dev/null +++ b/lib/routes/fantia/user.js @@ -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: `

${item.comment}

`, + 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 += ``; + + return item; + }) + ) + ); + + ctx.state.data = { + title: `Fantia - ${response.data.fanclub.fanclub_name_with_creator_name}`, + link: `${rootUrl}/fanclubs/${ctx.params.id}`, + item: items, + }; +};