fix(route/saraba1st): add host config & change default host (#18895)
This commit is contained in:
parent
ccb708846d
commit
10288db67d
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="quoted" style="background:rgba(220,220,220,0.3);">
|
||||
<a style="text-decoration: none;" href="https://bbs.saraba1st.com/2b/{{ author.link }}">{{ author.name }}</a>
|
||||
<a style="text-decoration: none;" href="{{ host }}/2b/{{ author.link }}">{{ author.name }}</a>
|
||||
<span style="text-decoration: none;color:#aaa;">{{ author.postinfo }}</span>
|
||||
</div>
|
||||
<div class="content" style="margin-bottom:20px!important;">{{@ msg }}</div>
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue