Spaces:
Runtime error
Runtime error
Update server.js
Browse files
server.js
CHANGED
|
@@ -2,88 +2,63 @@ const express = require('express');
|
|
| 2 |
const axios = require('axios');
|
| 3 |
|
| 4 |
const app = express();
|
| 5 |
-
const PORT = 7860
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
api: {
|
| 10 |
-
base: "https://teraboxdl.site/api/",
|
| 11 |
-
token: "token",
|
| 12 |
-
terabox: "terabox"
|
| 13 |
-
},
|
| 14 |
-
headers: {
|
| 15 |
-
'authority': 'teraboxdl.site',
|
| 16 |
-
'user-agent': 'Postify/1.0.0'
|
| 17 |
-
},
|
| 18 |
-
token: null
|
| 19 |
-
};
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
terabox.headers
|
| 30 |
-
});
|
| 31 |
-
terabox.token = data.token;
|
| 32 |
-
return terabox.token;
|
| 33 |
-
} catch (err) {
|
| 34 |
-
throw Error(err.message)
|
| 35 |
-
};
|
| 36 |
-
};
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
return {
|
| 61 |
-
file_name: fileData[i].file_name,
|
| 62 |
-
file_id: fileData[i].fs_id,
|
| 63 |
-
size: fileData[i].size,
|
| 64 |
-
thumbnail: fileData[i].thumb,
|
| 65 |
-
download: fileData[i].download_url,
|
| 66 |
-
bytes: fileData[i].sizebytes
|
| 67 |
-
}
|
| 68 |
-
}
|
| 69 |
-
return result;
|
| 70 |
-
} catch (err) {
|
| 71 |
-
throw Error(err.message)
|
| 72 |
-
}
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
-
const linkNya = isUrl(url.trim());
|
| 76 |
-
return await request(terabox.api.terabox, {
|
| 77 |
-
url: linkNya
|
| 78 |
-
});
|
| 79 |
}
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
app.all('/dl', async (req, res) => {
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
});
|
| 88 |
|
| 89 |
-
app.listen(PORT)
|
|
|
|
|
|
|
|
|
| 2 |
const axios = require('axios');
|
| 3 |
|
| 4 |
const app = express();
|
| 5 |
+
const PORT = 7860;
|
| 6 |
|
| 7 |
+
// JSON parsing enable karein
|
| 8 |
+
app.use(express.json());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
async function getTeraboxLink(userUrl) {
|
| 11 |
+
try {
|
| 12 |
+
// Short URL se ID nikalne ke liye logic
|
| 13 |
+
const match = userUrl.match(/s\/([^\/]+)/i);
|
| 14 |
+
if (!match) throw new Error("Invalid Terabox Link");
|
| 15 |
+
|
| 16 |
+
const shortId = match[1];
|
| 17 |
+
const cleanUrl = `https://www.1024terabox.com/s/${shortId}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
// Nayi working API (Arman API)
|
| 20 |
+
const apiRes = await axios.get(`https://terabox-dl-arman.vercel.app/api?url=${cleanUrl}`, {
|
| 21 |
+
headers: {
|
| 22 |
+
'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'
|
| 23 |
+
},
|
| 24 |
+
timeout: 10000
|
| 25 |
+
});
|
| 26 |
|
| 27 |
+
const data = apiRes.data;
|
| 28 |
+
|
| 29 |
+
// Response format ko check karein aur sahi data return karein
|
| 30 |
+
return {
|
| 31 |
+
file_name: data.file_name || "video.mp4",
|
| 32 |
+
size: data.size || "Unknown",
|
| 33 |
+
download: data.download_url || data.link || data.dlink,
|
| 34 |
+
status: "Success"
|
| 35 |
+
};
|
| 36 |
+
} catch (err) {
|
| 37 |
+
return {
|
| 38 |
+
status: "Error",
|
| 39 |
+
message: "API Blocked or Link Expired",
|
| 40 |
+
details: err.message
|
| 41 |
+
};
|
| 42 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
+
// Home Page par message dikhane ke liye
|
| 46 |
+
app.get('/', (req, res) => {
|
| 47 |
+
res.send("<h1>Terabox API is Running!</h1><p>Use: <code>/dl?url=YOUR_LINK</code></p>");
|
| 48 |
+
});
|
| 49 |
+
|
| 50 |
+
// Download Route
|
| 51 |
app.all('/dl', async (req, res) => {
|
| 52 |
+
const url = req.query.url || req.body.url;
|
| 53 |
+
|
| 54 |
+
if (!url || !url.includes('tera')) {
|
| 55 |
+
return res.status(400).json({ error: "Please provide a valid Terabox link" });
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
const result = await getTeraboxLink(url);
|
| 59 |
+
res.json(result);
|
| 60 |
});
|
| 61 |
|
| 62 |
+
app.listen(PORT, () => {
|
| 63 |
+
console.log(`Server started on port ${PORT}`);
|
| 64 |
+
});
|