From caa172bfc6e0d9f05ba8eea2f020599c9737ae94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97?= <44351690+JamYiz@users.noreply.github.com> Date: Sat, 3 Jun 2023 00:30:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E8=89=B2=E8=8A=B1?= =?UTF-8?q?=E5=A0=82=E4=BD=9C=E8=80=85=E6=96=87=E7=AB=A0=20(#12584)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 色花堂作者文章 * 文档更改 * 修改router * fix:代码问题 * Fix bugs and add documentation * fix bugs * style: auto format * Update lib/v2/sehuatang/user.js * Update lib/v2/sehuatang/user.js * Update README.md * style: auto format --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- docs/install/README.md | 4 ++ docs/multimedia.md | 4 ++ lib/config.js | 3 + lib/v2/sehuatang/maintainer.js | 1 + lib/v2/sehuatang/router.js | 1 + lib/v2/sehuatang/user.js | 107 +++++++++++++++++++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 lib/v2/sehuatang/user.js diff --git a/docs/install/README.md b/docs/install/README.md index 2fa1500f5..ca92c2553 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -947,6 +947,10 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行 - `WENKU8_COOKIE`: 登陆轻小说文库后的 cookie +- 色花堂 + + - `SEHUATANG_COOKIE`: 登陆色花堂后的 cookie 值。 + - 邮箱 邮件列表路由: - `EMAIL_CONFIG_{email}`: 邮箱设置,替换 `{email}` 为 邮箱账号,邮件账户的 `@` 与 `.` 替换为 `_`,例如 `EMAIL_CONFIG_xxx_qq_com`。Linux 内容格式为 `password=密码&host=服务器&port=端口`,docker 内容格式为 `password=密码\&host=服务器\&port=端口`,例如: diff --git a/docs/multimedia.md b/docs/multimedia.md index bb8a0ade0..7e428b6e6 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -1635,6 +1635,10 @@ JavDB 有多个备用域名,本路由默认使用永久域名 +### 作者文章 + + + ## 深影译站 ### 首页 diff --git a/lib/config.js b/lib/config.js index b39e1d0f2..140eef258 100644 --- a/lib/config.js +++ b/lib/config.js @@ -256,6 +256,9 @@ const calculateValue = () => { saraba1st: { cookie: envs.SARABA1ST_COOKIE, }, + sehuatang: { + cookie: envs.SEHUATANG_COOKIE, + }, scboy: { token: envs.SCBOY_BBS_TOKEN, }, diff --git a/lib/v2/sehuatang/maintainer.js b/lib/v2/sehuatang/maintainer.js index 599f29ca4..5835e6083 100644 --- a/lib/v2/sehuatang/maintainer.js +++ b/lib/v2/sehuatang/maintainer.js @@ -1,6 +1,7 @@ module.exports = { '/bt/:subforumid?': ['qiwihui', 'junfengP', 'nczitzk'], '/picture/:subforumid': ['qiwihui', 'junfengP', 'nczitzk'], + '/user/:uid': ['JamYiz'], '/:subforumid?/:type?': ['qiwihui', 'junfengP', 'nczitzk'], '/:subforumid?': ['qiwihui', 'junfengP', 'nczitzk'], '/': ['qiwihui', 'junfengP', 'nczitzk'], diff --git a/lib/v2/sehuatang/router.js b/lib/v2/sehuatang/router.js index 77b1145c7..e6e18de6f 100644 --- a/lib/v2/sehuatang/router.js +++ b/lib/v2/sehuatang/router.js @@ -1,6 +1,7 @@ module.exports = function (router) { router.get('/bt/:subforumid?', require('./index')); router.get('/picture/:subforumid', require('./index')); + router.get('/user/:uid', require('./user')); router.get('/:subforumid?/:type?', require('./index')); router.get('/:subforumid?', require('./index')); router.get('', require('./index')); diff --git a/lib/v2/sehuatang/user.js b/lib/v2/sehuatang/user.js new file mode 100644 index 000000000..f8dfbe16e --- /dev/null +++ b/lib/v2/sehuatang/user.js @@ -0,0 +1,107 @@ +// 导入必要的模组 +const got = require('@/utils/got'); // 自订的 got +const cheerio = require('cheerio'); // 可以使用类似 jQuery 的 API HTML 解析器 +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); +const config = require('@/config').value; + +const baseUrl = 'https://sehuatang.org/'; + +module.exports = async (ctx) => { + if (!config.sehuatang.cookie) { + throw 'Sehuatang RSS is disabled due to the lack of relevant config'; + } + // 从Url参数中获取uid + const uid = ctx.params.uid; + const link = `${baseUrl}home.php?mod=space&uid=${uid}&do=thread&view=me&from=space`; + + const response = await got(link, { + headers: { + Cookie: config.sehuatang.cookie, + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('#delform tr:not(.th)') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 25) + .toArray() + .map((item) => { + item = $(item); + const a = item.find('th>a').first(); + const category = item.find('.xg1').first().text(); + return { + title: `[${category}] ${a.text()}`, + // `link` 需要一个绝对 URL,但 `a.attr('href')` 返回一个相对 URL。 + link: baseUrl + a.attr('href'), + // pubDate: '', + author: $('.mt').first().text(), + }; + }); + + const out = await Promise.all( + list.map((info) => + ctx.cache.tryGet(info.link, async () => { + const response = await got(info.link, { + headers: { + Cookie: config.sehuatang.cookie, + 'Accept-Encoding': 'gzip, deflate, br', + 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', + }, + }); + + const $ = cheerio.load(response.data); + const postMessage = $("[id^='postmessage']").slice(0, 1); + const images = $(postMessage).find('img'); + for (const image of images) { + const file = $(image).attr('file'); + if (!file || file === 'undefined') { + $(image).replaceWith(''); + } else { + $(image).replaceWith($(``)); + } + } + // if postMessage does not have any images, try to parse image url from `.pattl` + if (images.length === 0) { + const pattl = $('.pattl'); + const pattlImages = $(pattl).find('img'); + for (const pattlImage of pattlImages) { + const file = $(pattlImage).attr('file'); + if (!file || file === 'undefined') { + $(pattlImage).replaceWith(''); + } else { + $(pattlImage).replaceWith($(``)); + } + } + postMessage.append($(pattl)); + } + $('em[onclick]').remove(); + + info.description = (postMessage.html() || '抓取原帖失败').replace(/ignore_js_op/g, 'div'); + info.pubDate = timezone(parseDate($('.authi em span').attr('title')), 8); + + const magnet = postMessage.find('div.blockcode li').first().text(); + const isMag = magnet.startsWith('magnet'); + const torrent = postMessage.find('p.attnm a').attr('href'); + + const hasEnclosureUrl = isMag || torrent !== undefined; + if (hasEnclosureUrl) { + const enclosureUrl = isMag ? magnet : new URL(torrent, baseUrl).href; + info.enclosure_url = enclosureUrl; + info.enclosure_type = isMag ? 'application/x-bittorrent' : 'application/octet-stream'; + } + + return info; + }) + ) + ); + + ctx.state.data = { + // 在此处输出您的 RSS + title: `${$('.mt').text()}的帖子-色花堂`, + link, + item: out, + }; +};