-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add sis001 author (#16609)
* feat(route): add sis001 author * feat(route): fix default id * feat(route): fix id
- Loading branch information
Showing
3 changed files
with
84 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters