feat(route): add 5EPLAY News (#12479)

* feat(route): add 5EPLAY News

#12474

* style(radar.js): only format

* feat(route): add 5EPLAY article detail

* feat(route): tryGet 5EPLAY article detail

* style(route): code style format

* feat(route): update cookie tryGet

* feat(route): remove referrerpolicy

---------

Co-authored-by: Dlouxgit <blue@BluedeMacBook-Pro.local>
This commit is contained in:
Dlouxgit 2023-05-17 16:06:44 +08:00 committed by GitHub
parent db56ef5fca
commit e0bbfb858d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 160 additions and 0 deletions

View File

@ -1033,3 +1033,9 @@ Example`https://www.iyingdi.com/tz/people/55547` id 是 `55547`
### 游戏横幅
<Route author="y2361547758" example="/magireco/event_banner" path="/magireco/event_banner"/>
## 5EPLAY
### 新闻列表
<Route author="Dlouxgit" example="/5eplay/article" path="/5eplay/article"/>

100
lib/v2/5eplay/index.js Normal file
View File

@ -0,0 +1,100 @@
const cheerio = require('cheerio');
const zlib = require('zlib');
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const config = require('@/config').value;
const { getAcwScV2ByArg1 } = require('./utils');
module.exports = async (ctx) => {
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 ctx.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) =>
ctx.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 $ = cheerio.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,
};
})
)
);
ctx.state.data = {
title: '5EPLAY',
link: 'https://csgo.5eplay.com/article',
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/article': ['Dlouxgit'],
};

13
lib/v2/5eplay/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'5eplay.com': {
_name: '5EPLAY',
csgo: [
{
title: '新闻列表',
docs: 'https://docs.rsshub.app/game.html#_5eplay-xin-wen-lie-biao',
source: ['/', '/article'],
target: '/5eplay/article',
},
],
},
};

3
lib/v2/5eplay/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/article', require('.'));
};

35
lib/v2/5eplay/utils.js Normal file
View File

@ -0,0 +1,35 @@
const getAcwScV2ByArg1 = (arg1) => {
const pwd = '3000176000856006061501533003690027800375';
const hexXor = function (box, pwd) {
let res = '';
for (let i = 0x0; i < box.length && i < pwd.length; i += 2) {
const tmp1 = parseInt(box.slice(i, i + 2), 16);
const tmp2 = parseInt(pwd.slice(i, i + 2), 16);
let tmp = (tmp1 ^ tmp2).toString(16);
if (tmp.length === 1) {
tmp = '0' + tmp;
}
res += tmp;
}
return res;
};
const unsbox = function (str) {
const code = [15, 35, 29, 24, 33, 16, 1, 38, 10, 9, 19, 31, 40, 27, 22, 23, 25, 13, 6, 11, 39, 18, 20, 8, 14, 21, 32, 26, 2, 30, 7, 4, 17, 5, 3, 28, 34, 37, 12, 36];
const res = [];
for (let i = 0; i < str.length; i++) {
const cur = str[i];
for (let j = 0; j < code.length; j++) {
if (code[j] === i + 1) {
res[j] = cur;
}
}
}
return res.join('');
};
const box = unsbox(arg1);
return hexXor(box, pwd);
};
module.exports = {
getAcwScV2ByArg1,
};