fix(route): Fix saraba1st thread cannot get image (#10906)

* add saraba1st Cookie Environment.
fix thread img issue

* add Saraba1st config to Install Doc

* fix imgHtml

* fix timezone

* refactor: migrate to v2
This commit is contained in:
Axojhf
2022-09-26 20:52:50 +08:00
committed by GitHub
parent e4f264d6ea
commit 67fe3a0cfa
10 changed files with 93 additions and 74 deletions

View File

@@ -728,20 +728,6 @@
}, },
'huya.com': { _name: '虎牙直播', '.': [{ title: '直播间开播', docs: 'https://docs.rsshub.app/live.html#hu-ya-zhi-bo-zhi-bo-jian-kai-bo', source: '/:id', target: '/huya/live/:id' }] }, 'huya.com': { _name: '虎牙直播', '.': [{ title: '直播间开播', docs: 'https://docs.rsshub.app/live.html#hu-ya-zhi-bo-zhi-bo-jian-kai-bo', source: '/:id', target: '/huya/live/:id' }] },
'craigslist.org': { _name: 'Craigslist', '.': [{ title: '商品搜索列表', docs: 'https://docs.rsshub.app/shopping.html#craigslist' }] }, 'craigslist.org': { _name: 'Craigslist', '.': [{ title: '商品搜索列表', docs: 'https://docs.rsshub.app/shopping.html#craigslist' }] },
'saraba1st.com': {
_name: 'Saraba1st',
bbs: [
{
title: '帖子',
docs: 'https://docs.rsshub.app/bbs.html#saraba1st',
source: '/2b/:id',
target: (params) => {
const id = params.id.includes('thread') ? params.id.split('-')[1] : '';
return id ? `/saraba1st/thread/${id}` : '';
},
},
],
},
'scboy.com': { 'scboy.com': {
_name: 'scboy 论坛', _name: 'scboy 论坛',
www: [ www: [

View File

@@ -717,6 +717,10 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
- `FANBOX_SESSION_ID`: 对应 cookies 中的`FANBOXSESSID` - `FANBOX_SESSION_ID`: 对应 cookies 中的`FANBOXSESSID`
- Saraba1st 用于获取帖子里的图片
- `SARABA1ST_COOKIE`: 对应网页端的Cookie。
- Sci-hub 设置,用于科学期刊路由。 - Sci-hub 设置,用于科学期刊路由。
- `SCIHUB_HOST`: 可访问的 sci-hub 镜像地址,默认为 `https://sci-hub.se` - `SCIHUB_HOST`: 可访问的 sci-hub 镜像地址,默认为 `https://sci-hub.se`

View File

@@ -227,6 +227,9 @@ const calculateValue = () => {
pkubbs: { pkubbs: {
cookie: envs.PKUBBS_COOKIE, cookie: envs.PKUBBS_COOKIE,
}, },
saraba1st: {
cookie: envs.SARABA1ST_COOKIE,
},
scboy: { scboy: {
token: envs.SCBOY_BBS_TOKEN, token: envs.SCBOY_BBS_TOKEN,
}, },

View File

@@ -1516,20 +1516,6 @@ module.exports = {
}, },
], ],
}, },
'saraba1st.com': {
_name: 'Saraba1st',
bbs: [
{
title: '帖子',
docs: 'https://docs.rsshub.app/bbs.html#saraba1st',
source: '/2b/:id',
target: (params) => {
const id = params.id.includes('thread') ? params.id.split('-')[1] : '';
return id ? `/saraba1st/thread/${id}` : '';
},
},
],
},
'scboy.com': { 'scboy.com': {
_name: 'scboy 论坛', _name: 'scboy 论坛',
www: [ www: [

View File

@@ -1561,7 +1561,7 @@ router.get('/mit/csail/news', lazyloadRouteHandler('./routes/universities/mit/cs
router.get('/kpmg/insights', lazyloadRouteHandler('./routes/kpmg/insights')); router.get('/kpmg/insights', lazyloadRouteHandler('./routes/kpmg/insights'));
// Saraba1st // Saraba1st
router.get('/saraba1st/thread/:tid', lazyloadRouteHandler('./routes/saraba1st/thread')); // router.get('/saraba1st/thread/:tid', lazyloadRouteHandler('./routes/saraba1st/thread'));
// gradcafe // gradcafe
router.get('/gradcafe/result/:type', lazyloadRouteHandler('./routes/gradcafe/result')); router.get('/gradcafe/result/:type', lazyloadRouteHandler('./routes/gradcafe/result'));

View File

@@ -1,45 +0,0 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
const date = require('@/utils/date');
const queryString = require('query-string');
module.exports = async (ctx) => {
const tid = ctx.params.tid;
const res = await got.get('https://bbs.saraba1st.com/2b/forum.php', {
searchParams: queryString.stringify({
mod: 'viewthread',
tid,
ordertype: 1,
}),
});
const $ = cheerio.load(res.data);
const title = $('#thread_subject').text();
const list = $('#postlist > div[id^=post_]:not(:first-of-type)');
const count = [];
for (let i = 0; i < Math.min(list.length, 10); i++) {
count.push(i);
}
const resultItems = count.map((i) => {
const each = $(list[i]);
const floor = each.find('td.plc .pi a > em').text();
const floorUrl = each.find('td.plc .pi a').attr('href');
return {
title: `${title} #${floor}`,
link: url.resolve('https://bbs.saraba1st.com/2b/', floorUrl),
description: each.find('td.t_f').html(),
author: each.find('.authi .xw1').text(),
pubDate: date(each.find('.authi em').text()),
};
});
ctx.state.data = {
title: `Stage1 论坛 - ${title}`,
link: `https://bbs.saraba1st.com/2b/thread-${tid}-1-1.html`,
item: resultItems,
};
};

View File

@@ -0,0 +1,3 @@
module.exports = {
'/thread/:tid': ['zengxs'],
};

16
lib/v2/saraba1st/radar.js Normal file
View File

@@ -0,0 +1,16 @@
module.exports = {
'saraba1st.com': {
_name: 'Saraba1st',
bbs: [
{
title: '帖子',
docs: 'https://docs.rsshub.app/bbs.html#saraba1st',
source: '/2b/:id',
target: (params) => {
const id = params.id.includes('thread') ? params.id.split('-')[1] : '';
return id ? `/saraba1st/thread/${id}` : '';
},
},
],
},
};

View File

@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/thread/:tid', require('./thread'));
};

View File

@@ -0,0 +1,63 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const queryString = require('query-string');
const config = require('@/config').value;
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const tid = ctx.params.tid;
const cookieString = config.saraba1st.cookie ? config.saraba1st.cookie : '';
const res = await got('https://bbs.saraba1st.com/2b/forum.php', {
searchParams: queryString.stringify({
mod: 'viewthread',
tid,
ordertype: 1,
}),
headers: {
Cookie: cookieString,
},
});
const $ = cheerio.load(res.data);
const title = $('#thread_subject').text();
const list = $('#postlist > div[id^=post_]:not(:first-of-type)');
const count = [];
for (let i = 0; i < Math.min(list.length, 20); i++) {
count.push(i);
}
const resultItems = count.map((i) => {
const each = $(list[i]);
const floor = each.find('td.plc .pi a > em').text();
const floorUrl = each.find('td.plc .pi a').attr('href');
const contentHtml = $(each.find('td.t_f'));
const imgsHtml = contentHtml.find('img');
for (let i = 0; i < imgsHtml.length; i++) {
if (imgsHtml[i].attribs.src === 'https://static.saraba1st.com/image/common/none.gif') {
imgsHtml[i].attribs.src = imgsHtml[i].attribs.file;
const imgHtml = $(imgsHtml[i]);
imgHtml.removeAttr('zoomfile');
imgHtml.removeAttr('file');
imgHtml.removeAttr('onmouseover');
imgHtml.removeAttr('onclick');
}
}
contentHtml.find('div.aimg_tip').remove();
return {
title: `${title} #${floor}`,
link: new URL(floorUrl, 'https://bbs.saraba1st.com/2b/').href,
description: contentHtml.html(),
author: each.find('.authi .xw1').text(),
pubDate: timezone(parseDate(each.find('.authi em').text()), +8),
};
});
ctx.state.data = {
title: `Stage1 论坛 - ${title}`,
link: `https://bbs.saraba1st.com/2b/thread-${tid}-1-1.html`,
item: resultItems,
};
};