HerzaJ commited on
Commit
95e0eeb
·
verified ·
1 Parent(s): 6fc5530

Update plugins/cloudflare-bypass.js

Browse files
Files changed (1) hide show
  1. plugins/cloudflare-bypass.js +34 -35
plugins/cloudflare-bypass.js CHANGED
@@ -1,61 +1,60 @@
 
 
1
  const BASE_URL = 'https://herzaj-turnstile-solver.hf.space';
2
 
3
  async function callBypassAPI(url, sitekey) {
4
  try {
5
- const submitResponse = await fetch(`${BASE_URL}/turnstile?url=${encodeURIComponent(url)}&sitekey=${encodeURIComponent(sitekey)}`, {
 
 
 
 
6
  headers: {
7
  'Accept': 'application/json',
8
  'Content-Type': 'application/json'
9
  }
10
  });
11
-
12
- const submitText = await submitResponse.text();
13
- let submitData;
14
-
15
- try {
16
- submitData = JSON.parse(submitText);
17
- } catch (e) {
18
- throw new Error(`API returned invalid response: ${submitText.substring(0, 100)}`);
19
- }
20
-
21
  if (!submitData.task_id) {
22
  throw new Error('Failed to get task_id from API');
23
  }
24
 
25
  const taskId = submitData.task_id;
26
 
 
 
27
  let attempts = 0;
28
  const maxAttempts = 30;
29
 
30
  while (attempts < maxAttempts) {
31
- await new Promise(resolve => setTimeout(resolve, 2000));
32
-
33
- const resultResponse = await fetch(`${BASE_URL}/result/${taskId}`, {
34
- headers: {
35
- 'Accept': 'application/json'
36
- }
37
- });
38
-
39
- const resultText = await resultResponse.text();
40
- let resultData;
41
-
42
  try {
43
- resultData = JSON.parse(resultText);
44
- } catch (e) {
45
- attempts++;
46
- continue;
47
- }
48
-
49
- if (resultData.value) {
50
- return {
51
- token: resultData.value,
52
- solved_time: resultData.elapsed_time
53
- };
 
 
 
 
 
 
 
 
54
  }
55
-
 
56
  attempts++;
57
  }
58
-
59
  throw new Error('Timeout: Could not solve turnstile within time limit');
60
 
61
  } catch (error) {
 
1
+ const axios = require('axios');
2
+
3
  const BASE_URL = 'https://herzaj-turnstile-solver.hf.space';
4
 
5
  async function callBypassAPI(url, sitekey) {
6
  try {
7
+ const submitResponse = await axios.get(`${BASE_URL}/turnstile`, {
8
+ params: {
9
+ url: url,
10
+ sitekey: sitekey
11
+ },
12
  headers: {
13
  'Accept': 'application/json',
14
  'Content-Type': 'application/json'
15
  }
16
  });
17
+
18
+ const submitData = submitResponse.data;
19
+
 
 
 
 
 
 
 
20
  if (!submitData.task_id) {
21
  throw new Error('Failed to get task_id from API');
22
  }
23
 
24
  const taskId = submitData.task_id;
25
 
26
+ await new Promise(resolve => setTimeout(resolve, 5000));
27
+
28
  let attempts = 0;
29
  const maxAttempts = 30;
30
 
31
  while (attempts < maxAttempts) {
 
 
 
 
 
 
 
 
 
 
 
32
  try {
33
+ const resultResponse = await axios.get(`${BASE_URL}/result/${taskId}`, {
34
+ headers: {
35
+ 'Accept': 'application/json'
36
+ }
37
+ });
38
+
39
+ const resultData = resultResponse.data;
40
+
41
+ if (resultData.value) {
42
+ return {
43
+ token: resultData.value,
44
+ solved_time: resultData.elapsed_time
45
+ };
46
+ }
47
+
48
+ } catch (error) {
49
+ if (error.response && error.response.status !== 404) {
50
+ console.error(error.message);
51
+ }
52
  }
53
+
54
+ await new Promise(resolve => setTimeout(resolve, 2000));
55
  attempts++;
56
  }
57
+
58
  throw new Error('Timeout: Could not solve turnstile within time limit');
59
 
60
  } catch (error) {