holz-provider
Advanced tools
Comparing version 0.2.4 to 0.3.0
@@ -8,2 +8,3 @@ "use strict"; | ||
const https_1 = __importDefault(require("https")); | ||
const querystring_1 = require("querystring"); | ||
const types_1 = require("./types"); | ||
@@ -61,13 +62,6 @@ exports.PROVIDER_ID = "holz"; | ||
const interval = setInterval(() => { | ||
const data = JSON.stringify({ | ||
cid: cid | ||
}); | ||
const requestOptions = { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Content-Length": data.length | ||
} | ||
method: "GET" | ||
}; | ||
const request = https_1.default.request(new URL("https://holz.wolkeneis.dev/api"), requestOptions, (response) => { | ||
const request = https_1.default.request(new URL(`https://holz.wolkeneis.dev/api/?${(0, querystring_1.stringify)({ cid: cid })}`), requestOptions, (response) => { | ||
let body = ""; | ||
@@ -106,3 +100,2 @@ response.on("data", (chunk) => { | ||
}); | ||
request.write(data); | ||
request.end(); | ||
@@ -109,0 +102,0 @@ }, 10000); |
{ | ||
"name": "holz-provider", | ||
"version": "0.2.4", | ||
"version": "0.3.0", | ||
"description": "Holz Captcha Provider + Server", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
@@ -8,2 +8,3 @@ import https, { RequestOptions } from "https"; | ||
} from "puppeteer-extra-plugin-recaptcha/dist/types"; | ||
import { stringify } from "querystring"; | ||
import { Captcha, isCaptcha } from "./types"; | ||
@@ -72,41 +73,38 @@ | ||
const interval = setInterval(() => { | ||
const data = JSON.stringify({ | ||
cid: cid | ||
}); | ||
const requestOptions: RequestOptions = { | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Content-Length": data.length | ||
} | ||
method: "GET" | ||
}; | ||
const request = https.request(new URL("https://holz.wolkeneis.dev/api"), requestOptions, (response) => { | ||
let body = ""; | ||
response.on("data", (chunk) => { | ||
body += chunk; | ||
}); | ||
response.on("end", () => { | ||
if (response.statusCode !== 200) { | ||
clearTime(); | ||
return reject(body); | ||
} | ||
let captcha: Captcha; | ||
try { | ||
captcha = JSON.parse(body); | ||
if (!isCaptcha(captcha)) { | ||
const request = https.request( | ||
new URL(`https://holz.wolkeneis.dev/api/?${stringify({ cid: cid })}`), | ||
requestOptions, | ||
(response) => { | ||
let body = ""; | ||
response.on("data", (chunk) => { | ||
body += chunk; | ||
}); | ||
response.on("end", () => { | ||
if (response.statusCode !== 200) { | ||
clearTime(); | ||
return reject(`Invalid captcha: ${JSON.stringify(captcha)}`); | ||
return reject(body); | ||
} | ||
if (!captcha.token) { | ||
return; | ||
let captcha: Captcha; | ||
try { | ||
captcha = JSON.parse(body); | ||
if (!isCaptcha(captcha)) { | ||
clearTime(); | ||
return reject(`Invalid captcha: ${JSON.stringify(captcha)}`); | ||
} | ||
if (!captcha.token) { | ||
return; | ||
} | ||
clearTime(); | ||
return resolve(captcha); | ||
} catch (error) { | ||
clearTime(); | ||
return reject((error as Error).toString()); | ||
} | ||
clearTime(); | ||
return resolve(captcha); | ||
} catch (error) { | ||
clearTime(); | ||
return reject((error as Error).toString()); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
); | ||
request.on("error", (error) => { | ||
@@ -117,3 +115,2 @@ request.destroy(); | ||
}); | ||
request.write(data); | ||
request.end(); | ||
@@ -120,0 +117,0 @@ }, 10000); |
Sorry, the diff of this file is not supported yet
159090
601