From e326e71bfcb0c11846c03cbcf3290681ac8fdd2f Mon Sep 17 00:00:00 2001 From: Gim949 Date: Wed, 16 Nov 2022 19:12:36 -0500 Subject: [PATCH] Add workaround for cloudflare --- lib/util/Request.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/util/Request.js b/lib/util/Request.js index 3e42926..93d4e82 100644 --- a/lib/util/Request.js +++ b/lib/util/Request.js @@ -3,6 +3,7 @@ const cheerio = require("cheerio"); const Qs = require("qs"); const baseUrl = "https://nhentai.net"; +const pipeUrl = (url) => `https://translate.google.com/translate?sl=vi&tl=en&hl=vi&u=${url}&client=webapp`; /** * @class Request @@ -17,7 +18,7 @@ module.exports = class Request { * @returns {object|null} nHentai book API */ async getBook(bookID) { - let json = `${baseUrl}/api/gallery/${bookID}`; + let json = pipeUrl(`${baseUrl}/api/gallery/${bookID}`); return axios .get(json) @@ -36,7 +37,7 @@ module.exports = class Request { * @return {object|null} nHentai book API */ async getRelated(bookID) { - let json = `${baseUrl}/api/gallery/${bookID}/related`; + let json = pipeUrl(`${baseUrl}/api/gallery/${bookID}/related`); return axios .get(json) @@ -56,7 +57,7 @@ module.exports = class Request { */ async getList(url) { return axios - .get(url) + .get(pipeUrl(url)) .then((res) => { const $ = cheerio.load(res.data, { decodeEntities: false, @@ -131,7 +132,7 @@ module.exports = class Request { * @returns {object} nHentai popular list */ async getPopularNow() { - return axios.get(baseUrl).then((res) => { + return axios.get(pipeUrl(baseUrl)).then((res) => { const $ = cheerio.load(res.data, { decodeEntities: false, });