From e0bbfb858dabd4f5705c2ac3afa76c7d7d4def70 Mon Sep 17 00:00:00 2001 From: Dlouxgit <57781857+Dlouxgit@users.noreply.github.com> Date: Wed, 17 May 2023 16:06:44 +0800 Subject: [PATCH] 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 --- docs/game.md | 6 +++ lib/v2/5eplay/index.js | 100 ++++++++++++++++++++++++++++++++++++ lib/v2/5eplay/maintainer.js | 3 ++ lib/v2/5eplay/radar.js | 13 +++++ lib/v2/5eplay/router.js | 3 ++ lib/v2/5eplay/utils.js | 35 +++++++++++++ 6 files changed, 160 insertions(+) create mode 100644 lib/v2/5eplay/index.js create mode 100644 lib/v2/5eplay/maintainer.js create mode 100644 lib/v2/5eplay/radar.js create mode 100644 lib/v2/5eplay/router.js create mode 100644 lib/v2/5eplay/utils.js diff --git a/docs/game.md b/docs/game.md index 30488565e..c1b475db1 100644 --- a/docs/game.md +++ b/docs/game.md @@ -1033,3 +1033,9 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547` ### 游戏横幅 + +## 5EPLAY + +### 新闻列表 + + diff --git a/lib/v2/5eplay/index.js b/lib/v2/5eplay/index.js new file mode 100644 index 000000000..fda633f71 --- /dev/null +++ b/lib/v2/5eplay/index.js @@ -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] ? `` : ''), + 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(``); + } + }); + + return { + title: item.title, + description: res.join('
'), + pubDate: parseDate(item.dateline * 1000), + link: item.jump_link, + }; + }) + ) + ); + + ctx.state.data = { + title: '5EPLAY', + link: 'https://csgo.5eplay.com/article', + item: items, + }; +}; diff --git a/lib/v2/5eplay/maintainer.js b/lib/v2/5eplay/maintainer.js new file mode 100644 index 000000000..6502497eb --- /dev/null +++ b/lib/v2/5eplay/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/article': ['Dlouxgit'], +}; diff --git a/lib/v2/5eplay/radar.js b/lib/v2/5eplay/radar.js new file mode 100644 index 000000000..3db73274d --- /dev/null +++ b/lib/v2/5eplay/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/5eplay/router.js b/lib/v2/5eplay/router.js new file mode 100644 index 000000000..297fec2bd --- /dev/null +++ b/lib/v2/5eplay/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get('/article', require('.')); +}; diff --git a/lib/v2/5eplay/utils.js b/lib/v2/5eplay/utils.js new file mode 100644 index 000000000..8626af514 --- /dev/null +++ b/lib/v2/5eplay/utils.js @@ -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, +};