summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/npm/node_modules/funcaptcha/src/api.ts
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-28 09:22:33 +0200
committerGitHub <noreply@github.com>2023-10-28 09:22:33 +0200
commit1a3b59838e21b98b5cfcafddf1737afb25129cfe (patch)
treeb9c645cbe897af198ea0551509f901a249af35f2 /g4f/Provider/npm/node_modules/funcaptcha/src/api.ts
parentMerge pull request #1176 from hlohaus/history (diff)
parentAdd arkose_token to OpenaiChat (diff)
downloadgpt4free-1a3b59838e21b98b5cfcafddf1737afb25129cfe.tar
gpt4free-1a3b59838e21b98b5cfcafddf1737afb25129cfe.tar.gz
gpt4free-1a3b59838e21b98b5cfcafddf1737afb25129cfe.tar.bz2
gpt4free-1a3b59838e21b98b5cfcafddf1737afb25129cfe.tar.lz
gpt4free-1a3b59838e21b98b5cfcafddf1737afb25129cfe.tar.xz
gpt4free-1a3b59838e21b98b5cfcafddf1737afb25129cfe.tar.zst
gpt4free-1a3b59838e21b98b5cfcafddf1737afb25129cfe.zip
Diffstat (limited to 'g4f/Provider/npm/node_modules/funcaptcha/src/api.ts')
-rw-r--r--g4f/Provider/npm/node_modules/funcaptcha/src/api.ts85
1 files changed, 85 insertions, 0 deletions
diff --git a/g4f/Provider/npm/node_modules/funcaptcha/src/api.ts b/g4f/Provider/npm/node_modules/funcaptcha/src/api.ts
new file mode 100644
index 00000000..6582750d
--- /dev/null
+++ b/g4f/Provider/npm/node_modules/funcaptcha/src/api.ts
@@ -0,0 +1,85 @@
+import request from "./http";
+import util from "./util";
+
+export interface GetTokenOptions {
+ pkey: string;
+ // Service URL
+ surl?: string;
+ data?: { [key: string]: string };
+ headers?: { [key: string]: string };
+ site?: string;
+ // Page URL
+ location?: string;
+ proxy?: string;
+ language?: string;
+}
+
+export interface GetTokenResult {
+ challenge_url: string;
+ challenge_url_cdn: string;
+ challenge_url_cdn_sri: string;
+ disable_default_styling: boolean | null;
+ iframe_height: number | null;
+ iframe_width: number | null;
+ // Enable keyboard biometrics
+ kbio: boolean;
+ // Enable mouse biometrics
+ mbio: boolean;
+ noscript: string;
+ // Enable touch biometrics
+ tbio: boolean;
+ // The token for the funcaptcha. Can be used 10 times before having to get a new token.
+ token: string;
+}
+
+export async function getToken(
+ options: GetTokenOptions
+): Promise<GetTokenResult> {
+ options = {
+ surl: "https://client-api.arkoselabs.com",
+ data: {},
+ ...options,
+ };
+
+ if (!options.headers)
+ options.headers = { "User-Agent": util.DEFAULT_USER_AGENT };
+ else if (!Object.keys(options.headers).map(v => v.toLowerCase()).includes("user-agent"))
+ options.headers["User-Agent"] = util.DEFAULT_USER_AGENT;
+
+ options.headers["Accept-Language"] = "en-US,en;q=0.9";
+ options.headers["Sec-Fetch-Site"] = "same-origin";
+ options.headers["Accept"] = "*/*";
+ options.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8";
+ options.headers["sec-fetch-mode"] = "cors"
+
+ if (options.site) {
+ options.headers["Origin"] = options.surl
+ options.headers["Referer"] = `${options.surl}/v2/${options.pkey}/1.5.5/enforcement.fbfc14b0d793c6ef8359e0e4b4a91f67.html`
+ }
+
+ let ua = options.headers[Object.keys(options.headers).find(v => v.toLowerCase() == "user-agent")]
+
+ let res = await request(
+ options.surl,
+ {
+ method: "POST",
+ path: "/fc/gt2/public_key/" + options.pkey,
+ body: util.constructFormData({
+ bda: util.getBda(ua, options),
+ public_key: options.pkey,
+ site: options.site ? new URL(options.site).origin : undefined,
+ userbrowser: ua,
+ capi_version: "1.5.5",
+ capi_mode: "inline",
+ style_theme: "default",
+ rnd: Math.random().toString(),
+ ...Object.fromEntries(Object.keys(options.data).map(v => ["data[" + v + "]", options.data[v]])),
+ language: options.language || "en",
+ }),
+ headers: options.headers,
+ },
+ options.proxy
+ );
+
+ return JSON.parse(res.body.toString());
+}