diff options
author | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-28 07:21:00 +0200 |
---|---|---|
committer | Heiner Lohaus <heiner@lohaus.eu> | 2023-10-28 07:21:00 +0200 |
commit | dc04ca93060443a3ce6263a476f4dafc66afc6b3 (patch) | |
tree | b9c645cbe897af198ea0551509f901a249af35f2 /g4f/Provider/npm/node_modules/funcaptcha/lib/session.js | |
parent | Update config supports_message_history (diff) | |
download | gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.gz gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.bz2 gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.lz gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.xz gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.tar.zst gpt4free-dc04ca93060443a3ce6263a476f4dafc66afc6b3.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/npm/node_modules/funcaptcha/lib/session.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/g4f/Provider/npm/node_modules/funcaptcha/lib/session.js b/g4f/Provider/npm/node_modules/funcaptcha/lib/session.js new file mode 100644 index 00000000..e2216d3b --- /dev/null +++ b/g4f/Provider/npm/node_modules/funcaptcha/lib/session.js @@ -0,0 +1,77 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Session = void 0; +const challenge_1 = require("./challenge"); +const http_1 = require("./http"); +const util_1 = require("./util"); +let parseToken = (token) => Object.fromEntries(token + .split("|") + .map((v) => v.split("=").map((v) => decodeURIComponent(v)))); +class Session { + constructor(token, sessionOptions) { + var _a; + if (typeof token === "string") { + this.token = token; + } + else { + this.token = token.token; + } + if (!this.token.startsWith("token=")) + this.token = "token=" + this.token; + this.tokenInfo = parseToken(this.token); + this.tokenInfo.mbio = typeof (token) !== "string" ? (_a = token.mbio) !== null && _a !== void 0 ? _a : false : false; + this.userAgent = (sessionOptions === null || sessionOptions === void 0 ? void 0 : sessionOptions.userAgent) || util_1.default.DEFAULT_USER_AGENT; + this.proxy = sessionOptions === null || sessionOptions === void 0 ? void 0 : sessionOptions.proxy; + } + async getChallenge() { + let res = await (0, http_1.default)(this.tokenInfo.surl, { + path: "/fc/gfct/", + method: "POST", + body: util_1.default.constructFormData({ + sid: this.tokenInfo.r, + render_type: "canvas", + token: this.tokenInfo.token, + analytics_tier: this.tokenInfo.at, + "data%5Bstatus%5D": "init", + lang: "en", + apiBreakerVersion: "green" + }), + headers: { + "User-Agent": this.userAgent, + "Content-Type": "application/x-www-form-urlencoded", + "Accept-Language": "en-US,en;q=0.9", + "Sec-Fetch-Site": "same-origin", + "Referer": this.getEmbedUrl() + }, + }, this.proxy); + let data = JSON.parse(res.body.toString()); + data.token = this.token; + data.tokenInfo = this.tokenInfo; + if (data.game_data.gameType == 1) { + return new challenge_1.Challenge1(data, { + proxy: this.proxy, + userAgent: this.userAgent, + }); + } + else if (data.game_data.gameType == 3) { + return new challenge_1.Challenge3(data, { + proxy: this.proxy, + userAgent: this.userAgent, + }); + } + else if (data.game_data.gameType == 4) { + return new challenge_1.Challenge4(data, { + proxy: this.proxy, + userAgent: this.userAgent, + }); + } + else { + throw new Error("Unsupported game type: " + data.game_data.gameType); + } + //return res.body.toString() + } + getEmbedUrl() { + return `${this.tokenInfo.surl}/fc/gc/?${util_1.default.constructFormData(this.tokenInfo)}`; + } +} +exports.Session = Session; |