diff --git a/lib/routes/sis001/author.ts b/lib/routes/sis001/author.ts new file mode 100644 index 000000000..51fb8b031 --- /dev/null +++ b/lib/routes/sis001/author.ts @@ -0,0 +1,52 @@ +import { Route } from '@/types'; +import cache from '@/utils/cache'; +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { baseUrl, getThread } from './common'; + +export const route: Route = { + path: '/author/:id?', + categories: ['bbs'], + example: '/sis001/author/13131575', + parameters: { id: '作者 ID,可以在作者的个人空间地址找到' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '作者', + maintainers: ['keocheung'], + handler, +}; + +async function handler(ctx) { + const { id = '13131575' } = ctx.req.param(); + const url = `${baseUrl}/forum/space.php?uid=${id}`; + + const response = await got(url); + const $ = load(response.data); + + const username = $('div.username').text(); + + let items = $('div.center_subject ul li a[href^=thread]') + .toArray() + .map((item) => { + item = $(item); + return { + title: item.text(), + link: `${baseUrl}/forum/${item.attr('href')}`, + author: username, + }; + }); + + items = await Promise.all(items.map((item) => cache.tryGet(item.link, async () => await getThread(item)))); + + return { + title: `${username}的主题`, + link: url, + item: items, + }; +} diff --git a/lib/routes/sis001/common.ts b/lib/routes/sis001/common.ts new file mode 100644 index 000000000..51632562b --- /dev/null +++ b/lib/routes/sis001/common.ts @@ -0,0 +1,30 @@ +import got from '@/utils/got'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +const baseUrl = 'https://www.sis001.com'; + +async function getThread(item) { + const response = await got(item.link); + const $ = load(response.data); + + item.category = $('.posttags a') + .toArray() + .map((a) => $(a).text()); + item.pubDate = timezone( + parseDate( + $('.postinfo') + .eq(0) + .text() + .match(/发表于 (.*)\s*只看该作者/)[1], + 'YYYY-M-D HH:mm' + ), + 8 + ); + $('div[id^=postmessage_] table, fieldset, .posttags, strong').remove(); + item.description = $('div[id^=postmessage_]').eq(0).remove('strong').html() + ($('.defaultpost .postattachlist').html() ?? ''); + return item; +} + +export { baseUrl, getThread }; diff --git a/lib/routes/sis001/forum.ts b/lib/routes/sis001/forum.ts index 784db054e..fc55de618 100644 --- a/lib/routes/sis001/forum.ts +++ b/lib/routes/sis001/forum.ts @@ -2,9 +2,7 @@ import { Route } from '@/types'; import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; -import { parseDate } from '@/utils/parse-date'; -import timezone from '@/utils/timezone'; -const baseUrl = 'https://www.sis001.com'; +import { baseUrl, getThread } from './common'; export const route: Route = { path: '/forum/:id?', @@ -43,33 +41,12 @@ async function handler(ctx) { title: item.find('th em').text() + ' ' + item.find('span a').eq(0).text(), link: new URL(item.find('span a').eq(0).attr('href'), `${baseUrl}/forum/`).href, author: item.find('.author a').text(), - pubDate: parseDate(item.find('.author em').text(), 'YYYY-M-D'), }; }); items = await Promise.all( items.map((item) => - cache.tryGet(item.link, async () => { - const response = await got(item.link); - const $ = load(response.data); - - item.category = $('.posttags a') - .toArray() - .map((a) => $(a).text()); - item.pubDate = timezone( - parseDate( - $('.postinfo') - .eq(0) - .text() - .match(/发表于 (.*)\s*只看该作者/)[1], - 'YYYY-M-D HH:mm' - ), - 8 - ); - $('div[id^=postmessage_] table, fieldset, .posttags').remove(); - item.description = $('div[id^=postmessage_]').eq(0).html() + ($('.defaultpost .postattachlist').html() ?? ''); - return item; - }) + cache.tryGet(item.link, async () => await getThread(item)) ) );