From 2dd0033b4b5d49d53b694f040206424709b59bca Mon Sep 17 00:00:00 2001 From: Dlouxgit <57781857+Dlouxgit@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:26:19 +0800 Subject: [PATCH] fix(route/5eplay): update data acquisition method (#17120) fix #17067 --- lib/routes/5eplay/index.ts | 52 +------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/lib/routes/5eplay/index.ts b/lib/routes/5eplay/index.ts index 60e15b737..26c76bf4d 100644 --- a/lib/routes/5eplay/index.ts +++ b/lib/routes/5eplay/index.ts @@ -1,11 +1,8 @@ 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', @@ -34,70 +31,23 @@ export const route: Route = { 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] ? `` : ''), - 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 = []; + const res: string[] = []; content.find('> p, > blockquote').each((i, e) => { res.push($(e).text());