/
index.ts
126 lines (115 loc) 路 3.78 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { Route } from '@/types';
import cache from '@/utils/cache';
import { load } from 'cheerio';
import zlib from 'zlib';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
import { config } from '@/config';
import { getAcwScV2ByArg1 } from './utils';
export const route: Route = {
path: '/article',
categories: ['game'],
example: '/5eplay/article',
parameters: {},
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['csgo.5eplay.com/', 'csgo.5eplay.com/article'],
},
],
name: '鏂伴椈鍒楄〃',
maintainers: ['Dlouxgit'],
handler,
url: 'csgo.5eplay.com/',
};
async function handler() {
const rootUrl = 'https://csgo.5eplay.com/';
const apiUrl = `${rootUrl}api/article?page=1&type_id=0&time=0&order_by=0`;
const articleUrl = `${rootUrl}article`;
const { data: response } = await got({
method: 'get',
url: apiUrl,
});
// get acw_sc__v2
const acw_sc__v2 = await cache.tryGet(
articleUrl,
async () => {
// Zlib Z_BUF_ERROR: unexpected end of file, should close decompress
const detailResponse = await got(
{
method: 'get',
url: articleUrl,
},
{
decompress: false,
}
);
const unzipData = zlib.createUnzip({
chunkSize: 20 * 1024,
});
unzipData.write(detailResponse.body);
let acw_sc__v2 = '';
for await (const data of unzipData) {
const strData = data.toString();
const matches = strData.match(/var arg1='(.*?)';/);
if (matches) {
acw_sc__v2 = getAcwScV2ByArg1(matches[1]);
break;
}
}
return acw_sc__v2;
},
Math.min(config.cache.routeExpire, 25 * 60),
false
);
const items = await Promise.all(
response.data.list.map((item) =>
cache.tryGet(item.jump_link, async () => {
if (!acw_sc__v2) {
return {
title: item.title,
description: item.title + (item.images?.[0] ? `<img src="${item.images[0]}" />` : ''),
pubDate: parseDate(item.dateline * 1000),
link: item.jump_link,
};
}
const { data: detailResponse } = await got({
method: 'get',
url: item.jump_link,
headers: {
cookie: `acw_sc__v2=${acw_sc__v2}`,
},
});
const $ = load(detailResponse);
const content = $('.article-text');
const res = [];
content.find('> p, > blockquote').each((i, e) => {
res.push($(e).text());
const src = $(e).find('img').first().attr('src');
if (src && !src.includes('data:image/png;base64')) {
// drop base64 img
res.push(`<img src=${src} />`);
}
});
return {
title: item.title,
description: res.join('<br />'),
pubDate: parseDate(item.dateline * 1000),
link: item.jump_link,
};
})
)
);
return {
title: '5EPLAY',
link: 'https://csgo.5eplay.com/article',
item: items,
};
}