/
baoliao.ts
68 lines (61 loc) · 2.03 KB
/
baoliao.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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';
export const route: Route = {
path: '/baoliao/:uid',
categories: ['shopping'],
example: '/smzdm/baoliao/7367111021',
parameters: { uid: '用户id,网址上直接可以看到' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['zhiyou.smzdm.com/member/:uid/baoliao'],
},
],
name: '用户爆料',
maintainers: ['nczitzk'],
handler,
};
async function handler(ctx) {
const link = `https://zhiyou.smzdm.com/member/${ctx.req.param('uid')}/baoliao/`;
const response = await got(link);
const $ = load(response.data);
const title = $('.info-stuff-nickname').text();
const list = $('.pandect-content-stuff')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.find('.pandect-content-title a').text(),
link: item.find('.pandect-content-title a').attr('href'),
pubDate: timezone(parseDate(item.find('.pandect-content-time').text(), ['YYYY-MM-DD', 'MM-DD HH:mm']), +8),
};
});
const out = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const response = await got(item.link);
const $ = load(response.data);
item.description = $('article.txt-detail').html();
item.pubDate = timezone(parseDate($('.time').first().text().trim().replace('更新时间:', '')), 8);
item.author = title;
return item;
})
)
);
return {
title: `${title}的爆料 - 什么值得买`,
link,
item: out,
};
}