feat: add fantia search & ranking (#6245)

This commit is contained in:
Ethan Shen
2020-11-29 19:24:47 +00:00
committed by GitHub
parent 2d508960bf
commit c7b50b2b30
3 changed files with 123 additions and 0 deletions
+1
View File
@@ -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
+66
View File
@@ -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 ? `<img src="${item.icon.main}">` : ''}"><p>${item.title}</p>`,
}));
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 ? `<p>${item.comment}</p>` : ''}<img src="${item.thumb ? item.thumb.main : item.thumb_micro}">`,
}));
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 ? `<p>${item.buyable_lowest_plan.description}</p>` : ''}<img src="${item.thumb ? item.thumb.main : item.thumb_micro}">`,
}));
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 ? `<p>${item.buyable_lowest_plan.description}</p>` : ''}<img src="${item.thumb ? item.thumb.main : item.thumb_micro}">`,
}));
break;
}
}
ctx.state.data = {
title: `Fantia - Search ${type}`,
link: apiUrl.replace('api/v1/search/', ''),
item: items,
};
};