diff --git a/src/controller/nhentai/nhentaiGet.ts b/src/controller/nhentai/nhentaiGet.ts index e1093e6..433584d 100644 --- a/src/controller/nhentai/nhentaiGet.ts +++ b/src/controller/nhentai/nhentaiGet.ts @@ -10,7 +10,7 @@ export async function getNhentai(req: any, res: any) { if (isNaN(book)) throw Error("Value must be number"); let actualAPI; - if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP_2; + if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP; const url = `${actualAPI}/api/gallery/${book}`; const data = await scrapeContent(url); diff --git a/src/controller/nhentai/nhentaiRelated.ts b/src/controller/nhentai/nhentaiRelated.ts index 990bb69..6a54174 100644 --- a/src/controller/nhentai/nhentaiRelated.ts +++ b/src/controller/nhentai/nhentaiRelated.ts @@ -10,7 +10,7 @@ export async function relatedNhentai(req: any, res: any) { if (isNaN(book)) throw Error("Value must be number"); let actualAPI; - if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP_2; + if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP; const url = `${actualAPI}/api/gallery/${book}/related`; const data = await scrapeContent(url); diff --git a/src/controller/nhentai/nhentaiSearch.ts b/src/controller/nhentai/nhentaiSearch.ts index 1405c3b..26ca7bb 100644 --- a/src/controller/nhentai/nhentaiSearch.ts +++ b/src/controller/nhentai/nhentaiSearch.ts @@ -13,7 +13,7 @@ export async function searchNhentai(req: any, res: any) { if (!sorting.includes(sort)) throw Error("Invalid short: " + sorting.join(", ")); let actualAPI; - if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP_2; + if (!await mock(c.NHENTAI)) actualAPI = c.NHENTAI_IP; const url = `${actualAPI}/api/galleries/search?query=${key}&sort=${sort}&page=${page}`; const data = await scrapeContent(url); diff --git a/src/utils/modifier.ts b/src/utils/modifier.ts index a255bdc..c26587c 100644 --- a/src/utils/modifier.ts +++ b/src/utils/modifier.ts @@ -1,4 +1,29 @@ import p from "phin"; +import { CookieJar } from "tough-cookie"; +import { HttpsCookieAgent } from "http-cookie-agent/http"; +import { config } from "dotenv"; +import * as pkg from "../../package.json"; +config(); + +const jar = new CookieJar(); +jar.setCookie(process.env.CF as string, "https://nhentai.net/"); + +async function nhentaiStatus(): Promise { + const res = await p({ + url: "https://nhentai.net/api/galleries/search?query=futanari", + core: { + agent: new HttpsCookieAgent({ cookies: { jar, }, }), + }, + "headers": { + "User-Agent": `jandapress/${pkg.version} Node.js/16.9.1` + }, + }); + if (res.statusCode === 200) { + return true; + } else { + return false; + } +} function getPururinInfo(value: string) { return value.replace(/\n/g, " ").replace(/\s\s+/g, " ").trim(); @@ -62,4 +87,4 @@ export const isNumeric = (val: string) : boolean => { }; -export { getPururinInfo, getPururinPageCount, getUrl, getId, getDate, timeAgo, mock }; \ No newline at end of file +export { getPururinInfo, getPururinPageCount, getUrl, getId, getDate, timeAgo, mock, nhentaiStatus }; \ No newline at end of file diff --git a/test/nhentaiCookietest.ts b/test/nhentaiCookietest.ts new file mode 100644 index 0000000..9a72a72 --- /dev/null +++ b/test/nhentaiCookietest.ts @@ -0,0 +1,24 @@ +import p from "phin"; +import { CookieJar } from "tough-cookie"; +import { HttpsCookieAgent } from "http-cookie-agent/http"; +import { config } from "dotenv"; +config(); + +const jar = new CookieJar(); +jar.setCookie("cf_clearance=HBMSCcaARc4EO7JkODYxsgfCoxqBX1gxyRswiHL5VZ4-1654510626-0-150", "https://nhentai.net/"); + +async function test() { + const res = await p({ + url: "https://nhentai.net/api/galleries/search?query=mother", + core: { + agent: new HttpsCookieAgent({ cookies: { jar, }, }), + }, + "headers": { + "User-Agent": "jandapress/1.0.5 Node.js/16.9.1" // nhentai-api-client/3.4.3 Node.js/16.9.1 + }, + }); + //check status + console.log(res.statusCode); +} + +test(); \ No newline at end of file