fix: Fantia请求部分内容时因无cookie导致出错 (#10892)

* 为fantia增加cookie配置

* 为fantia的另一个路由增加cookies

* 增加文档教程,另外增加容错,就算Cookie也不抛出异常,而是返回小的缩略图

* refactor: migrate to v2
This commit is contained in:
Nisekoi5 2022-09-27 23:20:06 +08:00 committed by GitHub
parent 3e6f0542c2
commit de26213b58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 115 additions and 11 deletions

View File

@ -618,6 +618,10 @@ See docs of the specified route and `lib/config.js` for detailed information.
- `EH_IGNEOUS`: The value of `igneous` in the cookie header after logging in ExHentai. If this value is set, RSS will be generated from ExHentai
- `EH_IMG_PROXY`: Cover proxy address. If this is set, the link to the cover image will be replaced with this value at the beginning. When using ExHentai, the cover image requires cookies to access it, so you can use this with a cookie-added proxy server to access the cover image without cookies in some readers.
- Fantia
- `FANTIA_COOKIE`: The `cookie` after login can be obtained by viewing the request header in the console, If not filled in will cause some posts that require login to read to get exceptions
- GitHub: [Access Token application](https://github.com/settings/tokens)
- `GITHUB_ACCESS_TOKEN`: GitHub Access Token

View File

@ -163,6 +163,68 @@ For RSS content, specify options in the `routeParams` parameter in query string
<RouteEn author="nczitzk" example="/elitebabes/search/pose" path="/elitebabes/search/:keyword?" :paramsDesc="['Keyword']"/>
## Fantia
### Search
<RouteEn author="nczitzk" example="/fantia/search/posts/all/daily" path="/fantia/search/:type?/:caty?/:period?/:order?/:rating?/:keyword?" :paramsDesc="['Type, see the table below, `posts` by default', 'Category, see the table below, can also be found in search page URL, `すべてのクリエイター` by default', 'Ranking period, see the table below, empty by default' ,'Sorting, see the table below, `更新の新しい順` by default', 'Rating, see the table below, `すべて` by default', 'Keyword, empty by default']">
Type
| クリエイター | 投稿 | 商品 | コミッション |
| -------- | ----- | -------- | ----------- |
| fanclubs | posts | products | commissions |
Category
| 分类 | 分类名 |
| ------------ | ---------- |
| イラスト | 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 |
Ranking period
| デイリー | ウィークリー | マンスリー | 全期間 |
| ----- | ------ | ------- | --- |
| daily | weekly | monthly | all |
Sorting
| 更新の新しい順 | 更新の古い順 | 投稿の新しい順 | 投稿の古い順 | お気に入り数順 |
| ------- | ---------- | ------- | ---------- | ------- |
| updater | update_old | newer | create_old | popular |
Rating
| すべて | 一般のみ | R18 のみ |
| --- | ------- | ------ |
| all | general | adult |
</RouteEn>
### User Posts
<RouteEn author="nczitzk" example="/fantia/user/3498" path="/fantia/user/:id" :paramsDesc="['User id, can be found in user profile URL']" />
## GoComics Comic Strips
<RouteEn author="stjohnjohnson" example="/gocomics/foxtrot" path="/gocomics/:strip" :paramsDesc="['URL path of the strip on gocomics.com']" />

View File

@ -652,6 +652,10 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
- `EH_STAR`: E-Hentai 账户获得捐赠等级后将出现该 cookie。若设置此值图片访问量限制将与账号关联而非 IP 地址
- `EH_IMG_PROXY`: 封面代理访问地址。若设置此值,封面图链接将被替换为以此值开头。使用 ExHentai 时,封面图需要有 Cookie 才能访问,在一些阅读软件上没法显示封面,可以使用此值搭配一个加 Cookie 的代理服务器实现阅读软件无 Cookie 获取封面图。
- Fantia
- `FANTIA_COOKIE`: 登录后的 `cookie` , 可以在控制台中查看请求头获取。如果不填会导致部分需要登录后才能阅读的帖子获取异常
- Gitee 全部路由:[申请地址](https://gitee.com/api/v5/swagger)
- `GITEE_ACCESS_TOKEN`: Gitee 私人令牌

View File

@ -195,7 +195,7 @@ pageClass: routes
### 搜索
<Route author="nczitzk" example="/fantia/search/posts/all/daily" path="/fantia/search/:type?/:caty?/:peroid?/:order?/:rating?/:keyword?" :paramsDesc="['类型,见下表,默认为 posts','分类,见下表,也可在搜索页的 URL 中找到,默认为 すべてのクリエイター', '排行时段,见下表,填写该字段即返回排行榜,默认为空,即不排名' ,'排序,见下表,默认为 更新の新しい順', 'R18显示见下表默认为 すべて', '关键字,默认为空']">
<Route author="nczitzk" example="/fantia/search/posts/all/daily" path="/fantia/search/:type?/:caty?/:period?/:order?/:rating?/:keyword?" :paramsDesc="['类型,见下表,默认为 posts','分类,见下表,也可在搜索页的 URL 中找到,默认为 すべてのクリエイター', '排行时段,见下表,填写该字段即返回排行榜,默认为空,即不排名' ,'排序,见下表,默认为 更新の新しい順', 'R18显示见下表默认为 すべて', '关键字,默认为空']">
类型

View File

@ -152,6 +152,9 @@ const calculateValue = () => {
username: envs.FANFOU_USERNAME,
password: envs.FANFOU_PASSWORD,
},
fantia: {
cookies: envs.FANTIA_COOKIE,
},
game4399: {
cookie: envs.GAME_4399,
},

View File

@ -3465,8 +3465,8 @@ router.get('/matataki/users/:userId/favorites/:favoriteListId/posts/:ipfsFlag?',
router.get('/zhimap/:categoryUuid?/:recommend?', lazyloadRouteHandler('./routes/zhimap/index'));
// Fantia
router.get('/fantia/search/:type?/:caty?/:peroid?/:order?/:rating?/:keyword?', lazyloadRouteHandler('./routes/fantia/search'));
router.get('/fantia/user/:id', lazyloadRouteHandler('./routes/fantia/user'));
// router.get('/fantia/search/:type?/:caty?/:peroid?/:order?/:rating?/:keyword?', lazyloadRouteHandler('./routes/fantia/search'));
// router.get('/fantia/user/:id', lazyloadRouteHandler('./routes/fantia/user'));
// i-Cable
router.get('/icable/:category/:option?', lazyloadRouteHandler('./routes/icable/category'));

View File

@ -0,0 +1,4 @@
module.exports = {
'/search/:type?/:caty?/:peroid?/:order?/:rating?/:keyword?': ['nczitzk'],
'/user/:id': ['nczitzk'],
};

13
lib/v2/fantia/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'fantia.jp': {
_name: 'Fantia',
'.': [
{
title: '用户投稿',
docs: 'https://docs.rsshub.app/picture.html#fantia',
source: ['/fanclubs/:id'],
target: '/fantia/user/:id',
},
],
},
};

4
lib/v2/fantia/router.js Normal file
View File

@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/search/:type?/:caty?/:period?/:order?/:rating?/:keyword?', require('./search'));
router.get('/user/:id', require('./user'));
};

View File

@ -1,4 +1,6 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const Config = require('@/config').value.fantia;
module.exports = async (ctx) => {
const type = ctx.params.type || 'posts';
@ -6,15 +8,18 @@ module.exports = async (ctx) => {
const order = ctx.params.order || 'updater';
const rating = ctx.params.rating || 'all';
const keyword = ctx.params.keyword || '';
const peroid = ctx.params.peroid || '';
const period = ctx.params.period || '';
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}${
const apiUrl = `${rootUrl}/api/v1/search/${type}?keyword=${keyword}&peroid=${period}&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,
headers: {
Cookie: Config.cookies ? Config.cookies : '',
},
});
let items = {};
@ -32,7 +37,7 @@ module.exports = async (ctx) => {
items = response.data.posts.map((item) => ({
title: item.title,
link: `${rootUrl}/posts/${item.id}`,
pubDate: new Date(item.posted_at).toUTCString(),
pubDate: parseDate(item.posted_at),
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}">`,
}));

View File

@ -1,4 +1,6 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const Config = require('@/config').value.fantia;
module.exports = async (ctx) => {
const rootUrl = 'https://fantia.jp';
@ -6,25 +8,28 @@ module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: userUrl,
headers: {
Cookie: Config.cookies ? Config.cookies : '',
},
});
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(),
pubDate: parseDate(item.posted_at),
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const contentResponse = await got({
method: 'get',
url: item.link,
headers: {
Cookie: Config.cookies ? Config.cookies : '',
},
});
item.link = item.link.replace('api/v1/', '');
item.description += `<img src="${contentResponse.data.post.thumb.large}">`;
item.description += `<img src="${contentResponse.data.post?.thumb?.large ? contentResponse.data.post?.thumb?.large : contentResponse.data.post.thumb_micro}">`;
return item;
})