/
index.ts
63 lines (53 loc) · 1.65 KB
/
index.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
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/',
radar: [
{
source: ['getdr.com/'],
target: '',
},
],
name: 'Unknown',
maintainers: ['nczitzk'],
handler,
url: 'getdr.com/',
};
async function handler() {
const rootUrl = 'https://getdr.com/最新詐騙情報';
const apiUrl = 'https://public-api.wordpress.com/rest/v1.1/sites/demogetdr.wordpress.com/posts';
const response = await got({
method: 'get',
url: apiUrl,
});
const list = response.data.posts.map((item) => ({
link: item.URL,
title: item.title,
author: item.author.name,
pubDate: parseDate(item.date),
}));
const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = load(detailResponse.data);
content('.wp-block-image').each(function () {
content(this).html(`<img src="${content(this).find('img').attr('data-orig-file')}">`);
});
item.description = content('div[data-widget_type="theme-post-content.default"]').html();
return item;
})
)
);
return {
title: '最新詐騙情報 - 趨勢科技防詐達人',
link: rootUrl,
item: items,
};
}