From de26213b580dfdc09d759e78f2e1a6964159d560 Mon Sep 17 00:00:00 2001
From: Nisekoi5 <49276902+Nisekoi5@users.noreply.github.com>
Date: Tue, 27 Sep 2022 23:20:06 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20Fantia=E8=AF=B7=E6=B1=82=E9=83=A8?=
=?UTF-8?q?=E5=88=86=E5=86=85=E5=AE=B9=E6=97=B6=E5=9B=A0=E6=97=A0cookie?=
=?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=87=BA=E9=94=99=20(#10892)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 为fantia增加cookie配置
* 为fantia的另一个路由增加cookies
* 增加文档教程,另外增加容错,就算Cookie也不抛出异常,而是返回小的缩略图
* refactor: migrate to v2
---
docs/en/install/README.md | 4 ++
docs/en/picture.md | 62 +++++++++++++++++++++++++++++
docs/install/README.md | 4 ++
docs/picture.md | 2 +-
lib/config.js | 3 ++
lib/router.js | 4 +-
lib/v2/fantia/maintainer.js | 4 ++
lib/v2/fantia/radar.js | 13 ++++++
lib/v2/fantia/router.js | 4 ++
lib/{routes => v2}/fantia/search.js | 11 +++--
lib/{routes => v2}/fantia/user.js | 15 ++++---
11 files changed, 115 insertions(+), 11 deletions(-)
create mode 100644 lib/v2/fantia/maintainer.js
create mode 100644 lib/v2/fantia/radar.js
create mode 100644 lib/v2/fantia/router.js
rename lib/{routes => v2}/fantia/search.js (88%)
rename lib/{routes => v2}/fantia/user.js (70%)
diff --git a/docs/en/install/README.md b/docs/en/install/README.md
index f13001a61..cccf377ce 100644
--- a/docs/en/install/README.md
+++ b/docs/en/install/README.md
@@ -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
diff --git a/docs/en/picture.md b/docs/en/picture.md
index 08d2e5519..304aaf937 100644
--- a/docs/en/picture.md
+++ b/docs/en/picture.md
@@ -163,6 +163,68 @@ For RSS content, specify options in the `routeParams` parameter in query string
+## Fantia
+
+### Search
+
+
+
+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 |
+
+
+
+### User Posts
+
+
+
## GoComics Comic Strips
diff --git a/docs/install/README.md b/docs/install/README.md
index 736970b72..545bcaef4 100644
--- a/docs/install/README.md
+++ b/docs/install/README.md
@@ -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 私人令牌
diff --git a/docs/picture.md b/docs/picture.md
index 3f0fb9eb2..e4268455f 100644
--- a/docs/picture.md
+++ b/docs/picture.md
@@ -195,7 +195,7 @@ pageClass: routes
### 搜索
-
+
类型
diff --git a/lib/config.js b/lib/config.js
index 706af92d2..ac3e02677 100644
--- a/lib/config.js
+++ b/lib/config.js
@@ -152,6 +152,9 @@ const calculateValue = () => {
username: envs.FANFOU_USERNAME,
password: envs.FANFOU_PASSWORD,
},
+ fantia: {
+ cookies: envs.FANTIA_COOKIE,
+ },
game4399: {
cookie: envs.GAME_4399,
},
diff --git a/lib/router.js b/lib/router.js
index 063bb5e9a..fd198a0f0 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -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'));
diff --git a/lib/v2/fantia/maintainer.js b/lib/v2/fantia/maintainer.js
new file mode 100644
index 000000000..4680026e6
--- /dev/null
+++ b/lib/v2/fantia/maintainer.js
@@ -0,0 +1,4 @@
+module.exports = {
+ '/search/:type?/:caty?/:peroid?/:order?/:rating?/:keyword?': ['nczitzk'],
+ '/user/:id': ['nczitzk'],
+};
diff --git a/lib/v2/fantia/radar.js b/lib/v2/fantia/radar.js
new file mode 100644
index 000000000..6a7f94346
--- /dev/null
+++ b/lib/v2/fantia/radar.js
@@ -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',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/fantia/router.js b/lib/v2/fantia/router.js
new file mode 100644
index 000000000..4bd92e7d0
--- /dev/null
+++ b/lib/v2/fantia/router.js
@@ -0,0 +1,4 @@
+module.exports = (router) => {
+ router.get('/search/:type?/:caty?/:period?/:order?/:rating?/:keyword?', require('./search'));
+ router.get('/user/:id', require('./user'));
+};
diff --git a/lib/routes/fantia/search.js b/lib/v2/fantia/search.js
similarity index 88%
rename from lib/routes/fantia/search.js
rename to lib/v2/fantia/search.js
index fd002074d..8cd09e48c 100644
--- a/lib/routes/fantia/search.js
+++ b/lib/v2/fantia/search.js
@@ -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 ? `${item.comment}
` : ''}
`,
}));
diff --git a/lib/routes/fantia/user.js b/lib/v2/fantia/user.js
similarity index 70%
rename from lib/routes/fantia/user.js
rename to lib/v2/fantia/user.js
index 1518e799e..6637e65f7 100644
--- a/lib/routes/fantia/user.js
+++ b/lib/v2/fantia/user.js
@@ -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: `${item.comment}
`,
- 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 += `
`;
+ item.description += `
`;
return item;
})