forked from Wavyzz/cf-bypass-fast
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c73bccb81 | ||
|
|
85d380d8e4 |
@@ -63,6 +63,7 @@ npm start # Production mode
|
||||
| `authToken` | `null` | API authentication token |
|
||||
| `browserLimit` | `20` | Max concurrent browsers |
|
||||
| `timeOut` | `60000` | Global timeout (ms) |
|
||||
| `CACHE_ENABLED` | `true` | Enable IUAM response cache |
|
||||
|
||||
## 📡 API Endpoints
|
||||
|
||||
@@ -75,7 +76,8 @@ Bypass Cloudflare protection and get cookies/tokens.
|
||||
{
|
||||
"mode": "iuam",
|
||||
"domain": "https://olamovies.watch/generate",
|
||||
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||
"include_html": true
|
||||
}
|
||||
```
|
||||
|
||||
@@ -83,6 +85,7 @@ Bypass Cloudflare protection and get cookies/tokens.
|
||||
- **`mode`** (required): `"iuam"` or `"turnstile"`
|
||||
- **`domain`** (required): Target website URL
|
||||
- **`user_agent`** (optional): User-Agent to use for the browser session
|
||||
- **`include_html`** (optional): `true` to include the final page HTML in IUAM responses
|
||||
- **`proxy`** (optional): Proxy configuration object
|
||||
|
||||
#### Response (Success)
|
||||
@@ -90,7 +93,8 @@ Bypass Cloudflare protection and get cookies/tokens.
|
||||
{
|
||||
"cf_clearance": "eNm9UOgqoNDTP.fmAK9JfvirEmLVpmd.ZWIfdqQxuTc-1758610092-1.2-2NwZwW6nK23HrAH71MtvOek9vCiiS7pUBGIPtra_gSBxYxY2csa6hW0j7i...",
|
||||
"user_agent": "Mozilla/5.0...",
|
||||
"elapsed_time": 3.05
|
||||
"elapsed_time": 3.05,
|
||||
"html": "<!DOCTYPE html><html>...</html>"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
async function getPageHtml(page, url) {
|
||||
try {
|
||||
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 10000 })
|
||||
} catch (_) {}
|
||||
|
||||
try {
|
||||
return await page.content()
|
||||
} catch (_) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function cloudflare(data, page) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (!data.domain) return reject(new Error("Missing domain parameter"))
|
||||
@@ -10,11 +22,13 @@ async function cloudflare(data, page) {
|
||||
if (!isResolved) {
|
||||
isResolved = true
|
||||
const elapsedTime = (Date.now() - startTime) / 1000
|
||||
resolve({
|
||||
const response = {
|
||||
cf_clearance: null,
|
||||
user_agent: userAgent,
|
||||
elapsed_time: elapsedTime,
|
||||
})
|
||||
}
|
||||
if (data.include_html) response.html = null
|
||||
resolve(response)
|
||||
}
|
||||
}, 20000)
|
||||
|
||||
@@ -52,11 +66,17 @@ async function cloudflare(data, page) {
|
||||
isResolved = true
|
||||
clearTimeout(cl)
|
||||
|
||||
resolve({
|
||||
const response = {
|
||||
cf_clearance,
|
||||
user_agent: userAgent,
|
||||
elapsed_time: elapsedTime,
|
||||
})
|
||||
}
|
||||
|
||||
if (data.include_html) {
|
||||
response.html = await getPageHtml(page, data.domain)
|
||||
}
|
||||
|
||||
resolve(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
10
index.js
10
index.js
@@ -13,6 +13,9 @@ global.timeOut = Number(process.env.timeOut) || 60000
|
||||
const CACHE_DIR = path.join(__dirname, "cache")
|
||||
const CACHE_FILE = path.join(CACHE_DIR, "cache.json")
|
||||
const CACHE_TTL = 5 * 60 * 1000
|
||||
const CACHE_ENABLED = process.env.CACHE_ENABLED
|
||||
? !["0", "false", "no"].includes(process.env.CACHE_ENABLED.toLowerCase())
|
||||
: true
|
||||
|
||||
function loadCache() {
|
||||
if (!fs.existsSync(CACHE_FILE)) return {}
|
||||
@@ -100,6 +103,9 @@ app.post('/cloudflare', async (req, res) => {
|
||||
if (data.user_agent && typeof data.user_agent !== 'string') {
|
||||
return res.status(400).json({ message: 'Bad Request: invalid user_agent' })
|
||||
}
|
||||
if (typeof data.include_html !== 'undefined' && typeof data.include_html !== 'boolean') {
|
||||
return res.status(400).json({ message: 'Bad Request: invalid include_html' })
|
||||
}
|
||||
if (authToken && data.authToken !== authToken) {
|
||||
return res.status(401).json({ message: 'Unauthorized' })
|
||||
}
|
||||
@@ -109,7 +115,7 @@ app.post('/cloudflare', async (req, res) => {
|
||||
}
|
||||
|
||||
let cacheKey, cached
|
||||
if (data.mode === "iuam") {
|
||||
if (CACHE_ENABLED && data.mode === "iuam" && !data.include_html) {
|
||||
|
||||
cacheKey = JSON.stringify(data)
|
||||
cached = readCache(cacheKey)
|
||||
@@ -147,7 +153,7 @@ app.post('/cloudflare', async (req, res) => {
|
||||
.then(r => ({ ...r }))
|
||||
.catch(err => ({ code: 500, message: err.message }))
|
||||
|
||||
if (!result.code || result.code === 200) {
|
||||
if (CACHE_ENABLED && !data.include_html && (!result.code || result.code === 200)) {
|
||||
writeCache(cacheKey, result)
|
||||
}
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user