/
user.ts
83 lines (71 loc) 路 2.32 KB
/
user.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import timezone from '@/utils/timezone';
import { parseDate } from '@/utils/parse-date';
import { rootUrl } from './utils';
export const route: Route = {
path: '/user/:id',
categories: ['new-media'],
example: '/odaily/user/2147486902',
parameters: { id: '鐢ㄦ埛 id锛屽彲鍦ㄧ敤鎴烽〉鍦板潃鏍忎腑鎵惧埌' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['0daily.com/user/:id', '0daily.com/'],
},
],
name: '鐢ㄦ埛鏂囩珷',
maintainers: ['nczitzk'],
handler,
};
async function handler(ctx) {
const id = ctx.req.param('id');
const currentUrl = `${rootUrl}/service/feed_stream/user/${id}?b_id=10&per_page=${ctx.req.query('limit') ?? 25}`;
let author = '';
const response = await got({
method: 'get',
url: currentUrl,
});
let items = response.data.data.items.data.map((item) => ({
title: item.title,
summary: item.summary,
link: `${rootUrl}/post/${item.entity_id}`,
pubDate: timezone(parseDate(item.published_at), +8),
}));
items = await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = load(detailResponse.data.match(/"content":"(.*)","extraction_tags":/)[1]);
content('img').each(function () {
content(this).attr(
'src',
content(this)
.attr('src')
.replaceAll(String.raw`\"`, '')
);
});
item.description = content.html();
item.author = author = detailResponse.data.match(/"name":"(.*)","role_id/)[1];
return item;
})
)
);
return {
title: `${author} - Odaily鏄熺悆鏃ユ姤`,
link: `${rootUrl}/user/${id}`,
item: items,
};
}