Spaces:
Runtime error
Runtime error
| KKconst express = require('express'); | |
| const axios = require('axios'); | |
| const app = express(); | |
| const PORT = 7860; | |
| // JSON parsing enable karein | |
| app.use(express.json()); | |
| async function getTeraboxLink(userUrl) { | |
| try { | |
| // Short URL se ID nikalne ke liye logic | |
| const match = userUrl.match(/s\/([^\/]+)/i); | |
| if (!match) throw new Error("Invalid Terabox Link"); | |
| const shortId = match[1]; | |
| const cleanUrl = `https://www.1024terabox.com/s/${shortId}`; | |
| // Nayi working API (Arman API) | |
| const apiRes = await axios.get(`https://terabox-dl-arman.vercel.app/api?url=${cleanUrl}`, { | |
| headers: { | |
| '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' | |
| }, | |
| timeout: 10000 | |
| }); | |
| const data = apiRes.data; | |
| // Response format ko check karein aur sahi data return karein | |
| return { | |
| file_name: data.file_name || "video.mp4", | |
| size: data.size || "Unknown", | |
| download: data.download_url || data.link || data.dlink, | |
| status: "Success" | |
| }; | |
| } catch (err) { | |
| return { | |
| status: "Error", | |
| message: "API Blocked or Link Expired", | |
| details: err.message | |
| }; | |
| } | |
| } | |
| // Home Page par message dikhane ke liye | |
| app.get('/', (req, res) => { | |
| res.send("<h1>Terabox API is Running!</h1><p>Use: <code>/dl?url=YOUR_LINK</code></p>"); | |
| }); | |
| // Download Route | |
| app.all('/dl', async (req, res) => { | |
| const url = req.query.url || req.body.url; | |
| if (!url || !url.includes('tera')) { | |
| return res.status(400).json({ error: "Please provide a valid Terabox link" }); | |
| } | |
| const result = await getTeraboxLink(url); | |
| res.json(result); | |
| }); | |
| app.listen(PORT, () => { | |
| console.log(`Server started on port ${PORT}`); | |
| }); | |