vikarshana commited on
Commit
1c7a737
·
verified ·
1 Parent(s): 737061d

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +38 -33
index.js CHANGED
@@ -95,51 +95,56 @@ app.get('/headers', async (req, res) => {
95
  }
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
- // Click the download button
114
- const [button] = await page.$x("//a[contains(@class,'wildbutton')]");
115
- if (!button) throw new Error("Download button not found");
116
-
117
- // Intercept the redirect when clicking
118
- const [response] = await Promise.all([
119
- page.waitForResponse(
120
- (res) =>
121
- res.status() === 302 || res.headers()["location"],
122
- { timeout: 30000 }
123
- ),
124
- button.click(),
125
- ]);
126
-
127
- const realLink = response.headers()["location"];
128
-
129
- await browser.close();
130
 
131
- if (!realLink) {
132
- return res.status(500).json({ status: false, error: "No redirect found" });
133
  }
134
 
135
- return res.json({ status: true, realLink });
 
 
 
 
 
 
 
 
136
  } catch (err) {
137
- console.error(err);
138
- return res.status(500).json({ status: false, error: err.message });
 
139
  }
140
  });
141
 
142
 
 
143
  app.get('/moddl', async (req, res) => {
144
  const apkUrl = req.query.url
145
 
 
95
  }
96
  });
97
 
 
 
 
 
 
98
 
99
+ app.get("/api/direct", async (req, res) => {
100
+ const { url } = req.query;
101
+ if (!url) return res.status(400).json({ status: false, error: "Missing url parameter" });
102
+
103
+ let browser;
104
  try {
105
+ browser = await puppeteer.launch({ headless: true, args: ["--no-sandbox"] });
 
 
 
106
  const page = await browser.newPage();
107
 
108
+ await page.setUserAgent(
109
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
110
+ "(KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
111
+ );
112
+
113
+ // Step 1: open the main page
114
+ await page.goto(url, { waitUntil: "domcontentloaded", timeout: 60000 });
115
+
116
+ // Step 2: extract the onclick link
117
+ const intermediate = await page.evaluate(() => {
118
+ const btn = document.querySelector("span.wildbutton");
119
+ if (!btn) return null;
120
+ const onclickAttr = btn.getAttribute("onclick");
121
+ if (!onclickAttr) return null;
122
+ const match = onclickAttr.match(/'(https?:\/\/[^']+)'/);
123
+ return match ? match[1] : null;
124
+ });
 
 
125
 
126
+ if (!intermediate) {
127
+ return res.status(404).json({ status: false, error: "Download link not found" });
128
  }
129
 
130
+ // Step 3: navigate to intermediate link and get final URL
131
+ const response = await page.goto(intermediate, { waitUntil: "networkidle2" });
132
+ const finalUrl = response.url();
133
+
134
+ res.json({
135
+ status: true,
136
+ intermediate,
137
+ direct: finalUrl
138
+ });
139
  } catch (err) {
140
+ res.status(500).json({ status: false, error: err.message });
141
+ } finally {
142
+ if (browser) await browser.close();
143
  }
144
  });
145
 
146
 
147
+
148
  app.get('/moddl', async (req, res) => {
149
  const apkUrl = req.query.url
150