From 27577b48ca227a333988bf8f42757821e98fa9f3 Mon Sep 17 00:00:00 2001 From: Richard Yu Date: Thu, 16 Apr 2020 19:40:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20steamdb=20blocked=20by=20cloudflare,=20w?= =?UTF-8?q?rong=20=20ordinal=20and=20allo=E2=80=A6=20(#4451)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/steam/steamdb/free.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/routes/steam/steamdb/free.js b/lib/routes/steam/steamdb/free.js index 9754e4ba8a..e78a9bd874 100644 --- a/lib/routes/steam/steamdb/free.js +++ b/lib/routes/steam/steamdb/free.js @@ -1,10 +1,10 @@ -const got = require('@/utils/got'); +const cloudscraper = require('cloudscraper'); const cheerio = require('cheerio'); module.exports = async (ctx) => { const { type } = ctx.params; const url = 'https://steamdb.info/upcoming/free'; - const { data: html } = await got.get(url); + const html = await cloudscraper.get(url); const $ = cheerio.load(html); const $trs = $('.container table.table-products:first-of-type tbody tr'); @@ -26,14 +26,14 @@ module.exports = async (ctx) => { // title - 1 const title = $($tds.get(1)).text().trim(); - // promotion type - 2 - const promoType = $($tds.get(2)).text().trim(); + // promotion type - 3 + const promoType = $($tds.get(3)).text().trim(); - // startDate - 3 - const startDate = $tds.get(3).attribs.title; + // startDate - 4 + const startDate = $tds.get(4).attribs.title; - // endDate - 4 - // const endDate = $tds.get(4).attribs.title; + // endDate - 5 + // const endDate = $tds.get(5).attribs.title; // ignore items without appid or not matched the type if (!appid || (type && type.toLowerCase() !== promoType.toLocaleLowerCase())) { @@ -42,7 +42,7 @@ module.exports = async (ctx) => { const hoverLink = `https://steamdb.info/api/RenderAppHover/?appid=${appid}`; const description = await ctx.cache.tryGet(hoverLink, async () => { - const { data: description } = await got.get(hoverLink); + const description = await cloudscraper.get(hoverLink); return description; }); @@ -60,5 +60,6 @@ module.exports = async (ctx) => { title: 'Steam 免费游戏 [SteamDB]', link: url, item: item.filter((itm) => !!itm), + allowEmpty: true, }; };