diff --git a/lib/config.ts b/lib/config.ts index 735e9614b..db9d0d20e 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -292,6 +292,7 @@ export type Config = { }; saraba1st: { cookie?: string; + host?: string; }; sehuatang: { cookie?: string; @@ -729,6 +730,7 @@ const calculateValue = () => { }, saraba1st: { cookie: envs.SARABA1ST_COOKIE, + host: envs.SARABA1ST_HOST || 'https://stage1st.com', }, sehuatang: { cookie: envs.SEHUATANG_COOKIE, diff --git a/lib/routes/saraba1st/digest.ts b/lib/routes/saraba1st/digest.ts index 3a9e12433..94493e467 100644 --- a/lib/routes/saraba1st/digest.ts +++ b/lib/routes/saraba1st/digest.ts @@ -12,7 +12,7 @@ import path from 'node:path'; export const route: Route = { path: '/digest/:tid', categories: ['bbs'], - example: '/saraba1st/digest/forum-75-1', + example: '/saraba1st/digest/forum-6-1', parameters: { tid: '论坛 id' }, features: { requireConfig: false, @@ -25,13 +25,14 @@ export const route: Route = { name: '论坛摘要', maintainers: ['shinemoon'], handler, - description: `版面网址如果为 \`https://bbs.saraba1st.com/2b/forum-75-1.html\` 那么论坛 id 就是 \`forum-75-1\`。`, + description: `版面网址如果为 \`https://stage1st.com/2b/forum-6-1.html\` 那么论坛 id 就是 \`forum-6-1\`。`, }; async function handler(ctx) { const tid = ctx.req.param('tid'); const cookieString = config.saraba1st.cookie ?? ''; - const res = await got('https://bbs.saraba1st.com/2b/' + tid + '.html', { + const host = config.saraba1st.host; + const res = await got(`${host}/2b/${tid}.html`, { headers: { Cookie: cookieString, }, @@ -48,7 +49,7 @@ async function handler(ctx) { const floorUrl = each.find('th.new a.s.xst').attr('href'); return { title: `${title}:${floor}`, - link: new URL(floorUrl, 'https://bbs.saraba1st.com/2b/').href, + link: new URL(floorUrl, `${host}/2b/`).href, author: each.find('td.by cite').text(), pubDate: timezone(parseDate(each.find('td.by em').first().text()), +8), }; @@ -65,7 +66,7 @@ async function handler(ctx) { return { title: `Stage1 论坛 - ${title}`, - link: `https://bbs.saraba1st.com/2b/${tid}.html`, + link: `${host}/2b/${tid}.html`, // item: await resultItems, item: resultItems, }; @@ -92,6 +93,7 @@ async function fetchContent(url) { postinfo: subind(this).find('div.authi em[id*=authorposton]').text(), }, msg: subind(this).find('td[id*="postmessage_"]').html(), + host: config.saraba1st.host, }); stubS.append(section); } diff --git a/lib/routes/saraba1st/namespace.ts b/lib/routes/saraba1st/namespace.ts index 106c418ed..1cc3191b4 100644 --- a/lib/routes/saraba1st/namespace.ts +++ b/lib/routes/saraba1st/namespace.ts @@ -2,6 +2,6 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { name: 'Saraba1st', - url: 'bbs.saraba1st.com', + url: 'stage1st.com', lang: 'zh-CN', }; diff --git a/lib/routes/saraba1st/templates/digest.art b/lib/routes/saraba1st/templates/digest.art index 06c8ea37e..ef7f64954 100644 --- a/lib/routes/saraba1st/templates/digest.art +++ b/lib/routes/saraba1st/templates/digest.art @@ -1,5 +1,5 @@
- {{ author.name }} + {{ author.name }} {{ author.postinfo }}
{{@ msg }}
diff --git a/lib/routes/saraba1st/thread.ts b/lib/routes/saraba1st/thread.ts index 5a62efb6e..3c7b3d24c 100644 --- a/lib/routes/saraba1st/thread.ts +++ b/lib/routes/saraba1st/thread.ts @@ -9,7 +9,7 @@ import timezone from '@/utils/timezone'; export const route: Route = { path: '/thread/:tid', categories: ['bbs'], - example: '/saraba1st/thread/1842868', + example: '/saraba1st/thread/751272', parameters: { tid: '帖子 id' }, features: { requireConfig: false, @@ -22,14 +22,15 @@ export const route: Route = { name: '帖子', maintainers: ['zengxs'], handler, - description: `帖子网址如果为 \`https://bbs.saraba1st.com/2b/thread-1842868-1-1.html\` 那么帖子 id 就是 \`1789863\`。`, + description: `帖子网址如果为 \`https://stage1st.com/2b/thread-751272-1-1.html\` 那么帖子 id 就是 \`751272\`。`, }; async function handler(ctx) { const tid = ctx.req.param('tid'); const cookieString = config.saraba1st.cookie ?? ''; + const host = config.saraba1st.host; - const res = await got('https://bbs.saraba1st.com/2b/forum.php', { + const res = await got(`${host}/2b/forum.php`, { searchParams: queryString.stringify({ mod: 'viewthread', tid, @@ -49,6 +50,9 @@ async function handler(ctx) { for (let i = 0; i < Math.min(list.length, 20); i++) { count.push(i); } + + const staticUrl = new URL('/image/common/none.gif', host); + staticUrl.hostname = `static.${staticUrl.hostname.split('.').slice(-2).join('.')}`; const resultItems = count.map((i) => { const each = $(list[i]); const floor = each.find('td.plc .pi a > em').text(); @@ -56,7 +60,7 @@ async function handler(ctx) { const contentHtml = $(each.find('td.t_f')); const imgsHtml = contentHtml.find('img'); for (const element of imgsHtml) { - if (element.attribs.src === 'https://static.saraba1st.com/image/common/none.gif') { + if (element.attribs.src === staticUrl.href) { element.attribs.src = element.attribs.file; const imgHtml = $(element); imgHtml.removeAttr('zoomfile'); @@ -68,7 +72,7 @@ async function handler(ctx) { contentHtml.find('div.aimg_tip').remove(); return { title: `${title} #${floor}`, - link: new URL(floorUrl, 'https://bbs.saraba1st.com/2b/').href, + link: new URL(floorUrl, `${host}/2b/`).href, description: contentHtml.html(), author: each.find('.authi .xw1').text(), pubDate: timezone(parseDate(each.find('.authi em').text()), +8), @@ -77,7 +81,7 @@ async function handler(ctx) { return { title: `Stage1 论坛 - ${title}`, - link: `https://bbs.saraba1st.com/2b/thread-${tid}-1-1.html`, + link: `${host}/2b/thread-${tid}-1-1.html`, item: resultItems, }; }