-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloudflare enabled on API endpoints #25
Comments
That's site issue for sure. |
sometimes api works but most time it doesn't. I hope api can be work again cuz this is the most comfortable nhentai api in my mind <3 |
Current workaround: // index.mjs
import { API, TagTypes, } from 'nhentai-api';
import { CookieJar } from 'tough-cookie';
import _httpCookie from 'http-cookie-agent/http';
const { HttpsCookieAgent: CookieAgent } = _httpCookie;
const jar = new CookieJar();
const agent = new CookieAgent({ cookies: { jar, }, });
jar.setCookie('cf_clearance=4iV5fuQ0.prnWCqcZ.kqLFV6hp.QQ5y_lRkEw97N3ZA-1653929202-0-150', 'https://nhentai.net/');
const api = new API({ agent, });
api.getBook(177013).then(book => {
console.log(book.title.pretty);
}); To get
|
Is this permanent or need to be refreshed once in a while? 🤔 |
@Chaoray, sadly, it's temporary and you'll need to refresh it, |
OK, I think it is enough for personal usage. |
Make sure you got right token for right User Agents, check if UA Header is the one using by your node. |
There is at least has 2 workarounds:
@Zekfad one question, But when i just arbitrary ie: import p from "phin";
import { CookieJar } from "tough-cookie";
import { HttpsCookieAgent } from "http-cookie-agent/http";
const jar = new CookieJar();
jar.setCookie("some cookie", "https://nhentai.net/");
async function test() {
const res = await p({
url: "https://nhentai.net/api/galleries/search?query=futa",
core: {
agent: new HttpsCookieAgent({ cookies: { jar, }, }),
},
"headers": {
"User-Agent": "jandapress/1.0.5 Node.js/16.9.1" // just worked with "nhentai-api-client", cannot use my own even i've already to set it
},
});
console.log(res.statusCode);
}
test(); |
@sinkaroid token is linked to the user agent, so you have to get new one for each UA you use. |
Thanks it's working now |
How to use their IP? Edit: |
Indeed it won't. I mean, token is IP bound. If you have your server you can of course start proxy, and complete challenge though proxy, to get valid token for given IP. |
Ok¯\_(ツ)_/¯ const api = new API({
hosts: {
api: '35.186.156.165'
},
ssl: false
}); Like this? |
Oh, so that's why it wasn't working. |
@Chaoray, just IP, don't specify URI. Also, disable SSL. |
Using site IPs is perfect but |
@Zekfad How would I use IP instead of the default URL? I tried from this but kept getting errors const api = new API({
hosts: {
api: '35.186.156.165'
},
ssl: false
}); |
I guess it's no longer possible to bypass it this way, as both IPs I know doesn't work. |
The IP http://138.2.77.198:3002 works on the browser though. at least to me |
Hey It's working on my local, but how to use this with repl / railway / or heroku? |
It's the nhentai address? how did you know? |
Same question here, hence I thought using the IP might work.
https://github.com/sinkaroid/jandapress/blob/master/src/utils/options.ts#L10 |
Now how to use this with nhentai-api |
No, you can't. Nhentai blocked direct ip access, which was the previous method we were using before it was blocked. |
@Chaoray this is incorrect. The direct IP access error comes from the fact that the IP the person attempted to use was a Cloudflare network IP, which naturally disallows direct access (otherwise how would they know what you're trying to connect to?). If you navigate to the IP and port, with With a bit of patching, you can get the library to work fine with the IP address: diff --git a/node_modules/nhentai-api/dist/cjs/bundle.cjs b/node_modules/nhentai-api/dist/cjs/bundle.cjs
index 46ad4e5..840d3b3 100644
--- a/node_modules/nhentai-api/dist/cjs/bundle.cjs
+++ b/node_modules/nhentai-api/dist/cjs/bundle.cjs
@@ -507,7 +507,7 @@ class API{
* Applies provided options on top of defaults.
* @param {?nHentaiOptions} [options={}] Options to apply.
*/
-constructor(options={}){_defineProperty(this,"hosts",void 0),_defineProperty(this,"ssl",void 0),_defineProperty(this,"agent",void 0);let params=function processOptions({hosts:{api:api="nhentai.net",images:images="i.nhentai.net",thumbs:thumbs="t.nhentai.net"}={},ssl:ssl=!0,agent:agent=null}={}){return agent||(agent=ssl?https.Agent:http.Agent),"Function"===agent.constructor.name&&(agent=new agent),{hosts:{api:api,images:images,thumbs:thumbs},ssl:ssl,agent:agent}}(options);Object.assign(this,params)}
+constructor(options={}){_defineProperty(this,"hosts",void 0),_defineProperty(this,"ssl",void 0),_defineProperty(this,"agent",void 0);let params=function processOptions({hosts:{api:api="138.2.77.198",images:images="i.nhentai.net",thumbs:thumbs="t.nhentai.net"}={},ssl:ssl=!0,agent:agent=null}={}){return agent||(agent=ssl?https.Agent:http.Agent),"Function"===agent.constructor.name&&(agent=new agent),{hosts:{api:api,images:images,thumbs:thumbs},ssl:ssl,agent:agent}}(options);Object.assign(this,params)}
/**
* Get http(s) module depending on `options.ssl`.
* @type {https|http}
@@ -518,7 +518,7 @@ constructor(options={}){_defineProperty(this,"hosts",void 0),_defineProperty(thi
* @param {string} options.host Host.
* @param {string} options.path Path.
* @returns {Promise<object>} Parsed JSON.
- */request(options){let{net:net,agent:agent}=this;return new Promise(((resolve,reject)=>{Object.assign(options,{agent:agent,headers:{"User-Agent":`nhentai-api-client/3.4.3 Node.js/${process.versions.node}`}}),net.get(options,(_response=>{const
+ */request(options){let net=(options.host==="138.2.77.198"?http__default.default:this.net),agent=(options.host==="138.2.77.198"?new http.Agent():this.agent);return new Promise(((resolve,reject)=>{Object.assign(options,{agent:agent,headers:{"User-Agent":`nhentai-api-client/3.4.3 Node.js/${process.versions.node}`}}),net.get({...options,port:options.host==="138.2.77.198"?3002:undefined},(_response=>{const
/** @type {IncomingMessage}*/
response=_response,{statusCode:statusCode}=response,contentType=response.headers["content-type"];let error;if(200!==statusCode?error=new Error(`Request failed with status code ${statusCode}`):/^application\/json/.test(contentType)||(error=new Error(`Invalid content-type - expected application/json but received ${contentType}`)),error)return response.resume(),void reject(APIError.absorb(error,response));response.setEncoding("utf8");let rawData="";response.on("data",(chunk=>rawData+=chunk)),response.on("end",(()=>{try{resolve(JSON.parse(rawData))}catch(error){reject(APIError.absorb(error,response))}}))})).on("error",(error=>reject(APIError.absorb(error))))}))}
/** (this can be thrown into a patch-package Obviously this patch is very.. hacky: it doesn't support custom agents (if you use those) and it recreates the HTTP agent every time, but it does indeed work. First-party support shouldn't be too terrible and I'll probably contribute it myself when I get around to it. |
Issue regarding port number support can be tracked in #26 now. |
@LewisTehMinerz Can you tell me how to get the real ip behind cloudflare? |
You can't. It's just that nhentai's IP address was already known and appears to have been public for ages. I got that IP address from the previous posts here. |
Ok, I tried your solution but it seemed not working to me :P |
How long |
About few hours, you can see cookie expiration date. |
@Zekfad where is the actual i can view the cookie expiration date, it's on chrome browser or where, |
@soujiokita DevTools -> Application -> Cookies, there is the Expiration date. |
they enabled cf on this IP yesterday for a few hours |
Try this url on an http client: https://nhentai.net/api/gallery/177013
The text was updated successfully, but these errors were encountered: