From b538f75ef60fba88daa9528f1acd573435e7e0f2 Mon Sep 17 00:00:00 2001 From: sgqy Date: Sun, 4 Oct 2020 04:24:15 +0800 Subject: [PATCH] fix: (semi-fix) login to NGA to prevent 403 error. (#5747) --- docs/en/install/README.md | 12 ++++++++++++ docs/en/social-media.md | 8 -------- docs/install/README.md | 16 ++++++++++++++++ docs/social-media.md | 7 ------- lib/config.js | 4 ++++ lib/routes/nga/post.js | 7 ++++++- 6 files changed, 38 insertions(+), 16 deletions(-) diff --git a/docs/en/install/README.md b/docs/en/install/README.md index f4b15d667..e152f78b5 100644 --- a/docs/en/install/README.md +++ b/docs/en/install/README.md @@ -407,12 +407,24 @@ See the relation between access key/code and white/blacklisting. ### Route-specific Configurations +::: tip Notice + +Configs here is incomplete. + +See docs of specified route and `lib/config.js` for detail information. + +::: + - pixiv: [Registration](https://accounts.pixiv.net/signup) - `PIXIV_USERNAME`: Pixiv username - `PIXIV_PASSWORD`: Pixiv password +- pixiv fanbox: Get paid content + + - `FANBOX_SESSION_ID`: equals to `FANBOXSESSID` in site cookies. + - disqus: [API Key application](https://disqus.com/api/applications/) - `DISQUS_API_KEY`: Disqus API diff --git a/docs/en/social-media.md b/docs/en/social-media.md index b850c1e1a..39a1cd521 100644 --- a/docs/en/social-media.md +++ b/docs/en/social-media.md @@ -118,14 +118,6 @@ Only for self-hosted ## pixiv-fanbox -::: warning Paywall - -The site **fanbox** is made for paid users. To get paid content, you should host by yourself. - -Settings: environment argument `FANBOX_SESSION_ID` equals to `FANBOXSESSID` in site cookies. - -::: - ## Telegram diff --git a/docs/install/README.md b/docs/install/README.md index 6a10f49db..0adcbab06 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -434,12 +434,22 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行 ### 部分 RSS 模块配置 +::: tip 提示 + +此处信息不完整。完整配置请参考路由对应的文档和 `lib/config.js`。 + +::: + - pixiv 全部路由:[注册地址](https://accounts.pixiv.net/signup) - `PIXIV_USERNAME`: Pixiv 用户名 - `PIXIV_PASSWORD`: Pixiv 密码 +- pixiv fanbox 用于获取付费内容 + + - `FANBOX_SESSION_ID`: 对应 cookies 中的`FANBOXSESSID`。 + - disqus 全部路由:[申请地址](https://disqus.com/api/applications/) - `DISQUS_API_KEY`: Disqus API @@ -544,3 +554,9 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行 - 新榜 - `NEWRANK_COOKIE`: 登陆后的 COOKIE 值,其中 token 是必要的,其他可删除 + +- NGA BBS 用于获取帖子内文 + + - `NGA_PASSPORT_UID`: 对应 cookie 中的 `ngaPassportUid`. + + - `NGA_PASSPORT_CID`: 对应 cookie 中的 `ngaPassportCid`. diff --git a/docs/social-media.md b/docs/social-media.md index 707cd3fae..12444685d 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -406,13 +406,6 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 ## pixiv-fanbox -::: warning 付费墙注意 - -由于 fanbox 专为付费用户设计,要查看已经付费的内容只能自建。 - -自建设置:环境变量`FANBOX_SESSION_ID`对应 cookies 中的`FANBOXSESSID`。 - -::: ## Popi 提问箱 diff --git a/lib/config.js b/lib/config.js index 76ff136f4..f5caf3b5d 100644 --- a/lib/config.js +++ b/lib/config.js @@ -156,6 +156,10 @@ const calculateValue = () => { device_id: envs.XIAOYUZHOU_ID, refresh_token: envs.XIAOYUZHOU_TOKEN, }, + nga: { + uid: envs.NGA_PASSPORT_UID, + cid: envs.NGA_PASSPORT_CID, + }, newrank: { cookie: envs.NEWRANK_COOKIE, }, diff --git a/lib/routes/nga/post.js b/lib/routes/nga/post.js index bba6ac695..60e20ed0c 100644 --- a/lib/routes/nga/post.js +++ b/lib/routes/nga/post.js @@ -1,18 +1,23 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); const iconv = require('iconv-lite'); +const config = require('@/config').value; module.exports = async (ctx) => { const getPageUrl = (tid, page = 1, hash = '') => `https://nga.178.com/read.php?tid=${tid}&page=${page}&rand=${Math.random() * 1000}#${hash}`; const getPage = async (tid, pageId = 1) => { const link = getPageUrl(tid, pageId); const timestamp = Math.floor(Date.now() / 1000); + let cookieString = `guestJs=${timestamp};`; + if (config.nga.uid && config.nga.cid) { + cookieString = `ngaPassportUid=${config.nga.uid}; ngaPassportCid=${config.nga.cid};`; + } const response = await got({ method: 'get', url: link, responseType: 'buffer', headers: { - Cookie: `guestJs=${timestamp};`, + Cookie: cookieString, }, });