/
notice.ts
83 lines (77 loc) 路 2.2 KB
/
notice.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 { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
const typeMap = {
0: '9004748',
1: '9004749',
2: '9213612',
3: '8314815',
4: '9222707',
};
/**
*
* @param ctx {import('koa').Context}
*/
export const route: Route = {
path: '/notice/:type?',
categories: ['programming'],
example: '/aliyun/notice',
parameters: { type: 'N' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '鍏憡',
maintainers: ['muzea'],
handler,
description: `| 绫诲瀷 | type |
| -------- | ---- |
| 鍏ㄩ儴 | |
| 鍗囩骇鍏憡 | 1 |
| 瀹夊叏鍏憡 | 2 |
| 澶囨鍏憡 | 3 |
| 鍏朵粬 | 4 |`,
};
async function handler(ctx) {
const type = ctx.req.param('type');
const url = `https://help.aliyun.com/noticelist/${typeMap[type] || typeMap[0]}.html`;
const response = await got({ method: 'get', url });
const $ = load(response.data);
const list = $('ul > li.notice-li')
.map((i, e) => {
const element = $(e);
const title = element.find('a').text().trim();
const link = 'https://help.aliyun.com' + element.find('a').attr('href').trim();
const date = element.find('.y-right').text();
const pubDate = timezone(parseDate(date), +8);
return {
title,
description: '',
link,
pubDate,
};
})
.get();
const result = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const itemReponse = await got(item.link);
const itemElement = load(itemReponse.data);
item.description = itemElement('#se-knowledge').html();
return item;
})
)
);
return {
title: $('title').text().trim(),
link: url,
item: result,
};
}