Skip to content

Commit

Permalink
feat(route): add sis001 author (#16609)
Browse files Browse the repository at this point in the history
* feat(route): add sis001 author

* feat(route): fix default id

* feat(route): fix id
  • Loading branch information
keocheung authored Sep 3, 2024
1 parent 608aa67 commit d77d4e5
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 25 deletions.
52 changes: 52 additions & 0 deletions lib/routes/sis001/author.ts
Original file line number Diff line number Diff line change
@@ -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,
};
}
30 changes: 30 additions & 0 deletions lib/routes/sis001/common.ts
Original file line number Diff line number Diff line change
@@ -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 };
27 changes: 2 additions & 25 deletions lib/routes/sis001/forum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?',
Expand Down Expand Up @@ -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))
)
);

Expand Down

0 comments on commit d77d4e5

Please sign in to comment.