From c7b50b2b3014ee86fa1c5e6544d287c3d376fb31 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Mon, 30 Nov 2020 03:24:47 +0800 Subject: [PATCH] feat: add fantia search & ranking (#6245) --- docs/picture.md | 56 +++++++++++++++++++++++++++++++ lib/router.js | 1 + lib/routes/fantia/search.js | 66 +++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 lib/routes/fantia/search.js diff --git a/docs/picture.md b/docs/picture.md index 365b8b1a4..949e7bd34 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -76,6 +76,62 @@ pageClass: routes ## Fantia +### 搜索 + + + +类型 + +| クリエイター | 投稿 | 商品 | コミッション | +| ------------ | ----- | -------- | ------------ | +| fanclubs | posts | products | commissions | + +分类 + +| 分类 | 分类名 | +| ---------------------- | ---------- | +| イラスト | illust | +| 漫画 | comic | +| コスプレ | cosplay | +| YouTuber・配信者 | youtuber | +| Vtuber | vtuber | +| 音声作品・ASMR | voice | +| 声優・歌い手 | voiceactor | +| アイドル | idol | +| アニメ・映像・写真 | anime | +| 3D | 3d | +| ゲーム制作 | game | +| 音楽 | music | +| 小説 | novel | +| ドール | doll | +| アート・デザイン | art | +| プログラム | program | +| 創作・ハンドメイド | handmade | +| 歴史・評論・情報 | history | +| 鉄道・旅行・ミリタリー | railroad | +| ショップ | shop | +| その他 | other | + +排行时段 + +| デイリー | ウィークリー | マンスリー | 全期間 | +| -------- | ------------ | ---------- | ------ | +| daily | weekly | monthly | all | + +排序 + +| 更新の新しい順 | 更新の古い順 | 投稿の新しい順 | 投稿の古い順 | お気に入り数順 | +| -------------- | ------------ | -------------- | ------------ | -------------- | +| updater | update_old | newer | create_old | popular | + +R18 显示 + +| すべて | 一般のみ | R18 のみ | +| ------ | -------- | -------- | +| all | general | adult | + + + ### 用户投稿 diff --git a/lib/router.js b/lib/router.js index c502af2c7..cec2c7636 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3513,6 +3513,7 @@ router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt')); router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic')); // Fantia +router.get('/fantia/search/:type?/:caty?/:peroid?/:order?/:rating?/:keyword?', require('./routes/fantia/search')); router.get('/fantia/user/:id', require('./routes/fantia/user')); // i-Cable diff --git a/lib/routes/fantia/search.js b/lib/routes/fantia/search.js new file mode 100644 index 000000000..fd002074d --- /dev/null +++ b/lib/routes/fantia/search.js @@ -0,0 +1,66 @@ +const got = require('@/utils/got'); + +module.exports = async (ctx) => { + const type = ctx.params.type || 'posts'; + const caty = ctx.params.caty || ''; + const order = ctx.params.order || 'updater'; + const rating = ctx.params.rating || 'all'; + const keyword = ctx.params.keyword || ''; + const peroid = ctx.params.peroid || ''; + + const rootUrl = 'https://fantia.jp'; + const apiUrl = `${rootUrl}/api/v1/search/${type}?keyword=${keyword}&peroid=${peroid}&brand_type=0&category=${caty === 'all' ? '' : caty}&order=${order}${ + rating === 'all' ? '' : rating === 'general' ? '&rating=general' : '&adult=1' + }&per_page=30`; + const response = await got({ + method: 'get', + url: apiUrl, + }); + + let items = {}; + + switch (type) { + case 'fanclubs': { + items = response.data.fanclubs.map((item) => ({ + title: item.fanclub_name_with_creator_name, + link: `${rootUrl}/fanclubs/${item.id}`, + description: `${item.icon ? `` : ''}">

${item.title}

`, + })); + break; + } + case 'posts': { + items = response.data.posts.map((item) => ({ + title: item.title, + link: `${rootUrl}/posts/${item.id}`, + pubDate: new Date(item.posted_at).toUTCString(), + author: item.fanclub.fanclub_name_with_creator_name, + description: `${item.comment ? `

${item.comment}

` : ''}`, + })); + break; + } + case 'products': { + items = response.data.products.map((item) => ({ + title: item.name, + link: `${rootUrl}/products/${item.id}`, + author: item.fanclub.fanclub_name_with_creator_name, + description: `${item.buyable_lowest_plan.description ? `

${item.buyable_lowest_plan.description}

` : ''}`, + })); + break; + } + case 'commissions': { + items = response.data.commissions.map((item) => ({ + title: item.name, + link: `${rootUrl}/commissions/${item.id}`, + author: item.fanclub.fanclub_name_with_creator_name, + description: `${item.buyable_lowest_plan.description ? `

${item.buyable_lowest_plan.description}

` : ''}`, + })); + break; + } + } + + ctx.state.data = { + title: `Fantia - Search ${type}`, + link: apiUrl.replace('api/v1/search/', ''), + item: items, + }; +};