Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -4,6 +4,7 @@ const port = process.env.PORT || 7860
|
|
| 4 |
const cookieParser = require('cookie-parser')
|
| 5 |
const puppeteer = require('puppeteer-extra');
|
| 6 |
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
|
|
|
| 7 |
|
| 8 |
puppeteer.use(StealthPlugin());
|
| 9 |
|
|
@@ -95,45 +96,53 @@ app.get('/headers', async (req, res) => {
|
|
| 95 |
});
|
| 96 |
|
| 97 |
app.get("/bypass", async (req, res) => {
|
| 98 |
-
const
|
| 99 |
-
if (!
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
let browser;
|
| 102 |
try {
|
| 103 |
-
browser = await puppeteer.launch({
|
| 104 |
headless: true,
|
| 105 |
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
| 106 |
});
|
| 107 |
-
|
| 108 |
const page = await browser.newPage();
|
| 109 |
-
await page.setUserAgent(
|
| 110 |
-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
|
| 111 |
-
);
|
| 112 |
|
| 113 |
-
|
| 114 |
-
await page.goto(url, { waitUntil: "networkidle2", timeout: 60000 });
|
| 115 |
|
| 116 |
-
//
|
| 117 |
-
const
|
| 118 |
-
el.getAttribute("onclick").match(/
|
| 119 |
);
|
| 120 |
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
-
const dlPage = await browser.newPage();
|
| 125 |
-
const response = await dlPage.goto(dlLink, { waitUntil: "networkidle2" });
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
|
| 131 |
-
res.json({ status: true,
|
| 132 |
-
} catch (
|
| 133 |
-
console.error(
|
| 134 |
-
res.json({ status: false, error:
|
| 135 |
-
} finally {
|
| 136 |
-
if (browser) await browser.close();
|
| 137 |
}
|
| 138 |
});
|
| 139 |
|
|
|
|
| 4 |
const cookieParser = require('cookie-parser')
|
| 5 |
const puppeteer = require('puppeteer-extra');
|
| 6 |
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
| 7 |
+
const axios = require("axios");
|
| 8 |
|
| 9 |
puppeteer.use(StealthPlugin());
|
| 10 |
|
|
|
|
| 96 |
});
|
| 97 |
|
| 98 |
app.get("/bypass", async (req, res) => {
|
| 99 |
+
const siteUrl = req.query.url;
|
| 100 |
+
if (!siteUrl) {
|
| 101 |
+
return res.status(400).json({ status: false, error: "Missing ?url param" });
|
| 102 |
+
}
|
| 103 |
|
|
|
|
| 104 |
try {
|
| 105 |
+
const browser = await puppeteer.launch({
|
| 106 |
headless: true,
|
| 107 |
args: ["--no-sandbox", "--disable-setuid-sandbox"],
|
| 108 |
});
|
|
|
|
| 109 |
const page = await browser.newPage();
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
await page.goto(siteUrl, { waitUntil: "networkidle2", timeout: 60000 });
|
|
|
|
| 112 |
|
| 113 |
+
// Grab download link from button (onclick attr)
|
| 114 |
+
const downloadLink = await page.$eval(".wildbutton", el =>
|
| 115 |
+
el.getAttribute("onclick").match(/'(.*?)'/)[1]
|
| 116 |
);
|
| 117 |
|
| 118 |
+
// Collect cookies for axios
|
| 119 |
+
const cookies = await page.cookies();
|
| 120 |
+
const cookieString = cookies.map(c => `${c.name}=${c.value}`).join("; ");
|
| 121 |
+
|
| 122 |
+
await browser.close();
|
| 123 |
+
|
| 124 |
+
// Use axios to request the downloadLink with cookies
|
| 125 |
+
const response = await axios.get(downloadLink, {
|
| 126 |
+
headers: {
|
| 127 |
+
"User-Agent":
|
| 128 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36",
|
| 129 |
+
"Referer": siteUrl,
|
| 130 |
+
"Cookie": cookieString,
|
| 131 |
+
},
|
| 132 |
+
maxRedirects: 0, // stop at redirect to capture Location header
|
| 133 |
+
validateStatus: (status) => status >= 200 && status < 400,
|
| 134 |
+
});
|
| 135 |
|
| 136 |
+
const realLink = response.headers.location;
|
|
|
|
|
|
|
| 137 |
|
| 138 |
+
if (!realLink) {
|
| 139 |
+
return res.status(500).json({ status: false, error: "Failed to extract real link" });
|
| 140 |
+
}
|
| 141 |
|
| 142 |
+
return res.json({ status: true, realLink });
|
| 143 |
+
} catch (e) {
|
| 144 |
+
console.error(e);
|
| 145 |
+
return res.status(500).json({ status: false, error: e.message });
|
|
|
|
|
|
|
| 146 |
}
|
| 147 |
});
|
| 148 |
|